# shellcheck disable=SC2034

get_hardware_info() {
  local mem_ko  ram_pretty disk_ko disk_pretty
    # RAM Totale (on la récupère en Ko dans /proc/meminfo)
    mem_ko=$(awk '/MemTotal/ {print $2}' /proc/meminfo)
    ram_pretty=$(format_size "$mem_ko")

    # DISQUE Total (on le récupère en Ko avec df -k)
    disk_ko=$(df -k / | awk 'NR==2 {print $2}')
    disk_pretty=$(format_size "$disk_ko")

    F_HARD="Core=${COLOR_WHITE}$(nproc) ${COLOR_YELLOW}M=${COLOR_WHITE}${ram_pretty} ${COLOR_YELLOW}D=${COLOR_WHITE}${disk_pretty}"

  F_CPU="${COLOR_WHITE}$(LC_ALL=C lscpu | awk -F: '
      /BIOS Model name/ {
          gsub(/^[ \t]+/, "", $2)
          print $2
          found=1
          exit
      }

      /Model name/ && !found {
          model=$2
          gsub(/^[ \t]+/, "", model)
      }

      END {
          if (!found)
              print model
      }
  ' | sed 's/ @ / /; s/(R)//g; s/(TM)//g; s/ CPU//g; s/  */ /g; s/[ \t]*$//')"
}

get_network_info() {
    F_IPS="${COLOR_WHITE}$(hostname -I)"
}

get_uptime_info() {
    local s
    s=$(cut -d. -f1 /proc/uptime)
    F_UPT="${COLOR_WHITE}$(printf "%dj %02dh %02dm" $((s/86400)) $((s/3600%24)) $((s/60%60)))"
}

get_memory_info() {
    local m m_tot
    m=($(free -m | awk '/Mem:/ {print $2, $3}'))
    m_tot=${m[0]} m_use=${m[1]}
    M_PCT=$((m_use * 100 / m_tot))
    F_BAR_MEM=$(draw_bar "${M_PCT}")
}

get_load_info() {
    read -r one rest < /proc/loadavg
    local cpu_dec=${one#*.}
    [[ "$one" == *"."* && "${cpu_dec//0/}" != "" ]] && local val=$((${one%.*} + 1)) || local val=${one%.*}
    F_BAR_CPU="$(draw_bar "$val")"
}

get_disk_info() {
    local d
    d=$(df / | awk 'NR==2 {print $5}' | sed 's/%//')
    F_BAR_DSK="$(draw_bar "$d")"
}

get_user_info() {
    F_USR="${COLOR_WHITE}$(awk -F: '$3 >= 1000 && $7 !~ /(nologin|false)/ {count++} END {print count+1}' /etc/passwd)"
}

get_os_info() {
  local distrib_id distrib_name version_id codename

  # --- INFOS SYSTÈME ---
  distrib_id=$(grep '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"')
  distrib_name="${distrib_id^}" # Debian, Ubuntu...

  version_id=$(grep '^VERSION_ID=' /etc/os-release | cut -d= -f2 | tr -d '"')

  codename=$(grep '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2 | tr -d '"')
  codename="${codename^}"

  logo_os='🐧'
  if [ "$distrib_name" = "Debian" ]; then
    logo_os='🌀'
  fi

  # Résultat final : "Debian 12 (Bookworm)"
  F_OS="${COLOR_CYAN} ${logo_os}${distrib_name} ${version_id} ${COLOR_LIGHT_BLUE}(${codename})"
}