---
- name: Install X11 and Chromium packages
  ansible.builtin.apt:
    name:
      - xserver-xorg-core
      - x11-xserver-utils
      - xinit
      - openbox
      - chromium
      - unclutter
    state: present
    update_cache: true
  become: true

- name: Ensure Chromium managed policy directory exists
  ansible.builtin.file:
    path: /etc/chromium/policies/managed
    state: directory
    owner: root
    group: root
    mode: "0755"
  become: true

- name: Deploy Chromium kiosk policy (disables translate prompt and sets language)
  ansible.builtin.copy:
    dest: /etc/chromium/policies/managed/morz-kiosk.json
    owner: root
    group: root
    mode: "0644"
    content: |
      {
        "TranslateEnabled": false,
        "SpellcheckEnabled": false,
        "DefaultNotificationsSetting": 2,
        "DefaultGeolocationSetting": 2
      }
  become: true
  notify: Restart morz-kiosk

- name: Deploy kiosk startup script
  ansible.builtin.template:
    src: morz-kiosk.j2
    dest: /usr/local/bin/morz-kiosk
    owner: root
    group: root
    mode: "0755"
  become: true
  notify: Restart morz-kiosk

- name: Deploy kiosk systemd unit
  ansible.builtin.template:
    src: morz-kiosk.service.j2
    dest: /etc/systemd/system/morz-kiosk.service
    owner: root
    group: root
    mode: "0644"
  become: true
  notify:
    - Reload systemd
    - Restart morz-kiosk

- name: Enable and start morz-kiosk
  ansible.builtin.systemd:
    name: morz-kiosk
    enabled: true
    state: started
    daemon_reload: false
  become: true
