#!/usr/bin/env bash

function ui::policy::list_row() {
  local name="${1:-}" default_rule="${2:-}" strict="${3:-}" auto="${4:-}"
 
  local rule_val="-"
  [[ -n "$default_rule" ]] && rule_val="$default_rule"
 
  local rule_padded
  rule_padded=$(printf "%-16s" "$rule_val")
 
  local strict_display
  [[ "$strict" == "true" ]] && strict_display="yes" || strict_display="no"
  local strict_padded
  strict_padded=$(printf "%-4s" "$strict_display")
 
  local auto_display=""
  [[ "$auto" == "false" ]] && auto_display="  \033[2mauto:\033[0m no"
 
  printf "  %-14s  \033[2mrule:\033[0m %s  \033[2mstrict:\033[0m %s%s\n" \
    "$name" "$rule_padded" "$strict_padded" "$auto_display"
}

function ui::policy::detail_field() {
  local key="${1:-}" value="${2:-}"
  ui::row "$key" "$value"
}

# ======================================================
# Table view
# ======================================================

function ui::policy::list_header_table() {
  printf "\n  %-16s %-8s %-14s %-8s %s\n" \
    "NAME" "TUNNEL" "DEFAULT RULE" "STRICT" "AUTO"
  printf "  %s\n" "$(printf '─%.0s' {1..60})"
}
 
function ui::policy::list_row_table() {
  local name="${1:-}" tunnel="${2:-}" default_rule="${3:-}" \
        strict="${4:-}" auto="${5:-}"
  printf "  %-16s %-8s %-14s %-8s %s\n" \
    "$name" "$tunnel" "${default_rule:--}" "$strict" "$auto"
}
 