<?php
// admin/ui_design_system.php
// Central registry for the new gradual UI design system.

if (!function_exists('ua_design_setting_defaults')) {
  function ua_design_setting_defaults(): array {
    return [
      'ui_design_mode' => 'v2',
      'ui_theme' => 'armoury_dark',
      'ui_accent' => '',
      'ui_density' => 'comfy',
      'ui_radius' => '16',
      'ui_sidebar' => 'hover',
      'ui_font_family' => 'system',
      'ui_font_size' => '15',
      'ui_font_weight' => '700',
      'ui_text_color' => '',
      'ui_border_color' => '',
      'ui_border_style' => 'solid',
      'ui_border_width' => '1',
      'ui_card_style' => 'soft',
      'ui_page_max_width' => 'none',
      'ui_control_height' => '40',
      'ui_table_row_height' => '46',
      'ui_surface_alpha' => '82',
      'ui_menu_alpha' => '76',
      'ui_spacing_scale' => 'normal',

      // Unified template-controlled color tokens. Empty values are avoided here
      // so every page has a deterministic source of truth even before DB save.
      'ui_body_bg' => '#07111f',
      'ui_surface_color' => '#071827',
      'ui_surface_alt_color' => '#0a2431',
      'ui_topbar_color' => '#071a28',
      'ui_windowbar_color' => '#071624',
      'ui_sidebar_color' => '#063238',
      'ui_sidebar_item_color' => '#0b4a4d',
      'ui_input_color' => '#061d2a',
      'ui_input_text_color' => '#eaf0ff',
      'ui_table_head_color' => '#08373e',
      'ui_table_row_color' => '#062532',
      'ui_table_row_alt_color' => '#082e3a',
      'ui_menu_color' => '#061923',
      'ui_modal_color' => '#071827',
      'ui_alert_color' => '#102b3f',
      'ui_security_alert_color' => '#44151d',

      // Granular typography tokens.
      'ui_title_font_size' => '22',
      'ui_bar_font_size' => '12',
      'ui_input_font_size' => '13',
      'ui_table_font_size' => '13',
      'ui_menu_font_size' => '13',
      'ui_modal_font_size' => '14',
    ];
  }
}

if (!function_exists('ua_design_choice')) {
  function ua_design_choice($value, array $allowed, string $fallback): string {
    $value = is_scalar($value) ? (string)$value : '';
    return in_array($value, $allowed, true) ? $value : $fallback;
  }
}

if (!function_exists('ua_design_int_range')) {
  function ua_design_int_range($value, int $min, int $max, int $fallback): int {
    $value = (int)$value;
    if ($value < $min || $value > $max) return $fallback;
    return $value;
  }
}

if (!function_exists('ua_design_hex_or_empty')) {
  function ua_design_hex_or_empty($value): string {
    $value = trim((string)$value);
    if ($value === '') return '';
    if ($value[0] !== '#') $value = '#' . $value;
    return preg_match('/^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/', $value) ? $value : '';
  }
}

if (!function_exists('ua_design_mode_class')) {
  function ua_design_mode_class(string $mode): string {
    return $mode === 'v2' ? 'ua-design-v2' : 'ua-design-legacy';
  }
}
