#!/usr/bin/env bash

UI_RESET=$'\033[0m'
UI_BOLD=$'\033[1m'
UI_BLUE=$'\033[34m'
UI_GREEN=$'\033[32m'
UI_YELLOW=$'\033[33m'
UI_RED=$'\033[31m'

ui_header() {
  local message="$1"
  printf '\n%s%s== %s ==%s\n\n' "$UI_BOLD" "$UI_BLUE" "$message" "$UI_RESET"
}

ui_section() {
  local message="$1"
  printf '%s[%s]%s\n' "$UI_BLUE" "$message" "$UI_RESET"
}

ui_info() {
  local message="$1"
  printf '%s[INFO]%s %s\n' "$UI_BLUE" "$UI_RESET" "$message"
}

ui_success() {
  local message="$1"
  printf '%s[OK]%s %s\n' "$UI_GREEN" "$UI_RESET" "$message"
}

ui_warn() {
  local message="$1"
  printf '%s[WARN]%s %s\n' "$UI_YELLOW" "$UI_RESET" "$message"
}

ui_error() {
  local message="$1"
  printf '%s[ERR]%s %s\n' "$UI_RED" "$UI_RESET" "$message" >&2
}

ui_menu() {
  local title="$1"
  shift
  local option

  ui_section "$title"
  for option in "$@"; do
    printf ' - %s\n' "$option"
  done
}

ui_confirm() {
  local prompt="$1"
  local answer=""

  read -r -p "$prompt [y/N] " answer
  [[ "$answer" =~ ^[Yy]$ ]]
}

ui_pause() {
  read -r -p "Appuyer sur Entree pour continuer... " _
}
