#!/bin/bash

# --- 0. Pre-installation Setup ---
echo "🎨 Customize your Terminal Color Palette"
echo "Select a primary color for your Starship prompt:"
echo "  1) Vibrant Orange (#FF8C00) [Default]"
echo "  2) Yellow         (#E6D709)"
echo "  3) Mint Green     (#50FA7B)"
echo "  4) Light Blue     (#8BE9FD)"
echo "  5) Pink           (#FF79C6)"
echo "  6) Red            (#FF5555)"
echo "  7) Purple         (#BD93F9)"
echo "  8) Cyan           (#00FFFF)"
echo "  9) Lime           (#32CD32)"
echo " 10) Blue           (#007BFF)"

read -p "Enter the number of your choice [1]: " color_choice

case $color_choice in
    2) PRIMARY_COLOR="#E6D709" ;;
    3) PRIMARY_COLOR="#50FA7B" ;;
    4) PRIMARY_COLOR="#8BE9FD" ;;
    5) PRIMARY_COLOR="#FF79C6" ;;
    6) PRIMARY_COLOR="#FF5555" ;;
    7) PRIMARY_COLOR="#BD93F9" ;;
    8) PRIMARY_COLOR="#00FFFF" ;;
    9) PRIMARY_COLOR="#32CD32" ;;
    10) PRIMARY_COLOR="#007BFF" ;;
    *) PRIMARY_COLOR="#FF8C00" ;; # Default
esac

echo -e "Selected hex color: $PRIMARY_COLOR\n"

# --- 1. Update and install dependencies ---
echo -n "📦 Checking and installing dependencies... "
if sudo apt install -y git curl lsd micro zoxide fzf > /dev/null 2>&1; then
    echo "Done."
else
    echo "Failed! Check your internet connection."
    exit 1
fi

# --- 2. Setup Fonts ---
echo -n "🔨 Syncing fonts... "
mkdir -p ~/.local/share/fonts
if [ -d "./fonts" ]; then
    # -u (update) only copies if the source is newer than the destination
    cp -uf ./fonts/*.ttf ~/.local/share/fonts/ > /dev/null 2>&1
    fc-cache -f > /dev/null 2>&1
    echo "Fonts updated successfully."
else
    echo "No fonts folder found, skipping."
fi

# --- 3. Install Starship ---
echo -n "  Installing/Updating Starship... "
if curl -sS https://starship.rs/install.sh | sh -s -- -y > /dev/null 2>&1; then
    echo "Done."
else
    echo "Failed to install Starship."
fi

# --- 4. Setup Configs ---

# Starship
echo -n "  Configuring Starship... "
mkdir -p ~/.config
if [ -f "starship.toml" ]; then
    cp -f starship.toml ~/.config/starship.toml
    sed -i "s/{{PRIMARY_COLOR}}/${PRIMARY_COLOR}/g" ~/.config/starship.toml
    echo "Done."
else
    echo "Failed (starship.toml not found)."
fi


# Bashrc
echo -n "󱆃  Applying .bashrc... "
if [ -f ".bashrc" ]; then
    if [ ! -L ~/.bashrc ] && [ ! -f ~/.bashrc.bak ]; then
        cp ~/.bashrc ~/.bashrc.bak
    fi
    cp -f .bashrc_debian ~/.bashrc && echo "Done."
else
    echo "Skipped (.bashrc not found)."
fi


echo "-----------------------------------------------"
echo "✅ All set! Terminal Restarting."
echo "-----------------------------------------------"
source ~/.bashrc