#!/bin/bash
clear

# Enable strict mode for bash
set -euo pipefail

# Define functions and colors
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${SCRIPT_DIR}/utils/colors.sh"
source "${SCRIPT_DIR}/utils/helpers.sh"

LOG="install.log"
[ -f "$LOG" ] && rm -f "$LOG"
touch "$LOG"

# Displau logo and information
display_header

# Initial checks
check_not_root
check_internet
check_arch
check_chezmoi

# Request confirmation
echo "┌──────────────────────────────────────┐"
echo "│   Start Setup? (y/N)                 │"
echo "└──────────────────────────────────────┘"
read -p "~> " inst
case $inst in 
    y | Y) echo -e "\nStarting setup..." ;;
    *) echo -e "\nSetup cancelled." && exit 0 ;;
esac

# Install components
source "${SCRIPT_DIR}/scripts/core.sh"
source "${SCRIPT_DIR}/scripts/desktop.sh"
source "${SCRIPT_DIR}/scripts/shells.sh"
source "${SCRIPT_DIR}/scripts/development.sh"

# Setup configuration files
echo -e "${GREEN}Applying dotfiles configuration...${DEFAULT}"
chezmoi apply

# Final configuration
setup_final

echo -e "${GREEN}Installation completed successfully!${DEFAULT}"
echo -e "Please reboot your system to apply all changes."
exit 0
