#!/bin/bash

# Ralsei Cursors Installation Script for CachyOS
# Installs custom Ralsei cursor theme

set -e

echo "🎮 Installing Ralsei cursors..."

# Create cursor directory
CURSOR_DIR="$HOME/.local/share/icons/RalseiCursors"
mkdir -p "$CURSOR_DIR"

# Copy cursor files from config directory
CONFIG_DIR="~/config"
CURSOR_SOURCE="$CONFIG_DIR/hosts/default/packages/ralsei-cursors/cursors"

if [ -d "$CURSOR_SOURCE" ]; then
    echo "📁 Copying cursor files..."
    cp -r "$CURSOR_SOURCE"/* "$CURSOR_DIR/"
    
    # Copy theme index file
    if [ -f "$CONFIG_DIR/hosts/default/packages/ralsei-cursors/index.theme" ]; then
        cp "$CONFIG_DIR/hosts/default/packages/ralsei-cursors/index.theme" "$CURSOR_DIR/"
    fi
    
    echo "✅ Ralsei cursors copied successfully!"
else
    echo "❌ Cursor source directory not found at: $CURSOR_SOURCE"
    echo "Please ensure your config directory structure is correct."
    exit 1
fi

# Update icon cache
echo "🔄 Updating icon cache..."
if command -v gtk-update-icon-cache &> /dev/null; then
    gtk-update-icon-cache -f -t "$CURSOR_DIR"
    echo "✅ Icon cache updated!"
else
    echo "⚠️  gtk-update-icon-cache not found. You may need to install gtk-update-icon-cache"
fi

# Set as default cursor theme (optional - user can do this manually)
echo "🎯 Setting Ralsei cursors as default..."
if command -v gsettings &> /dev/null; then
    gsettings set org.gnome.desktop.interface cursor-theme "RalseiCursors"
    echo "✅ Cursor theme set as default!"
else
    echo "⚠️  gsettings not found. You may need to set the cursor theme manually."
fi

# Alternative method using XDG
if command -v xdg-settings &> /dev/null; then
    xdg-settings set cursor-theme "RalseiCursors" 2>/dev/null || true
fi
