#!/bin/bash

# Install dotfiles for Arch Linux
# This script copies the .zshrc file to the home directory

set -e

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
PURPLE='\033[0;35m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color

# Function for colored output
print_status() {
    echo -e "${BLUE}[INFO]${NC} $1"
}

print_success() {
    echo -e "${GREEN}[SUCCESS]${NC} $1"
}

print_warning() {
    echo -e "${YELLOW}[WARNING]${NC} $1"
}

print_error() {
    echo -e "${RED}[ERROR]${NC} $1"
}

echo -e "${PURPLE}================================${NC}"
echo -e "${PURPLE}  Arch Linux Dotfiles Installer${NC}"
echo -e "${PURPLE}================================${NC}"
echo ""

print_status "Starting dotfiles installation..."

# Get the directory where this script is located
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
print_status "Script directory: $SCRIPT_DIR"

# Copy .zshrc to home directory
echo ""
print_status "Installing .zshrc configuration..."
if cp "$SCRIPT_DIR/.zshrc" ~/.zshrc; then
    print_success ".zshrc installed to ~/.zshrc"
else
    print_error "Failed to copy .zshrc"
    exit 1
fi

# Copy .profile to home directory
echo ""
print_status "Installing .profile configuration..."
if cp "$SCRIPT_DIR/.profile" ~/.profile; then
    print_success ".profile installed to ~/.profile"
else
    print_error "Failed to copy .profile"
    exit 1
fi

# Copy .aliases to home directory
echo ""
print_status "Installing .aliases configuration..."
if cp "$SCRIPT_DIR/.aliases" ~/.aliases; then
    print_success ".aliases installed to ~/.aliases"
else
    print_error "Failed to copy .aliases"
    exit 1
fi

# Copy .p10k.zsh to home directory
echo ""
print_status "Installing Powerlevel10k configuration..."
if cp "$SCRIPT_DIR/.p10k.zsh" ~/.p10k.zsh; then
    print_success ".p10k.zsh installed to ~/.p10k.zsh"
else
    print_error "Failed to copy .p10k.zsh"
    exit 1
fi

# === FUZZEL CONFIG ===
# Comment out this section if you don't want fuzzel configuration
echo ""
print_status "Installing fuzzel configuration..."
if mkdir -p ~/.config/fuzzel; then
    print_success "Created fuzzel config directory"
else
    print_error "Failed to create fuzzel config directory"
    exit 1
fi

if cp "$SCRIPT_DIR/.config/fuzzel/fuzzel.ini" ~/.config/fuzzel/fuzzel.ini; then
    print_success "Fuzzel config installed to ~/.config/fuzzel/fuzzel.ini"
else
    print_warning "Failed to copy fuzzel config - file may not exist"
fi

echo ""
echo -e "${CYAN}================================${NC}"
echo -e "${CYAN}  Installation Complete! 🎉${NC}"
echo -e "${CYAN}================================${NC}"

echo ""
print_status "Next steps:"
echo -e "  ${YELLOW}1.${NC} Restart your terminal or run 'source ~/.zshrc'"
echo -e "  ${YELLOW}2.${NC} Powerlevel10k configuration has been copied - no need to run 'p10k configure'"
echo -e "  ${YELLOW}3.${NC} If you haven't already, run the install-arch-dotfiles-requirements.sh script first"
echo ""
print_warning "Note: Make sure you have installed the required dependencies first!"
