#!/bin/bash
set -euo pipefail
source "$(dirname "${BASH_SOURCE[0]}")/../lib/logging.sh"

log "Starting Sway installer..."

# 1. Install packages
log "Installing required packages..."
sudo pacman -Syu --noconfirm --needed \
    brightnessctl btop dmenu foot glfw grim \
    greetd-tuigreet gst-plugin-pipewire imagemagick iwd libpulse \
    libva-intel-driver libva-mesa-driver lightdm lightdm-gtk-greeter \
    networkmanager pavucontrol pipewire pipewire-alsa pipewire-jack pipewire-pulse \
    slurp sway swaybg swayidle swaylock alacritty \
    ttf-jetbrains-mono vulkan-intel vulkan-radeon waybar wget \
    wireplumber wofi wpa_supplicant \
    xdg-utils xf86-video-amdgpu xf86-video-ati xf86-video-nouveau \
    xf86-video-vmware xorg-server xorg-xinit xorg-xwayland \
    zram-generator

# 2. Enable services
log "Enabling services..."
sudo systemctl enable NetworkManager.service

# 3. greetd config
log "Deploying greetd config..."
sudo cp -f ~/Dotfiles/desktopenvs/hyprland/greetd-tuigreet/config.toml /etc/greetd/config.toml
sudo systemctl enable greetd.service

# 4. Copy DE configs
log "Copying Sway configs..."
CONFIGS=(sway alacritty)
for cfg in "${CONFIGS[@]}"; do
    rm -rf ~/.config/"$cfg"
    cp -r ~/Dotfiles/desktopenvs/sway/"$cfg" ~/.config/
done

cp ~/Dotfiles/colors.conf ~/.config/colors.conf
cp ~/Dotfiles/apply-theme.sh ~/apply-theme.sh
chmod +x ~/apply-theme.sh

log "Sway installation complete. Run shell-setup.sh if you haven't already, then reboot."
