#!/bin/bash
# Install Sway configuration files only - Arch Linux version

set -e

echo "Installing Sway configuration files for Arch Linux..."
echo "======================================================="

# Create sway config directory
mkdir -p ~/.config/sway
echo "✓ Created ~/.config/sway directory"

# Backup existing sway config if it exists
if [ -f ~/.config/sway/config ]; then
    echo "⚠ Backing up existing sway config to ~/.config/sway/config.backup"
    cp ~/.config/sway/config ~/.config/sway/config.backup
fi

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# === MAKO CONFIG ===
# Create mako config directory
mkdir -p ~/.config/mako
echo "✓ Created ~/.config/mako directory"
echo ""
echo "Installing mako config..."
cp $SCRIPT_DIR/home_dotfiles/.config/mako/config ~/.config/mako/config
echo "✓ mako config installed to ~/.config/mako/config"

# === SWAY CONFIG ===
# Comment out this section if you don't want to install the main config
echo ""
echo "Installing main Sway config..."
cp $SCRIPT_DIR/home_dotfiles/.config/sway/config ~/.config/sway/config
echo "✓ Sway config installed to ~/.config/sway/config"

# === SWAYIMG CONFIG ===
echo ""
echo "Installing swayimg config..."
cp $SCRIPT_DIR/home_dotfiles/.config/swayimg/swayimgrc ~/.config/swayimg/swayimgrc
echo "✓ Swayimg config installed to ~/.config/swayimg/swayimgrc"

# === I3STATUS-RUST CONFIG ===
# Comment out this section if you don't want i3status-rust
echo ""
echo "Installing i3status-rust config..."
cp $SCRIPT_DIR/home_dotfiles/.config/sway/i3status-rust.toml ~/.config/sway/i3status-rust.toml
echo "✓ i3status-rust config installed to ~/.config/sway/i3status-rust.toml"

# === WEATHER SCRIPT ===
# Comment out this section if you don't want the weather script
echo ""
echo "Installing weather script..."
cp $SCRIPT_DIR/home_dotfiles/.config/sway/weather-sway.sh ~/.config/sway/weather-sway.sh
chmod +x ~/.config/sway/weather-sway.sh
echo "✓ Weather script installed to ~/.config/sway/weather-sway.sh"

# === BLUETOOTH SCRIPT ===
echo ""
echo "Installing bluetooth script..."
cp $SCRIPT_DIR/home_dotfiles/.config/sway/bluetooth-sway.sh ~/.config/sway/bluetooth-sway.sh
chmod +x ~/.config/sway/bluetooth-sway.sh
echo "✓ Bluetooth script installed to ~/.config/sway/bluetooth-sway.sh"

# === VOLUME NOTIFY SCRIPT ===
# Comment out this section if you don't want volume notifications
if [ -f $SCRIPT_DIR/home_dotfiles/.config/sway/volume-notify-sway.sh ]; then
    echo ""
    echo "Installing volume notify script..."
    cp $SCRIPT_DIR/home_dotfiles/.config/sway/volume-notify-sway.sh ~/.config/sway/volume-notify-sway.sh
    chmod +x ~/.config/sway/volume-notify-sway.sh
    echo "✓ Volume notify script installed to ~/.config/sway/volume-notify-sway.sh"
else
    echo ""
    echo "⚠ volume-notify-sway.sh not found, skipping..."
fi

# === SET THUNAR AS DEFAULT FILE MANAGER ===
echo ""
echo "Setting thunar as default file manager..."
xdg-mime default thunar.desktop inode/directory application/x-gnome-saved-search
echo "✓ thunar set as default file manager"

# === SET WALLPAPER ===
echo ""
echo "Setting wallpaper..."
WALLPAPER_PATH="$SCRIPT_DIR/home_dotfiles/wallpapers/chris-czermak-PamFFHL6fVY-unsplash.jpg"
cp $WALLPAPER_PATH ~/.config/sway/wallpaper.jpg
echo "✓ Wallpaper installed to ~/.config/sway/wallpaper.jpg"

echo ""
echo "=========================================="
echo "✅ Sway configuration installation complete!"
echo "=========================================="
echo ""
echo "Next steps:"
echo "1. Run ./install-arch-sway-requirements.sh to install packages"
echo "2. Log out and select Sway from your display manager"
echo "3. Or start Sway from TTY with: sway"
echo ""
echo "Config files installed:"
echo "- ~/.config/mako/config (notification styling)"
echo "- ~/.config/sway/config (main Sway config)"
echo "- ~/.config/swayimg/swayimgrc (image viewer config)"
echo "- ~/.config/sway/i3status-rust.toml (status bar config)"
echo "- ~/.config/sway/weather-sway.sh (weather script)"
echo "- thunar set as default file manager"
if [ -f ~/.config/sway/volume-notify-sway.sh ]; then
    echo "- ~/.config/sway/volume-notify-sway.sh (volume notifications)"
fi 

makoctl reload
