#!/usr/bin/env bash
# PS1 module with Nerd Font fallback + disable switch
# Designed for bash 3.2+ (macOS) and bash 4/5 (Linux)
# Load this in interactive shells.

case "$-" in
  *i*) ;;
  *) return 0 ;;
esac

# Disable switch (per-user/per-shell)
# 1) env: DISABLE_GLOBAL_PS1=1
# 2) file: ~/.config/ps1/disable
if [[ "${DISABLE_GLOBAL_PS1:-0}" == "1" ]]; then
  return 0
fi
if [[ -f "$HOME/.config/ps1/disable" ]]; then
  return 0
fi

# Force NF separators globally (rounded caps) unless ASCII is forced.
export PS1_FORCE_NF=1

# Nerd Font detection (best-effort) + overrides
#   PS1_FORCE_ASCII=1 -> always fallback separators
#   PS1_FORCE_NF=1    -> always Nerd Font separators
_ps1_has_nf() {
  if [[ "${PS1_FORCE_ASCII:-0}" == "1" ]]; then return 1; fi
  if [[ "${PS1_FORCE_NF:-0}" == "1" ]]; then return 0; fi

  # Linux/WSL: fontconfig often available
  if command -v fc-list >/dev/null 2>&1; then
    fc-list 2>/dev/null | grep -qi "Nerd Font" && return 0
  fi

  # macOS: fontconfig often not present; default to fallback unless forced
  return 1
}

# Season selection (dynamic or static)
#   PS1_SEASON_MODE=dynamic|static
#   PS1_SEASON= winter|spring|summer|autumn
# Also reads config from /etc/ps1-season or ~/.config/ps1/season
_ps1_season_config() {
  local cfg=""
  if [[ -r /etc/ps1-season ]]; then
    cfg="/etc/ps1-season"
  elif [[ -r "$HOME/.config/ps1/season" ]]; then
    cfg="$HOME/.config/ps1/season"
  fi

  if [[ -n "$cfg" ]]; then
    while IFS='=' read -r k v; do
      k="${k//[[:space:]]/}"
      v="${v//[[:space:]]/}"
      case "$k" in
        PS1_SEASON_MODE) export PS1_SEASON_MODE="$v" ;;
        PS1_SEASON) export PS1_SEASON="$v" ;;
      esac
    done < "$cfg"
  fi
}

_ps1_season_dynamic() {
  local mm dd m d
  mm=$(TZ=Europe/Oslo date +%m); dd=$(TZ=Europe/Oslo date +%d)
  m=$((10#$mm)); d=$((10#$dd))

  if (( m >= 3 && m <= 5 )); then
    echo "spring"
  elif (( m >= 6 && m <= 8 )); then
    echo "summer"
  elif (( m == 9 || m == 10 || (m == 11 && d < 15) )); then
    echo "autumn"
  else
    echo "winter"
  fi
}

_ps1_season() {
  _ps1_season_config
  local mode="${PS1_SEASON_MODE:-dynamic}"
  local season="${PS1_SEASON:-}"

  if [[ "$mode" == "static" && -n "$season" ]]; then
    echo "$season"
  else
    _ps1_season_dynamic
  fi
}

# Style selection (aurora/neon/forge/circuit/mono/git/hawolex + custom pack)
#   PS1_STYLE=aurora|neon|forge|circuit|mono|git|hawolex|hawolexv2|radar|synthwave|noir|topo|glitch|arcticfire|acidlime
#   PS1_STYLE_PACK=standard|contest|holiday|custom
#   PS1_CONTEST_LAYOUT=day-time-user|user-time|time-user|day-time
#   PS1_HOLIDAY=christmas|easter|halloween|valentine|thanksgiving|newyear
#   PS1_GIT=0|1
# Also reads config from /etc/ps1-style or ~/.config/ps1/style
_ps1_style_config() {
  local cfg=""
  if [[ -r /etc/ps1-style ]]; then
    cfg="/etc/ps1-style"
  elif [[ -r "$HOME/.config/ps1/style" ]]; then
    cfg="$HOME/.config/ps1/style"
  fi

  if [[ -n "$cfg" ]]; then
    while IFS='=' read -r k v; do
      k="${k//[[:space:]]/}"
      v="${v//[[:space:]]/}"
      case "$k" in
        PS1_STYLE) export PS1_STYLE="$v" ;;
        PS1_STYLE_PACK) export PS1_STYLE_PACK="$v" ;;
        PS1_CONTEST_LAYOUT) export PS1_CONTEST_LAYOUT="$v" ;;
        PS1_HOLIDAY) export PS1_HOLIDAY="$v" ;;
        PS1_GIT) export PS1_GIT="$v" ;;
      esac
    done < "$cfg"
  fi
}

_ps1_style() {
  _ps1_style_config
  local style="${PS1_STYLE:-aurora}"
  echo "$style"
}

_ps1_style_pack() {
  _ps1_style_config
  local pack="${PS1_STYLE_PACK:-standard}"
  echo "$pack"
}

_ps1_contest_layout() {
  _ps1_style_config
  local layout="${PS1_CONTEST_LAYOUT:-day-time-user}"
  echo "$layout"
}

_ps1_holiday() {
  _ps1_style_config
  local holiday="${PS1_HOLIDAY:-christmas}"
  echo "$holiday"
}

_ps1_git_enabled() {
  _ps1_style_config
  local v="${PS1_GIT:-0}"
  case "$v" in
    1|y|Y|yes|YES|true|TRUE|on|ON) echo "1" ;;
    *) echo "0" ;;
  esac
}

_ps1_git_line_tail() {
  if [[ "$(_ps1_git_enabled)" == "1" ]]; then
    export GIT_PS1_SHOWDIRTYSTATE=1
    export GIT_PS1_SHOWSTASHSTATE=1
    export GIT_PS1_SHOWUNTRACKEDFILES=1
    local info
    info="$(__git_capsule)"
    if [[ -n "$info" ]]; then
      printf "%s " "$info"
      return
    fi
  fi
  printf "  "
}

_ps1_context_badge() {
  local parts=()
  if [[ -n "${SSH_CONNECTION:-}" ]]; then
    parts+=("ssh")
  fi
  if [[ -f /.dockerenv || -f /run/.containerenv ]]; then
    parts+=("ctr")
  fi
  if command -v git >/dev/null 2>&1 && git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
    parts+=("git")
  fi
  if ((${#parts[@]} == 0)); then
    printf ""
    return
  fi
  printf "[%s] " "$(IFS=:; echo "${parts[*]}")"
}

_ps1_glitch_glyph() {
  local glyphs=( "≣" "∿" "⌁" "⋯" "⋆" "≡" )
  local idx=$((10#$(date +%S) % ${#glyphs[@]}))
  printf "%s" "${glyphs[$idx]}"
}

_ps1_path_topo() {
  local p="${__PS1_PATH}"
  local colors=(109 110 111 110)
  local out=""
  local idx=0
  local IFS='/'
  read -ra parts <<< "$p"
  for part in "${parts[@]}"; do
    if [[ -z "$part" ]]; then
      out+="/"
      continue
    fi
    local c="${colors[$((idx % ${#colors[@]}))]}"
    out+="\[\e[38;5;${c}m\]${part}\[\e[0m\]/"
    ((idx++))
  done
  out="${out%/}"
  printf "%s" "$out"
}


# ---- Load Git prompt helper (best effort) ----
__try_source_git_prompt() {
  local candidates=(
    "/usr/share/git/completion/git-prompt.sh"
    "/usr/local/etc/bash_completion.d/git-prompt.sh"
    "/etc/bash_completion.d/git-prompt.sh"
  )
  for f in "${candidates[@]}"; do
    [[ -r "$f" ]] && source "$f" && return 0
  done
  return 1
}
__try_source_git_prompt >/dev/null 2>&1

__git_capsule() {
  local info status=""
  local clean="✨"
  local dirty="🔨"
  local staged="📌"
  local untracked="🧷"
  local stashed="📦"
  local has_ps1=0

  if declare -F __git_ps1 >/dev/null 2>&1; then
    has_ps1=1
    info="$(__git_ps1 "%s" 2>/dev/null)"
    if [[ -z "$info" ]]; then
      has_ps1=0
    fi
  fi
  if [[ -z "$info" ]]; then
    if command -v git >/dev/null 2>&1; then
      info="$(git symbolic-ref --quiet --short HEAD 2>/dev/null || git rev-parse --short HEAD 2>/dev/null)"
    fi
  fi

  [[ -z "$info" ]] && return 0

  if (( has_ps1 )); then
    if [[ "$info" == *"*"* ]]; then status+=" $dirty"; fi
    if [[ "$info" == *"+"* ]]; then status+=" $staged"; fi
    if [[ "$info" == *"%"* ]]; then status+=" $untracked"; fi
    if [[ "$info" == *"$"* ]]; then status+=" $stashed"; fi
    if [[ -z "$status" ]]; then status=" $clean"; fi

    info="${info//\%/}"
    info="${info//\*/}"
    info="${info//\+/}"
    info="${info//\$/}"
  fi

  info="$(printf "%s" "$info" | xargs)"
  printf "  ⟦%s⟧%s" "$info" "$status"
}

# Time-based emoji with seasonal accents (Europe/Oslo)
_ps1_pick_icon() {
  local list_name="$1"
  local season="$2"
  local day
  local -a list
  local idx
  local offset=0

  day=$(TZ=Europe/Oslo date +%j)
  case "$season" in
    spring) offset=11 ;;
    summer) offset=23 ;;
    autumn) offset=37 ;;
    christmas) offset=61 ;;
    easter) offset=73 ;;
    halloween) offset=97 ;;
    valentine) offset=109 ;;
    thanksgiving) offset=131 ;;
    newyear) offset=151 ;;
    hawolex) offset=173 ;;
    *) offset=0 ;;
  esac

  eval "list=(\"\${${list_name}[@]}\")"
  if ((${#list[@]} == 0)); then
    echo ""
    return
  fi

  idx=$(( (10#$day + offset) % ${#list[@]} ))
  echo "${list[$idx]}"
}

_ps1_symbol() {
  local hh mm h m
  hh=$(TZ=Europe/Oslo date +%H); mm=$(TZ=Europe/Oslo date +%M)
  h=$((10#$hh)); m=$((10#$mm))

  local season="${__PS1_SEASON:-winter}"
  local pack="${__PS1_STYLE_PACK:-standard}"
  local holiday="${__PS1_HOLIDAY:-christmas}"
  local rot_season="${season}"
  local sunrise coffee work evening night
  local -a sunrise_list work_list

  if [[ "$__PS1_STYLE" == "hawolex" ]]; then
    rot_season="hawolex"
    sunrise_list=( "💻" "🚗" "🔊" "🎮" )
    work_list=( "🎧" "🕹️" "📟" "🧩" )
    coffee="☕"; evening="🌆"; night="🌙"
  elif [[ "$pack" == "contest" ]]; then
    rot_season="winter"
    sunrise_list=( "⚡️" "🛰️" "🧬" "🧠" )
    work_list=( "🛠️" "💾" "🧪" "🧩" )
    coffee="☕"; evening="🎛️"; night="🕶️"
  elif [[ "$pack" == "holiday" ]]; then
    rot_season="$holiday"
    case "$holiday" in
      christmas)
        sunrise_list=( "🎄" "🎅" "❄️" "⛄" )
        work_list=( "🎁" "🧤" "🧣" "🦌" )
        coffee="☕"; evening="🌟"; night="🕯️"
        ;;
      easter)
        sunrise_list=( "🐣" "🥚" "🌷" "🌤" )
        work_list=( "🐰" "🌼" "🧺" "🍫" )
        coffee="☕"; evening="🌅"; night="🌙"
        ;;
      halloween)
        sunrise_list=( "🎃" "🦇" "🌕" "🕸️" )
        work_list=( "👻" "💀" "🕯️" "🧪" )
        coffee="☕"; evening="🌆"; night="🕷️"
        ;;
      valentine)
        sunrise_list=( "💖" "🌹" "💘" "💕" )
        work_list=( "💌" "🍫" "🕊️" "💗" )
        coffee="☕"; evening="🌆"; night="🌙"
        ;;
      thanksgiving)
        sunrise_list=( "🦃" "🍁" "🥧" "🍂" )
        work_list=( "🍽️" "🌾" "🧺" "🥖" )
        coffee="☕"; evening="🌆"; night="🌙"
        ;;
      newyear)
        sunrise_list=( "🎆" "🥂" "🎇" "✨" )
        work_list=( "🗓️" "⏳" "🚀" "✨" )
        coffee="☕"; evening="🌆"; night="🌙"
        ;;
      *)
        sunrise_list=( "🎉" "✨" "🎊" "🌟" )
        work_list=( "🧩" "🛠️" "💾" "🧪" )
        coffee="☕"; evening="🌆"; night="🌙"
        ;;
    esac
  else
  case "$season" in
    spring)
      sunrise_list=( "🌷" "🌱" "🐣" "🌤" )
      work_list=( "🌿" "🪴" "🐝" "🌼" )
      coffee="☕"; evening="🌤"; night="🌙"
      ;;
    summer)
      sunrise_list=( "🌞" "🏖️" "🌅" "🌤" )
      work_list=( "🏄" "🏖️" "🚤" "🌴" )
      coffee="🧃"; evening="🌇"; night="🌙"
      ;;
    autumn)
      sunrise_list=( "🍁" "🍂" "🌫️" "🌦️" )
      work_list=( "🍂" "🍄" "🎃" "🪵" )
      coffee="☕"; evening="🌆"; night="🌙"
      ;;
    *)
      sunrise_list=( "🏔️" "🌨️" "❄️" "🌌" )
      work_list=( "🎿" "⛷️" "🏂" "🧊" )
      coffee="☕"; evening="🌆"; night="🌙"
      ;;
  esac
  fi

  sunrise="$(_ps1_pick_icon sunrise_list "$rot_season")"
  work="$(_ps1_pick_icon work_list "$rot_season")"

  if (( h >= 5 && h <= 8 )); then echo "$sunrise"
  elif (( h >= 9 && h <= 10 )); then echo "$coffee"
  elif (( h == 11 && m < 30 )); then echo "🥪"
  elif (( (h == 11 && m >= 30) || (h >= 12 && h <= 15) )); then echo "$work"
  elif (( h == 16 )); then echo "🍲"
  elif (( h >= 17 && h <= 22 )); then echo "$evening"
  else echo "$night"
  fi
}

# Path shortening (keeps /home/user or /Users/user visible)
# bash 3.2 safe
_ps1_path() {
  local p="$PWD"
  local parts=()
  IFS='/' read -ra parts <<< "$p"

  if ((${#parts[@]} < 6)); then
    echo "$p"; return
  fi

  local n=${#parts[@]}
  echo "/${parts[1]}/${parts[2]}/…/${parts[$((n-2))]}/${parts[$((n-1))]}"
}

# Dynamic vars updated before each prompt
__PS1_SYM=""
__PS1_PATH=""
__PS1_STATUS=0
__PS1_USE_NF=0
__PS1_SEASON="winter"
__PS1_STYLE="aurora"
__PS1_STYLE_PACK="standard"
__PS1_CONTEST_LAYOUT="day-time-user"
__PS1_HOLIDAY="christmas"
__PS1_GIT=0

_ps1_set_prompt() {
  local RST="\[\e[0m\]"

  # Seasonal palettes (Z1 is darker than Z2)
  local Z1_BG Z1_FG Z2_BG Z2_FG Z3_BG Z4_BG Z5_BG PATH_FG FRAME
  local Z1_BG_CODE Z2_BG_CODE Z3_BG_CODE Z4_BG_CODE Z5_BG_CODE
  if [[ "$__PS1_STYLE_PACK" == "contest" ]]; then
    Z1_BG_CODE=24
    Z2_BG_CODE=31
    Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
    Z1_FG="\[\e[38;5;255m\]"
    Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
    Z2_FG="\[\e[38;5;255m\]"
    PATH_FG="\[\e[38;5;51m\]"
    FRAME="\[\e[38;5;23m\]"
  elif [[ "$__PS1_STYLE_PACK" == "holiday" ]]; then
    case "$__PS1_HOLIDAY" in
      christmas)
        Z1_BG_CODE=52
        Z2_BG_CODE=28
        Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
        Z1_FG="\[\e[38;5;255m\]"
        Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
        Z2_FG="\[\e[38;5;255m\]"
        PATH_FG="\[\e[38;5;194m\]"
        FRAME="\[\e[38;5;88m\]"
        ;;
      easter)
        Z1_BG_CODE=186
        Z2_BG_CODE=150
        Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
        Z1_FG="\[\e[38;5;16m\]"
        Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
        Z2_FG="\[\e[38;5;16m\]"
        PATH_FG="\[\e[38;5;94m\]"
        FRAME="\[\e[38;5;143m\]"
        ;;
      halloween)
        Z1_BG_CODE=53
        Z2_BG_CODE=166
        Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
        Z1_FG="\[\e[38;5;255m\]"
        Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
        Z2_FG="\[\e[38;5;16m\]"
        PATH_FG="\[\e[38;5;16m\]"
        FRAME="\[\e[38;5;89m\]"
        ;;
      valentine)
        Z1_BG_CODE=198
        Z2_BG_CODE=205
        Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
        Z1_FG="\[\e[38;5;255m\]"
        Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
        Z2_FG="\[\e[38;5;255m\]"
        PATH_FG="\[\e[38;5;224m\]"
        FRAME="\[\e[38;5;162m\]"
        ;;
      thanksgiving)
        Z1_BG_CODE=94
        Z2_BG_CODE=136
        Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
        Z1_FG="\[\e[38;5;230m\]"
        Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
        Z2_FG="\[\e[38;5;231m\]"
        PATH_FG="\[\e[38;5;223m\]"
        FRAME="\[\e[38;5;130m\]"
        ;;
      newyear)
        Z1_BG_CODE=17
        Z2_BG_CODE=20
        Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
        Z1_FG="\[\e[38;5;255m\]"
        Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
        Z2_FG="\[\e[38;5;255m\]"
        PATH_FG="\[\e[38;5;229m\]"
        FRAME="\[\e[38;5;19m\]"
        ;;
      *)
        Z1_BG_CODE=24
        Z2_BG_CODE=31
        Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
        Z1_FG="\[\e[38;5;255m\]"
        Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
        Z2_FG="\[\e[38;5;255m\]"
        Z3_BG_CODE="${Z2_BG_CODE}"
        Z4_BG_CODE="${Z2_BG_CODE}"
        Z5_BG_CODE="${Z2_BG_CODE}"
        Z3_BG="\[\e[48;5;${Z3_BG_CODE}m\]"
        Z4_BG="\[\e[48;5;${Z4_BG_CODE}m\]"
        Z5_BG="\[\e[48;5;${Z5_BG_CODE}m\]"
        PATH_FG="\[\e[38;5;51m\]"
        FRAME="\[\e[38;5;23m\]"
        ;;
    esac
  else
    case "$__PS1_SEASON" in
      spring)
        Z1_BG_CODE=68
        Z2_BG_CODE=70
        Z3_BG_CODE=72
        Z4_BG_CODE=121
        Z5_BG_CODE=120
        Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
        Z1_FG="\[\e[38;5;255m\]"
        Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
        Z2_FG="\[\e[38;5;22m\]"
        Z3_BG="\[\e[48;5;${Z3_BG_CODE}m\]"
        Z4_BG="\[\e[48;5;${Z4_BG_CODE}m\]"
        Z5_BG="\[\e[48;5;${Z5_BG_CODE}m\]"
        PATH_FG="\[\e[38;5;28m\]"
        FRAME="\[\e[38;5;65m\]"
        ;;
      summer)
        Z1_BG_CODE=141
        Z2_BG_CODE=142
        Z3_BG_CODE=143
        Z4_BG_CODE=214
        Z5_BG_CODE=208
        Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
        Z1_FG="\[\e[38;5;255m\]"
        Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
        Z2_FG="\[\e[38;5;0m\]"
        Z3_BG="\[\e[48;5;${Z3_BG_CODE}m\]"
        Z4_BG="\[\e[48;5;${Z4_BG_CODE}m\]"
        Z5_BG="\[\e[48;5;${Z5_BG_CODE}m\]"
        PATH_FG="\[\e[38;5;0m\]"
        FRAME="\[\e[38;5;130m\]"
        ;;
      autumn)
        Z1_BG_CODE=93
        Z2_BG_CODE=95
        Z3_BG_CODE=97
        Z4_BG_CODE=166
        Z5_BG_CODE=136
        Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
        Z1_FG="\[\e[38;5;255m\]"
        Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
        Z2_FG="\[\e[38;5;255m\]"
        Z3_BG="\[\e[48;5;${Z3_BG_CODE}m\]"
        Z4_BG="\[\e[48;5;${Z4_BG_CODE}m\]"
        Z5_BG="\[\e[48;5;${Z5_BG_CODE}m\]"
        PATH_FG="\[\e[38;5;223m\]"
        FRAME="\[\e[38;5;95m\]"
        ;;
      *)
        # winter (default)
        Z1_BG_CODE=59
        Z2_BG_CODE=61
        Z3_BG_CODE=63
        Z4_BG_CODE=38
        Z5_BG_CODE=37
        Z1_BG="\[\e[48;5;${Z1_BG_CODE}m\]"
        Z1_FG="\[\e[38;5;255m\]"
        Z2_BG="\[\e[48;5;${Z2_BG_CODE}m\]"
        Z2_FG="\[\e[38;5;255m\]"
        Z3_BG="\[\e[48;5;${Z3_BG_CODE}m\]"
        Z4_BG="\[\e[48;5;${Z4_BG_CODE}m\]"
        Z5_BG="\[\e[48;5;${Z5_BG_CODE}m\]"
        PATH_FG="\[\e[38;5;152m\]"
        FRAME="\[\e[38;5;60m\]"
        ;;
    esac
  fi

  # Status colors
  local OK="\[\e[38;5;76m\]"
  local BAD="\[\e[38;5;203m\]"
  local BOLD="\[\e[1m\]"
  local NOBOLD="\[\e[22m\]"

  local left right sep
  if [[ "$__PS1_USE_NF" -eq 1 ]]; then
    left=""; right=""; sep=""
  else
    left="["; right="]"; sep="▶"
  fi

  local prompt_sym
  if [[ "$__PS1_STATUS" -eq 0 ]]; then
    prompt_sym="${OK}${BOLD}➜${NOBOLD}${RST}"
  else
    prompt_sym="${BAD}${BOLD}➜${NOBOLD}${RST}"
  fi

  local style="${__PS1_STYLE:-aurora}"
  local git_tail=""
  if [[ "$style" != "git" ]]; then
    git_tail="$(_ps1_git_line_tail)"
  fi
  local L1="\\d \\A \\u"
  local L_HOST="@\\h"
  local PREFIX=""
  local HOST_PART="${L_HOST}"
  local PATH_PART="${__PS1_PATH}"
  local PATH_SEP=" "
  local END_PAD="  "
  local layout="${__PS1_CONTEST_LAYOUT:-day-time-user}"
  if [[ "$__PS1_STYLE_PACK" == "contest" || "$__PS1_STYLE_PACK" == "holiday" || "$__PS1_STYLE_PACK" == "standard" ]]; then
    case "$layout" in
      user-time) L1="\\u \\A" ;;
      time-user) L1="\\A \\u" ;;
      day-time) L1="\\d \\A" ;;
      *) L1="\\d \\A \\u" ;;
    esac
  fi
  if [[ "$__PS1_STYLE_PACK" == "contest" || "$__PS1_STYLE_PACK" == "holiday" ]]; then
    HOST_PART="@\\h - ${__PS1_PATH}"
    PATH_PART=""
    PATH_SEP=""
    PREFIX="\n"
  fi

  case "$style" in
    neon)
      local N1_BG_CODE=201
      local N2_BG_CODE=45
      local N1_BG="\[\e[48;5;${N1_BG_CODE}m\]"
      local N1_FG="\[\e[38;5;255m\]"
      local N2_BG="\[\e[48;5;${N2_BG_CODE}m\]"
      local N2_FG="\[\e[38;5;16m\]"
      local N_PATH_FG="\[\e[38;5;16m\]"
      local N_FRAME="\[\e[38;5;199m\]"
      local N_LEFT="${left}"
      local N_RIGHT="${right}"
      local N_SEP="${sep}"
      local N_LEFT_FG=""
      local N_RIGHT_FG=""
      if [[ "$__PS1_USE_NF" -eq 1 ]]; then
        N_LEFT=""
        N_RIGHT=""
        N_SEP=""
        N_LEFT_FG="\[\e[38;5;${N1_BG_CODE}m\]"
        N_RIGHT_FG="\[\e[38;5;${N2_BG_CODE}m\]"
      fi
      PS1="\
${PREFIX}${N_FRAME}╭─${RST}\
${N_LEFT_FG}${N_LEFT}${RST}${N1_BG}${N1_FG} ${BOLD}\\u${NOBOLD} \\d \\A ${RST}${N1_BG}${N2_BG}${N2_FG}${N_SEP}${RST}\
${N2_BG}${N2_FG} ${HOST_PART}${PATH_SEP}${N_PATH_FG}${PATH_PART}${END_PAD}${RST}${N_RIGHT_FG}${N_RIGHT}${RST}\
\n${N_FRAME}╰── ${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    forge)
      local F1_BG_CODE=94
      local F2_BG_CODE=166
      local F1_BG="\[\e[48;5;${F1_BG_CODE}m\]"
      local F1_FG="\[\e[38;5;230m\]"
      local F2_BG="\[\e[48;5;${F2_BG_CODE}m\]"
      local F2_FG="\[\e[38;5;231m\]"
      local F_PATH_FG="\[\e[38;5;224m\]"
      local F_FRAME="\[\e[38;5;130m\]"
      local F_LEFT="${left}"
      local F_RIGHT="${right}"
      local F_SEP="${sep}"
      local F_LEFT_FG=""
      local F_RIGHT_FG=""
      if [[ "$__PS1_USE_NF" -eq 1 ]]; then
        F_LEFT=""
        F_RIGHT=""
        F_SEP=""
        F_LEFT_FG="\[\e[38;5;${F1_BG_CODE}m\]"
        F_RIGHT_FG="\[\e[38;5;${F2_BG_CODE}m\]"
      fi
      PS1="\
${PREFIX}${F_FRAME}╭─${RST}\
${F_LEFT_FG}${F_LEFT}${RST}${F1_BG}${F1_FG} ${BOLD}${L1}${NOBOLD} ${RST}${F1_BG}${F2_BG}${F2_FG}${F_SEP}${RST}\
${F2_BG}${F2_FG} ${HOST_PART}${PATH_SEP}${F_PATH_FG}${PATH_PART}${END_PAD}${RST}${F_RIGHT_FG}${F_RIGHT}${RST}\
\n${F_FRAME}╰── ${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    circuit)
      local C_FG="\[\e[38;5;46m\]"
      local C_DIM="\[\e[38;5;22m\]"
      local C_PATH="\[\e[38;5;120m\]"
      PS1="\
${PREFIX}${C_DIM}┏━${RST}${C_FG}[${BOLD}\\u${NOBOLD} ${RST}${C_FG}\\A${RST}${C_DIM}]${RST}\
${C_DIM}━${RST}${C_FG}${HOST_PART}${RST}${PATH_SEP}${C_PATH}${PATH_PART}${RST}\
\n${C_DIM}┗━${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    mono)
      local M_FG="\[\e[38;5;250m\]"
      local M_DIM="\[\e[38;5;240m\]"
      PS1="\
${PREFIX}${M_FG}⟦${L1}⟧ ${M_DIM}${HOST_PART}${PATH_SEP}${M_FG}${PATH_PART}${RST}\
\n${M_DIM}└─${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    git)
      export GIT_PS1_SHOWDIRTYSTATE=1
      export GIT_PS1_SHOWSTASHSTATE=1
      export GIT_PS1_SHOWUNTRACKEDFILES=1
      local G_FRAME="\[\e[38;5;60m\]"
      local G_Z1_BG="\[\e[48;5;61m\]"
      local G_Z1_FG="\[\e[38;5;255m\]"
      local G_Z2_BG="\[\e[48;5;37m\]"
      local G_Z2_FG="\[\e[38;5;255m\]"
      local G_PATH_FG="\[\e[38;5;194m\]"
      local GIT_INFO="$(__git_capsule)"
      local G_LEFT=""
      local G_RIGHT=""
      local G_SEP=""
      local G_END_PAD=" "
      local G_LEFT_FG="\[\e[38;5;61m\]"
      local G_RIGHT_FG="\[\e[38;5;37m\]"
      PS1="\
${PREFIX}${G_FRAME}╭─${RST}\
${G_LEFT_FG}${G_LEFT}${RST}${G_Z1_BG}${G_Z1_FG} ${L1} ${RST}${G_Z1_BG}${G_Z2_BG}${G_Z2_FG}${G_SEP}${RST}\
${G_Z2_BG}${G_Z2_FG} ${HOST_PART}${PATH_SEP}${G_PATH_FG}${PATH_PART}${G_END_PAD}${RST}${G_RIGHT_FG}${G_RIGHT}${RST}\
\n${G_FRAME}╰── ${RST}${prompt_sym} ${__PS1_SYM}  ${GIT_INFO} "
      ;;
    hawolex)
      local H_FRAME="\[\e[38;5;24m\]"
      local H_Z1_BG="\[\e[48;5;54m\]"
      local H_Z1_FG="\[\e[38;5;255m\]"
      local H_Z2_BG="\[\e[48;5;31m\]"
      local H_Z2_FG="\[\e[38;5;255m\]"
      local H_PATH_FG="\[\e[38;5;230m\]"
      local H_LEFT=""
      local H_RIGHT=""
      local H_SEP=""
      local H_LEFT_FG="\[\e[38;5;54m\]"
      local H_RIGHT_FG="\[\e[38;5;31m\]"
      PS1="\
${PREFIX}${H_FRAME}╭─${RST}\
${H_LEFT_FG}${H_LEFT}${RST}${H_Z1_BG}${H_Z1_FG} ${L1} ${RST}${H_Z1_BG}${H_Z2_BG}${H_Z2_FG}${H_SEP}${RST}\
${H_Z2_BG}${H_Z2_FG} ${HOST_PART}${PATH_SEP}${H_PATH_FG}${PATH_PART}${END_PAD}${RST}${H_RIGHT_FG}${H_RIGHT}${RST}\
\n${H_FRAME}╰── ${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    hawolexv2)
      local HV2_FRAME="\[\e[38;5;24m\]"
      local HV2_1_BG="\[\e[48;5;54m\]"
      local HV2_1_FG="\[\e[38;5;255m\]"
      local HV2_2_BG="\[\e[48;5;55m\]"
      local HV2_2_FG="\[\e[38;5;255m\]"
      local HV2_3_BG="\[\e[48;5;56m\]"
      local HV2_3_FG="\[\e[38;5;255m\]"
      local HV2_4_BG="\[\e[48;5;31m\]"
      local HV2_4_FG="\[\e[38;5;255m\]"
      local HV2_5_BG="\[\e[48;5;30m\]"
      local HV2_PATH_FG="\[\e[38;5;230m\]"
      local HV2_LEFT="${left}"
      local HV2_RIGHT="${right}"
      local HV2_SEP="${sep}"
      local HV2_LEFT_FG=""
      local HV2_RIGHT_FG=""
      if [[ "$__PS1_USE_NF" -eq 1 ]]; then
        HV2_LEFT=""
        HV2_RIGHT=""
        HV2_SEP=""
        HV2_LEFT_FG="\[\e[38;5;54m\]"
        HV2_RIGHT_FG="\[\e[38;5;30m\]"
      fi
      local HV2_SEP12="\[\e[38;5;55m\]\[\e[48;5;54m\]${HV2_SEP}${RST}"
      local HV2_SEP23="\[\e[38;5;56m\]\[\e[48;5;55m\]${HV2_SEP}${RST}"
      local HV2_SEP34="\[\e[38;5;31m\]\[\e[48;5;56m\]${HV2_SEP}${RST}"
      local HV2_SEP45="\[\e[38;5;30m\]\[\e[48;5;31m\]${HV2_SEP}${RST}"
      local HV2_P1="" HV2_P2="" HV2_P3=""
      local HV2_LAYOUT="${__PS1_CONTEST_LAYOUT:-day-time-user}"
      if [[ "$__PS1_STYLE_PACK" == "contest" || "$__PS1_STYLE_PACK" == "holiday" ]]; then
        case "$HV2_LAYOUT" in
          user-time) HV2_P1="\\u"; HV2_P2="\\A" ;;
          time-user) HV2_P1="\\A"; HV2_P2="\\u" ;;
          day-time) HV2_P1="\\d"; HV2_P2="\\A" ;;
          *) HV2_P1="\\d"; HV2_P2="\\A"; HV2_P3="\\u" ;;
        esac
      else
        HV2_P1="\\d"; HV2_P2="\\A"; HV2_P3="\\u"
      fi
      local HV2_HOST="@\\h"
      local HV2_PATH_PREFIX=""
      if [[ "$__PS1_STYLE_PACK" == "contest" || "$__PS1_STYLE_PACK" == "holiday" ]]; then
        HV2_PATH_PREFIX="- "
      fi
      if [[ -n "$HV2_P3" ]]; then
        PS1="\
${PREFIX}${HV2_FRAME}╭─${RST}\
${HV2_LEFT_FG}${HV2_LEFT}${RST}${HV2_1_BG}${HV2_1_FG} ${HV2_P1} ${RST}${HV2_SEP12}${HV2_2_BG}${HV2_2_FG} ${HV2_P2} ${RST}${HV2_SEP23}${HV2_3_BG}${HV2_3_FG} ${HV2_P3} ${RST}${HV2_SEP34}${HV2_4_BG}${HV2_4_FG} ${HV2_HOST} ${RST}${HV2_SEP45}${HV2_5_BG}${HV2_PATH_FG} ${HV2_PATH_PREFIX}${__PS1_PATH}${END_PAD}${RST}${HV2_RIGHT_FG}${HV2_RIGHT}${RST}\
\n${HV2_FRAME}╰── ${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      else
        PS1="\
${PREFIX}${HV2_FRAME}╭─${RST}\
${HV2_LEFT_FG}${HV2_LEFT}${RST}${HV2_1_BG}${HV2_1_FG} ${HV2_P1} ${RST}${HV2_SEP12}${HV2_2_BG}${HV2_2_FG} ${HV2_P2} ${RST}${HV2_SEP23}${HV2_3_BG}${HV2_3_FG} ${HV2_HOST} ${RST}${HV2_SEP34}${HV2_4_BG}${HV2_4_FG} ${HV2_PATH_PREFIX}${__PS1_PATH}${END_PAD}${RST}${HV2_RIGHT_FG}${HV2_RIGHT}${RST}\
\n${HV2_FRAME}╰── ${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      fi
      ;;
    radar)
      local R_FRAME="\[\e[38;5;22m\]"
      local R_MAIN="\[\e[38;5;46m\]"
      local R_DIM="\[\e[38;5;28m\]"
      local R_PATH="\[\e[38;5;120m\]"
      PS1="\
${R_FRAME}╭─${RST}${R_MAIN}⟦\\u \\A⟧ ${R_DIM}@\\h ${R_PATH}${__PS1_PATH}${RST}\
\n${R_FRAME}╰─${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    synthwave)
      local SW_FRAME="\[\e[38;5;201m\]"
      local SW1_BG="\[\e[48;5;198m\]"
      local SW1_FG="\[\e[38;5;255m\]"
      local SW2_BG="\[\e[48;5;45m\]"
      local SW2_FG="\[\e[38;5;16m\]"
      local SW3_BG="\[\e[48;5;208m\]"
      local SW3_FG="\[\e[38;5;16m\]"
      local SW_LEFT="${left}"
      local SW_RIGHT="${right}"
      local SW_SEP="${sep}"
      local SW_LEFT_FG=""
      local SW_RIGHT_FG=""
      if [[ "$__PS1_USE_NF" -eq 1 ]]; then
        SW_LEFT=""
        SW_RIGHT=""
        SW_SEP=""
        SW_LEFT_FG="\[\e[38;5;198m\]"
        SW_RIGHT_FG="\[\e[38;5;208m\]"
      fi
      local SW_SEP12="\[\e[38;5;45m\]\[\e[48;5;198m\]${SW_SEP}${RST}"
      local SW_SEP23="\[\e[38;5;208m\]\[\e[48;5;45m\]${SW_SEP}${RST}"
      PS1="\
${SW_FRAME}╭─${RST}\
${SW_LEFT_FG}${SW_LEFT}${RST}${SW1_BG}${SW1_FG} ${L1} ${RST}${SW_SEP12}${SW2_BG}${SW2_FG} ${L_HOST} ${RST}${SW_SEP23}${SW3_BG}${SW3_FG} ${__PS1_PATH}${END_PAD}${RST}${SW_RIGHT_FG}${SW_RIGHT}${RST}\
\n${SW_FRAME}╰── ${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    noir)
      local N_FRAME="\[\e[38;5;236m\]"
      local N_MAIN="\[\e[38;5;250m\]"
      local N_DIM="\[\e[38;5;242m\]"
      local N_PATH="\[\e[38;5;160m\]"
      PS1="\
${N_FRAME}╭─${RST}${N_MAIN}${L1}${RST} ${N_DIM}${L_HOST}${RST} ${N_PATH}${__PS1_PATH}${RST}\
\n${N_FRAME}╰─${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    topo)
      local T_FRAME="\[\e[38;5;24m\]"
      local T_MAIN="\[\e[38;5;248m\]"
      PS1="\
${T_FRAME}╭─${RST}${T_MAIN}${L1}${RST} ${T_FRAME}${L_HOST}${RST} $(_ps1_path_topo)${END_PAD}${RST}\
\n${T_FRAME}╰─${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    glitch)
      local G_FRAME="\[\e[38;5;129m\]"
      local G_MAIN="\[\e[38;5;118m\]"
      local G_DIM="\[\e[38;5;60m\]"
      local G_SEP="$(_ps1_glitch_glyph)"
      PS1="\
${G_FRAME}╭─${RST}${G_MAIN}${L1}${RST} ${G_DIM}${G_SEP}${RST} ${G_MAIN}${L_HOST} ${RST}${G_DIM}${G_SEP}${RST} ${G_MAIN}${__PS1_PATH}${RST}\
\n${G_FRAME}╰─${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    arcticfire)
      local AF_FRAME="\[\e[38;5;25m\]"
      local AF1_BG="\[\e[48;5;24m\]"
      local AF1_FG="\[\e[38;5;255m\]"
      local AF2_BG="\[\e[48;5;31m\]"
      local AF2_FG="\[\e[38;5;255m\]"
      local AF3_BG="\[\e[48;5;208m\]"
      local AF3_FG="\[\e[38;5;16m\]"
      local AF_LEFT="${left}"
      local AF_RIGHT="${right}"
      local AF_SEP="${sep}"
      local AF_LEFT_FG=""
      local AF_RIGHT_FG=""
      if [[ "$__PS1_USE_NF" -eq 1 ]]; then
        AF_LEFT=""
        AF_RIGHT=""
        AF_SEP=""
        AF_LEFT_FG="\[\e[38;5;24m\]"
        AF_RIGHT_FG="\[\e[38;5;208m\]"
      fi
      local AF_SEP12="\[\e[38;5;31m\]\[\e[48;5;24m\]${AF_SEP}${RST}"
      local AF_SEP23="\[\e[38;5;208m\]\[\e[48;5;31m\]${AF_SEP}${RST}"
      PS1="\
${AF_FRAME}╭─${RST}\
${AF_LEFT_FG}${AF_LEFT}${RST}${AF1_BG}${AF1_FG} ${L1} ${RST}${AF_SEP12}${AF2_BG}${AF2_FG} ${L_HOST} ${RST}${AF_SEP23}${AF3_BG}${AF3_FG} ${__PS1_PATH}${END_PAD}${RST}${AF_RIGHT_FG}${AF_RIGHT}${RST}\
\n${AF_FRAME}╰── ${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    acidlime)
      local AL_FRAME="\[\e[38;5;46m\]"
      local AL_MAIN="\[\e[38;5;46m\]"
      local AL_DIM="\[\e[38;5;40m\]"
      local AL_PATH="\[\e[38;5;118m\]"
      PS1="\
${AL_FRAME}╭─${RST}${AL_MAIN}${L1}${RST} ${AL_DIM}${L_HOST}${RST} ${AL_PATH}${__PS1_PATH}${RST}\
\n${AL_FRAME}╰─${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      ;;
    *)
      # aurora (default)
      local A_LEFT="${left}"
      local A_RIGHT="${right}"
      local A_SEP="${sep}"
      local A_LEFT_FG=""
      local A_RIGHT_FG=""
      if [[ "$__PS1_USE_NF" -eq 1 ]]; then
        A_LEFT=""
        A_RIGHT=""
        A_SEP=""
        A_LEFT_FG="\[\e[38;5;${Z1_BG_CODE}m\]"
        A_RIGHT_FG="\[\e[38;5;${Z5_BG_CODE:-$Z2_BG_CODE}m\]"
      fi
      if [[ "$__PS1_STYLE_PACK" == "standard" && "$__PS1_USE_NF" -eq 1 ]]; then
        local SEP12="\[\e[38;5;${Z2_BG_CODE}m\]\[\e[48;5;${Z1_BG_CODE}m\]${A_SEP}${RST}"
        local SEP23="\[\e[38;5;${Z3_BG_CODE}m\]\[\e[48;5;${Z2_BG_CODE}m\]${A_SEP}${RST}"
        local SEP34="\[\e[38;5;${Z4_BG_CODE}m\]\[\e[48;5;${Z3_BG_CODE}m\]${A_SEP}${RST}"
        local SEP45="\[\e[38;5;${Z5_BG_CODE}m\]\[\e[48;5;${Z4_BG_CODE}m\]${A_SEP}${RST}"
        PS1="\
${PREFIX}${FRAME}╭─${RST}\
${A_LEFT_FG}${A_LEFT}${RST}${Z1_BG}${Z1_FG} \\d ${RST}${SEP12}${Z2_BG}${Z1_FG} \\A ${RST}${SEP23}${Z3_BG}${Z1_FG} \\u ${RST}${SEP34}${Z4_BG}${Z2_FG} ${L_HOST} ${RST}${SEP45}${Z5_BG}${PATH_FG} ${__PS1_PATH}${END_PAD}${RST}${A_RIGHT_FG}${A_RIGHT}${RST}\
\n${FRAME}╰── ${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      else
        PS1="\
${PREFIX}${FRAME}╭─${RST}\
${A_LEFT_FG}${A_LEFT}${RST}${Z1_BG}${Z1_FG} ${L1} ${RST}${Z1_BG}${Z2_BG}${Z2_FG}${A_SEP}${RST}\
${Z2_BG}${Z2_FG} ${HOST_PART}${PATH_SEP}${PATH_FG}${PATH_PART}${END_PAD}${RST}${A_RIGHT_FG}${A_RIGHT}${RST}\
\n${FRAME}╰── ${RST}${prompt_sym} ${__PS1_SYM}${git_tail}"
      fi
      ;;
  esac
}

_ps1_update() {
  __PS1_STATUS=$?
  __PS1_SEASON="$(_ps1_season)"
  __PS1_STYLE_PACK="$(_ps1_style_pack)"
  __PS1_CONTEST_LAYOUT="$(_ps1_contest_layout)"
  __PS1_HOLIDAY="$(_ps1_holiday)"
  __PS1_STYLE="$(_ps1_style)"
  __PS1_GIT="${PS1_GIT:-0}"
  __PS1_SYM="$(_ps1_symbol)"
  __PS1_PATH="$(_ps1_path)"
  if _ps1_has_nf; then __PS1_USE_NF=1; else __PS1_USE_NF=0; fi
  _ps1_set_prompt
}

ps1_on() {
  if [[ "${PROMPT_COMMAND:-}" != *"_ps1_update"* ]]; then
    if [[ -n "${PROMPT_COMMAND:-}" ]]; then
      PROMPT_COMMAND="${PROMPT_COMMAND}; _ps1_update"
    else
      PROMPT_COMMAND="_ps1_update"
    fi
  fi

  _ps1_set_prompt
}

ps1_off() { :; }

# Enable by default when loaded (global standard)
ps1_on
