#!/usr/bin/env bash
# ui/hosts.module.sh — rendering for hosts data

function ui::hosts::section_header() {
  local type="${1:-}"
  case "$type" in
    host)   printf "  \033[0;37mHosts\033[0m\n"   ;;
    subnet) printf "  \033[0;37mSubnets\033[0m\n" ;;
    port)   printf "  \033[0;37mPorts\033[0m\n"   ;;
  esac
}

# ui::hosts::list_row <type> <key> <name> <desc> <tags> <w_key> <w_name> <w_desc>
function ui::hosts::list_row() {
  local type="${1:-}" key="${2:-}" name="${3:-}" desc="${4:-}" tags="${5:-}" \
        w_key="${6:-15}" w_name="${7:-16}" w_desc="${8:-10}"

  local key_pad name_pad desc_val
  key_pad=$(printf  "%-${w_key}s"  "$key")
  name_pad=$(printf "%-${w_name}s" "$name")
  desc_val="${desc:--}"

  local desc_pad_n=$(( w_desc - ${#desc_val} ))
  [[ $desc_pad_n -lt 0 ]] && desc_pad_n=0

  local tags_display=""
  [[ -n "$tags" ]] && tags_display="\033[2m[${tags//,/, }]\033[0m"

  printf "  %s  %s  %s%*s  %b\n" \
    "$key_pad" "$name_pad" "$desc_val" "$desc_pad_n" "" "$tags_display"
}

# Table version (kept for future display config)
function ui::hosts::list_row_table() {
  local type="${1:-}" key="${2:-}" name="${3:-}" desc="${4:-}" tags="${5:-}"
  printf "  %-6s %-18s %-16s %-30s %s\n" \
    "$type" "$key" "$name" "${desc:-—}" "${tags:-—}"
}

function ui::hosts::list_header_table() {
  printf "\n  %-6s %-18s %-16s %-30s %s\n" \
    "TYPE" "KEY" "NAME" "DESCRIPTION" "TAGS"
  printf "  %s\n" "$(printf '─%.0s' {1..80})"
}