---
- name: "[Arch] Configure pacman"
  ansible.builtin.copy:
    mode: 0644
    src: "pacman.conf"
    dest: "/etc/"
  become: true
  tags:
    - pacman

- name: "[Arch] Update packages"
  community.general.pacman:
    update_cache: true
    upgrade: true
    state: latest
  become: true
  tags:
    - pacman

- name: "[Arch] Install default packages"
  kewlfft.aur.aur:
    name:
      - networkmanager
      - networkmanager-openvpn
      - network-manager-applet
      - inotify-tools
      - cifs-utils
      - reflector
      - ntfs-3g
      - openssh
      - upower
      - unzip
      - less
      - curl
      - wget
      - awk
      - zip
      - tar
      - eza
      - bat
      - jq
    state: present
  tags:
    - default_pkgs 

- name: "[Arch] Install programming packages"
  kewlfft.aur.aur:
    name:
      - jdk-openjdk
      - maven
      - rustup
      - npm
    state: present
  tags:
    - programming_pkgs
  when: system != 'server'

- name: "[Arch] Configure rustup"
  command: rustup default stable
  tags:
    - programming_pkgs
  when: system != 'server'

- name: "[Arch] Install desktop packages"
  kewlfft.aur.aur:
    name: 
      # Fonts
      - noto-fonts
      - noto-fonts-cjk
      - noto-fonts-emoji
      - ttf-font-awesome
      - nerd-fonts  
      # Pipewire
      - pipewire
      - wireplumber
      - pipewire-alsa
      - pipewire-audio
      - pipewire-jack
      - pipewire-pulse
      - gst-plugin-pipewire
      # Bluetooth
      - bluez
      - bluez-utils
      - blueman
      # Printing
      - cups
      - cups-pdf
      # Theming
      #- qt5ct 
      # Icon Themes
      - papirus-icon-theme
      # Cursor Themes
      - xcursor-breeze
      # Themes
      - catppuccin-gtk-theme-frappe
      - catppuccin-gtk-theme-latte
      - catppuccin-gtk-theme-macchiato
      - catppuccin-gtk-theme-mocha
      # Misc
      - brightnessctl
      #- wlr-randr
      - playerctl
      - libnotify
      - mediainfo
      - hyprpicker
      - swww
      - swayidle
      - grimblast-git
      - cliphist
      - wl-clipboard
      - polkit-kde-agent
      - xdg-desktop-portal-hyprland
      - gnome-keyring
    state: present
  tags:
    - desktop_pkgs
  when: system != 'server'

- name: "[Arch] Install desktop applications"
  kewlfft.aur.aur:
    name: 
      - libreoffice-fresh
      - nextcloud-client
      - element-desktop
      - youtube-music
      - vscodium-bin
      - pavucontrol
      - thunderbird
      - hyprpicker
      - brave-bin
      - obsidian
      - yt-dlp
      - nvtop
      - nemo
      - mpv
      # Device configuration
      #- openrazer-daemon
      #- openrgb
      #- piper
      # AMD Stats
      #- amdgpu_top
      # Character map
      #- gucharmap
      # Calculator
      #- galculator
    state: present
  tags:
    - desktop_apps
  when: system != 'server'

- name: "[Arch] Install additional desktop packages"
  kewlfft.aur.aur:
    name: 
      - steam
      - lutris
      # Wine
      - wine-staging
      - giflib
      - lib32-giflib
      - libpng
      - lib32-libpng
      - libldap
      - lib32-libldap
      - gnutls
      - lib32-gnutls
      - mpg123
      - lib32-mpg123
      - openal
      - lib32-openal
      - v4l-utils
      - lib32-v4l-utils
      - libpulse
      - lib32-libpulse
      - libgpg-error
      - lib32-libgpg-error
      - alsa-plugins
      - lib32-alsa-plugins
      - alsa-lib
      - lib32-alsa-lib
      - libjpeg-turbo
      - lib32-libjpeg-turbo
      - sqlite
      - lib32-sqlite
      - libxcomposite
      - lib32-libxcomposite
      - libxinerama
      - lib32-libgcrypt
      - libgcrypt
      - lib32-libxinerama
      - ncurses
      - lib32-ncurses
      - ocl-icd
      - lib32-ocl-icd
      - libxslt
      - lib32-libxslt
      - libva
      - lib32-libva
      - gtk3
      - lib32-gtk3
      - gst-plugins-base-libs
      - lib32-gst-plugins-base-libs
      - vulkan-icd-loader
      - lib32-vulkan-icd-loader
    state: present
  tags:
    - desktop_pkgs
  when: system == 'desktop_full'

- name: Gather GPU info
  shell: "lspci | grep -i vga"
  register: gpu_info
  tags:
    - desktop_pkgs
  when: system == 'desktop_full'

- name: "[Arch] Install AMD packages"
  kewlfft.aur.aur:
    name: 
      - lib32-mesa
      - vulkan-radeon
      - lib32-vulkan-radeon
    state: present
  when: "system == 'desktop_full' and 'Advanced Micro Devices' in gpu_info.stdout"

- name: "[Arch] Install Intel packages"
  kewlfft.aur.aur:
    name: 
      - lib32-mesa
      - vulkan-intel
      - lib32-vulkan-intel
    state: present
  tags:
    - desktop_pkgs
  when: "system == 'desktop_full' and 'Intel Corporation' in gpu_info.stdout"

- name: "[Arch] Install Nvidia packages"
  kewlfft.aur.aur:
    name: 
      - nvidia-dkms
      - nvidia-utils
      - lib32-nvidia-utils 
      - nvidia-settings
    state: present
  tags:
    - desktop_pkgs
  when: "system == 'desktop_full' and 'NVIDIA' in gpu_info.stdout"

- name: "[Arch] Enable services"
  ansible.builtin.service:
    name: "{{ item }}"
    enabled: true
  with_items: 
    - bluetooth
    - cups
    - sddm
  tags:
    - desktop_services
  when: "system == 'desktop'"
  become: true
