# ~/.zshrc - macOS Tahoe / Zsh

# Hanya jalankan konfigurasi ini pada shell interaktif.
[[ -o interactive ]] || return

# -----------------------------------------------------------------------------
# Homebrew (Apple Silicon)
# -----------------------------------------------------------------------------
if [[ -x /opt/homebrew/bin/brew ]]; then
    eval "$(/opt/homebrew/bin/brew shellenv)"
fi

# -----------------------------------------------------------------------------
# History
# -----------------------------------------------------------------------------
HISTFILE="$HOME/.zsh_history"
HISTSIZE=100000
SAVEHIST=500000

setopt APPEND_HISTORY
setopt INC_APPEND_HISTORY
setopt HIST_IGNORE_ALL_DUPS
setopt HIST_SAVE_NO_DUPS
setopt HIST_REDUCE_BLANKS
setopt HIST_IGNORE_SPACE
setopt EXTENDED_HISTORY

# -----------------------------------------------------------------------------
# Aliases
# -----------------------------------------------------------------------------
alias sudo='sudo '

# GNU ls dari Homebrew + vivid bila tersedia.
if command -v gls >/dev/null 2>&1; then
    alias ls='gls -lah --color=auto'
else
    # Fallback ke BSD ls bawaan macOS.
    alias ls='ls -lahG'
fi

if command -v tree >/dev/null 2>&1; then
    alias treeall='tree -ugsh --du'
fi

# File alias tambahan per-user.
[[ -f "$HOME/.zsh_aliases" ]] && source "$HOME/.zsh_aliases"

# -----------------------------------------------------------------------------
# Completion Zsh
# -----------------------------------------------------------------------------
autoload -Uz compinit
compinit -d "$HOME/.zcompdump"

# -----------------------------------------------------------------------------
# Custom prompt
# -----------------------------------------------------------------------------
[[ -f /usr/local/etc/shell-prompt.zsh ]] && source /usr/local/etc/shell-prompt.zsh

# -----------------------------------------------------------------------------
# LS_COLORS dengan tema vivid yang berubah berdasarkan tanggal
# -----------------------------------------------------------------------------
if command -v vivid >/dev/null 2>&1; then
    themes=(
        alabaster_dark ayu catppuccin-frappe catppuccin-latte dracula
        iceberg-dark jellybeans lava molokai nord one-dark one-light
        rose-pine rose-pine-dawn snazzy solarized-dark tokyonight-moon zenburn
    )

    current_date=$(date +%Y%m%d)
    random_index=$(( 10#$current_date % ${#themes[@]} + 1 ))
    theme_now=${themes[$random_index]}
    export LS_COLORS="$(vivid generate "$theme_now")"
fi

# -----------------------------------------------------------------------------
# Fastfetch
# -----------------------------------------------------------------------------
if command -v fastfetch >/dev/null 2>&1; then
    fastfetch --config "$HOME/.config/fastfetch/config.jsonc"
fi
