#!/bin/bash

# Define color codes
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m' # No Color

# Packages list
packages=(
    "zsh"      # Better than bash
    "micro"    # Better than nano
    "exa"      # Better than ls
    "bat"      # Better than cat
    "btop"     # Betther than top
    "ncdu"     # Better than du -h
    "duf"      # Better than df -h
    "neofetch" # Because it's cool
    "git"      # Because git
    "fuck"     # Fuck error
)

# Check the operating system
if [[ $(uname -s) == "Linux" ]]; then
    # Check if apt command is available
    if command -v apt >/dev/null 2>&1; then
        installer="apt"
    elif command -v dnf >/dev/null 2>&1; then
        installer="dnf"
    else
        echo "Unsupported Linux distribution. Please install packages manually."
        exit 1
    fi
elif [[ $(uname -s) == "Darwin" ]]; then
    if command -v brew >/dev/null 2>&1; then
        installer="brew"
    else
        echo "Homebrew is not installed on your system. Please install it manually."
        exit 1
    fi
else
    echo "Unsupported operating system. Please install packages manually."
    exit 1
fi

# Packages installation
clear
echo "Mise à jour de la liste des paquets..."
echo " "
sudo apt update >/dev/null 2>&1
echo "Installation des paquets :"
for package in "${packages[@]}"; do
    if $installer install "$package" -y >/dev/null 2>&1; then
        echo -e "  - Installation de $package : ${GREEN}ok${NC}"
    else
        echo -e "  - Installation de $package : ${RED}échoué${NC}"
    fi
done

# Git Installation
if [ ! -d ~/.zsh ]; then
  mkdir -p ~/.zsh
fi
if git clone https://github.com/zsh-users/zsh-autosuggestions ~/.zsh/zsh-autosuggestions >/dev/null 2>&1 ; then
        echo -e "  - Installation de zsh-autosuggestions : ${GREEN}ok${NC}"
    else
        echo -e "  - Installation de zsh-autosuggestions : ${RED}échoué${NC}"
    fi
if git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ~/.zsh/zsh-syntax-highlighting >/dev/null 2>&1 ; then
        echo -e "  - Installation de zsh-syntax-highlighting : ${GREEN}ok${NC}"
    else
        echo -e "  - Installation de zsh-syntax-highlighting : ${RED}échoué${NC}"
    fi
if git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.zsh/powerlevel10k >/dev/null 2>&1 ; then
        echo -e "  - Installation de powerlevel10k : ${GREEN}ok${NC}"
    else
        echo -e "  - Installation de powerlevel10k : ${RED}échoué${NC}"
    fi

echo "  - Copie des fichiers nécessaires à powerlevel10k"
cp ./p10k.zsh ~/.p10k.zsh
cp ./zshrc ~/.zshrc
echo "  - Copie des fichiers nécessaires à Neofetch"
if [ ! -d ~/.config/neofetch ]; then
  mkdir -p ~/.config/neofetch
fi
cp -r ./neofetch/* ~/.config/neofetch
echo "  - Mise en place de zsh par défaut (mot de passe nécessaire)"
chsh -s $(which zsh) # Pour fedora, si chsh non installé : dnf install util-linux-user
zsh