#!/bin/bash
set -euo pipefail

echo "=== COSMIC Desktop Installer ==="

echo "[+] Installing COSMIC..."
sudo pacman -S --noconfirm --needed \
    cosmic \
    pipewire wireplumber pipewire-alsa pipewire-jack pipewire-pulse \
    networkmanager \
    bluez bluez-utils \
    flatpak

echo "[+] Enabling services..."
# cosmic-greeter is COSMIC's own display manager; fall back to sddm if absent
if pacman -Qi cosmic-greeter &>/dev/null; then
    sudo systemctl enable cosmic-greeter.service
else
    sudo pacman -S --noconfirm --needed sddm
    sudo systemctl enable sddm.service
fi
sudo systemctl enable NetworkManager.service
sudo systemctl enable bluetooth.service

echo "=== COSMIC installation complete. Reboot to start. ==="
