# Enable profiling
# zmodload zsh/zprof

# Path to your oh-my-zsh installation
# export ZSH="$HOME/.oh-my-zsh"
# export ZSH_CUSTOM="$HOME/.oh-my-zsh/custom"
# export UPDATE_ZSH_DAYS=1

# Disable auto title
DISABLE_AUTO_TITLE="true"

# Auto-update and other zsh settings
# DISABLE_UPDATE_PROMPT=true
# zstyle ':omz:update' mode reminder  # remind to update

# Uncomment to use case-sensitive completion
# CASE_SENSITIVE="true"

# Uncomment to use hyphen-insensitive completion
# HYPHEN_INSENSITIVE="true"

# Miscellaneous configurations
# DISABLE_MAGIC_FUNCTIONS="true"
# DISABLE_LS_COLORS="true"
# ENABLE_CORRECTION="true"
# COMPLETION_WAITING_DOTS="true"
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Load zsh hooks
# autoload -Uz add-zsh-hook
#
# Load zsh completions
autoload -Uz compinit

# Fix: Ensure correct completion directory for Apple Silicon
fpath=(/opt/homebrew/share/zsh/site-functions $fpath)
compinit

# Plugins to load
# plugins=(
#     git
#     docker
#     zsh-syntax-highlighting
#     zsh-autosuggestions
#     colored-man-pages
#     macos
#     autoupdate
#     zoxide
# )
# export ZSH_AUTOSUGGEST_STRATEGY=(
#     history
#     completion
# )

# Source oh-my-zsh.sh
# . $ZSH/oh-my-zsh.sh

# Load Zinit
ZINIT_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}/zinit/zinit.git"
if [ ! -d "$ZINIT_HOME" ]; then
    mkdir -p "$(dirname "$ZINIT_HOME")"
    git clone https://github.com/zdharma-continuum/zinit.git "$ZINIT_HOME"
fi
source "${ZINIT_HOME}/zinit.zsh"

# Ensure compinit is loaded after zinit
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit

# Load plugins with zinit
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-history-substring-search

# Lazy load zsh-syntax-highlighting
zinit ice wait lucid atinit"ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern)"
zinit load zsh-users/zsh-syntax-highlighting

# Load async auto-suggestions
zinit ice wait lucid atload"zle-line-init() { zle autosuggest-enable }; zle -N zle-line-init"
zinit load zsh-users/zsh-autosuggestions

# zoxide
zinit ice from"gh-r" as"program" pick"bin/zoxide"
zinit load ajeetdsouza/zoxide

# Load eza completions if needed
[[ ! "$FPATH" =~ (^|:)${HOME}/.local/bin/eza/completions/zsh(:|$) ]] && export FPATH="$HOME/.local/bin/eza/completions/zsh:$FPATH"

# Initialize direnv
eval "$(direnv hook zsh)"

# Initialize zoxide
eval "$(zoxide init --cmd cd zsh)"

# Initialize Starship
eval "$(starship init zsh)"
export STARSHIP_CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/starship.toml"

# ----------------- Conda & Mamba Setup -----------------
# Conda paths where Miniforge is installed (for Apple Silicon)
CONDA_PATHS=("/opt/homebrew/Caskroom/miniforge/base" "/usr/local/Caskroom/miniforge/base")

for CONDA_PATH in "${CONDA_PATHS[@]}"; do
    if [ -d "$CONDA_PATH" ]; then
        # Manually set up Conda if available
        if [ -f "$CONDA_PATH/etc/profile.d/conda.sh" ]; then
            . "$CONDA_PATH/etc/profile.d/conda.sh"
        else
            # Fall back to adding Conda's bin directory to PATH if the profile.d script isn't found
            export PATH="$CONDA_PATH/bin:$PATH"
        fi

        # Initialize Mamba if available
        if [ -f "$CONDA_PATH/etc/profile.d/mamba.sh" ]; then
            . "$CONDA_PATH/etc/profile.d/mamba.sh"
        fi

        # Break after initializing the first found Conda path
        break
    fi
done

# ----------------- Skip Conda Init -----------------
# Prevent 'conda init' from running again to avoid resetting setup
# conda init "$(basename "${SHELL}")" >/dev/null 2>&1

# Compilation flags
# export ARCHFLAGS="-arch x86_64 -arch arm64"

# Custom aliases
alias python="python3"
alias grep="grep --color=auto"

alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."


if [[ -f ~/.local/bin/scripts/check_aliases ]]; then
    . ~/.local/bin/scripts/check_aliases
fi

# zprof (commented out for speed)
# zprof

