#!/bin/bash

# Install Oh My Zsh and related requirements for Arch Linux
# This script installs all necessary packages for the enhanced zsh setup

set -e

echo "Installing Oh My Zsh and related requirements..."

# Install base packages
echo "Installing base packages..."
sudo pacman -S --needed \
    zsh \
    git \
    curl \
    wget \
    fzf \
    ripgrep \
    fd \
    bat \
    eza \
    atuin \
    zoxide

# Install Oh My Zsh
echo "Installing Oh My Zsh..."
if [ ! -d "$HOME/.oh-my-zsh" ]; then
    sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
else
    echo "Oh My Zsh already installed, skipping..."
fi

# Install Powerlevel10k theme
echo "Installing Powerlevel10k theme..."
if [ ! -d "$HOME/.oh-my-zsh/custom/themes/powerlevel10k" ]; then
    git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k
else
    echo "Powerlevel10k theme already installed, skipping..."
fi

# Install zsh-syntax-highlighting plugin
echo "Installing zsh-syntax-highlighting plugin..."
if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting" ]; then
    git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
else
    echo "zsh-syntax-highlighting plugin already installed, skipping..."
fi

# Install zsh-autosuggestions plugin
echo "Installing zsh-autosuggestions plugin..."
if [ ! -d "$HOME/.oh-my-zsh/custom/plugins/zsh-autosuggestions" ]; then
    git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
else
    echo "zsh-autosuggestions plugin already installed, skipping..."
fi

# Set zsh as default shell
echo "Setting zsh as default shell..."
if [ "$SHELL" != "/bin/zsh" ]; then
    chsh -s /bin/zsh
    echo "Default shell changed to zsh. Please log out and log back in for changes to take effect."
else
    echo "Zsh is already the default shell."
fi

echo "Installation complete!"
echo ""
echo "Next steps:"
echo "1. Run the install-arch-dotfiles.sh script to copy the .zshrc file"
echo "2. Restart your terminal or run 'source ~/.zshrc'"
echo "3. Run 'p10k configure' to set up Powerlevel10k theme"
echo "4. Log out and log back in for the default shell change to take effect"
