<?php
// admin/theme_assets_lib.php
// Central registry for UI theme CSS files, metadata, and full design tokens.

if (!function_exists('ua_theme_registry')) {
  function ua_theme_registry(): array {
    return [
      'armoury_dark' => [
        'label' => 'Armoury Dark',
        'description' => 'Dark operations theme for monitoring and daily control.',
        'css' => null,
        'accent' => '#f5b000',
        'tokens' => [
          'ui_accent' => '#f5b000',
          'ui_text_color' => '#eaf0ff',
          'ui_border_color' => '#5b6573',
          'ui_body_bg' => '#080b12',
          'ui_surface_color' => '#101522',
          'ui_surface_alt_color' => '#182235',
          'ui_topbar_color' => '#121724',
          'ui_windowbar_color' => '#0f1420',
          'ui_sidebar_color' => '#0b101a',
          'ui_sidebar_item_color' => '#283247',
          'ui_input_color' => '#0d1422',
          'ui_input_text_color' => '#eaf0ff',
          'ui_table_head_color' => '#2a210f',
          'ui_table_row_color' => '#101827',
          'ui_table_row_alt_color' => '#141e30',
          'ui_menu_color' => '#101522',
          'ui_modal_color' => '#111827',
          'ui_alert_color' => '#231d10',
          'ui_security_alert_color' => '#44151d',
          'ui_font_family' => 'system',
          'ui_font_weight' => '700',
        ],
      ],
      'turquoise_isp' => [
        'label' => 'Turquoise ISP',
        'description' => 'The previous subscriber turquoise palette, promoted to a full theme.',
        'css' => 'assets/css/themes/turquoise_isp.css',
        'accent' => '#2dd4bf',
        'tokens' => [
          'ui_accent' => '#2dd4bf',
          'ui_text_color' => '#f4fffc',
          'ui_border_color' => '#2fb8ac',
          'ui_body_bg' => '#063f45',
          'ui_surface_color' => '#075450',
          'ui_surface_alt_color' => '#0b6b64',
          'ui_topbar_color' => '#062e38',
          'ui_windowbar_color' => '#073f45',
          'ui_sidebar_color' => '#042f37',
          'ui_sidebar_item_color' => '#0a7770',
          'ui_input_color' => '#042f35',
          'ui_input_text_color' => '#f4fffc',
          'ui_table_head_color' => '#c8d9df',
          'ui_table_row_color' => '#063e40',
          'ui_table_row_alt_color' => '#07494a',
          'ui_menu_color' => '#05383f',
          'ui_modal_color' => '#075450',
          'ui_alert_color' => '#0c5b5a',
          'ui_security_alert_color' => '#562028',
          'ui_font_family' => 'tahoma',
          'ui_font_weight' => '700',
        ],
      ],
      'dark_blue' => [
        'label' => 'Dark ISP Pro',
        'description' => 'Deep blue ISP operations palette.',
        'css' => 'assets/css/themes/dark_blue.css',
        'accent' => '#4f8cff',
        'tokens' => [
          'ui_accent' => '#4f8cff',
          'ui_text_color' => '#eaf2ff',
          'ui_border_color' => '#4f8cff',
          'ui_body_bg' => '#08111f',
          'ui_surface_color' => '#0e192d',
          'ui_surface_alt_color' => '#102344',
          'ui_topbar_color' => '#0a1c35',
          'ui_windowbar_color' => '#09172a',
          'ui_sidebar_color' => '#07162b',
          'ui_sidebar_item_color' => '#123a6f',
          'ui_input_color' => '#08182f',
          'ui_input_text_color' => '#eaf2ff',
          'ui_table_head_color' => '#123f78',
          'ui_table_row_color' => '#0a1f3d',
          'ui_table_row_alt_color' => '#0d284f',
          'ui_menu_color' => '#08172b',
          'ui_modal_color' => '#0e192d',
          'ui_alert_color' => '#102b4e',
          'ui_security_alert_color' => '#43151d',
          'ui_font_family' => 'system',
          'ui_font_weight' => '700',
        ],
      ],
      'whmcs_blue' => [
        'label' => 'WHMCS Blue',
        'description' => 'Clean light billing/admin palette.',
        'css' => 'assets/css/themes/whmcs_blue.css',
        'accent' => '#1a66ff',
        'tokens' => [
          'ui_accent' => '#1a66ff',
          'ui_text_color' => '#0b1220',
          'ui_border_color' => '#cbd5e1',
          'ui_body_bg' => '#f5f7fb',
          'ui_surface_color' => '#ffffff',
          'ui_surface_alt_color' => '#eef4ff',
          'ui_topbar_color' => '#ffffff',
          'ui_windowbar_color' => '#eaf1ff',
          'ui_sidebar_color' => '#123c69',
          'ui_sidebar_item_color' => '#1d5f9f',
          'ui_input_color' => '#ffffff',
          'ui_input_text_color' => '#0b1220',
          'ui_table_head_color' => '#d7e6ff',
          'ui_table_row_color' => '#ffffff',
          'ui_table_row_alt_color' => '#f1f5ff',
          'ui_menu_color' => '#ffffff',
          'ui_modal_color' => '#ffffff',
          'ui_alert_color' => '#dbeafe',
          'ui_security_alert_color' => '#fee2e2',
          'ui_font_family' => 'segoe',
          'ui_font_weight' => '600',
        ],
      ],
      'light_clean' => [
        'label' => 'Light Clean',
        'description' => 'Neutral light workspace palette.',
        'css' => 'assets/css/themes/light_clean.css',
        'accent' => '#0f766e',
        'tokens' => [
          'ui_accent' => '#0f766e',
          'ui_text_color' => '#0f172a',
          'ui_border_color' => '#c7d2da',
          'ui_body_bg' => '#f8fafc',
          'ui_surface_color' => '#ffffff',
          'ui_surface_alt_color' => '#eef5f7',
          'ui_topbar_color' => '#ffffff',
          'ui_windowbar_color' => '#eef5f7',
          'ui_sidebar_color' => '#172033',
          'ui_sidebar_item_color' => '#1f5f5a',
          'ui_input_color' => '#ffffff',
          'ui_input_text_color' => '#0f172a',
          'ui_table_head_color' => '#dbe5eb',
          'ui_table_row_color' => '#ffffff',
          'ui_table_row_alt_color' => '#f8fafc',
          'ui_menu_color' => '#ffffff',
          'ui_modal_color' => '#ffffff',
          'ui_alert_color' => '#e0f2fe',
          'ui_security_alert_color' => '#fee2e2',
          'ui_font_family' => 'segoe',
          'ui_font_weight' => '600',
        ],
      ],
      'neon_net' => [
        'label' => 'Network Neon',
        'description' => 'High contrast network monitoring palette.',
        'css' => 'assets/css/themes/neon_net.css',
        'accent' => '#22d3ee',
        'tokens' => [
          'ui_accent' => '#22d3ee',
          'ui_text_color' => '#eafffb',
          'ui_border_color' => '#22d3ee',
          'ui_body_bg' => '#05070c',
          'ui_surface_color' => '#0a0e16',
          'ui_surface_alt_color' => '#101735',
          'ui_topbar_color' => '#061923',
          'ui_windowbar_color' => '#04131d',
          'ui_sidebar_color' => '#04272b',
          'ui_sidebar_item_color' => '#103d56',
          'ui_input_color' => '#06151f',
          'ui_input_text_color' => '#eafffb',
          'ui_table_head_color' => '#0b3355',
          'ui_table_row_color' => '#071827',
          'ui_table_row_alt_color' => '#0b2033',
          'ui_menu_color' => '#06131c',
          'ui_modal_color' => '#071822',
          'ui_alert_color' => '#0b2e3a',
          'ui_security_alert_color' => '#3f1624',
          'ui_font_family' => 'system',
          'ui_font_weight' => '700',
        ],
      ],
      'green_isp' => [
        'label' => 'ISP Green',
        'description' => 'Green service-provider palette.',
        'css' => 'assets/css/themes/green_isp.css',
        'accent' => '#22c55e',
        'tokens' => [
          'ui_accent' => '#22c55e',
          'ui_text_color' => '#ecfff2',
          'ui_border_color' => '#2eb66a',
          'ui_body_bg' => '#07140c',
          'ui_surface_color' => '#0c1a12',
          'ui_surface_alt_color' => '#10291a',
          'ui_topbar_color' => '#0a2113',
          'ui_windowbar_color' => '#08190f',
          'ui_sidebar_color' => '#061f12',
          'ui_sidebar_item_color' => '#12562d',
          'ui_input_color' => '#07190f',
          'ui_input_text_color' => '#ecfff2',
          'ui_table_head_color' => '#104326',
          'ui_table_row_color' => '#0a2113',
          'ui_table_row_alt_color' => '#0d2a19',
          'ui_menu_color' => '#07180e',
          'ui_modal_color' => '#0c1a12',
          'ui_alert_color' => '#11341f',
          'ui_security_alert_color' => '#45171f',
          'ui_font_family' => 'system',
          'ui_font_weight' => '700',
        ],
      ],
    ];
  }
}

if (!function_exists('ua_theme_keys')) {
  function ua_theme_keys(): array {
    return array_keys(ua_theme_registry());
  }
}

if (!function_exists('ua_theme_design_tokens')) {
  function ua_theme_design_tokens(string $theme): array {
    $registry = ua_theme_registry();
    $theme = array_key_exists($theme, $registry) ? $theme : 'armoury_dark';
    $tokens = $registry[$theme]['tokens'] ?? [];
    return is_array($tokens) ? $tokens : [];
  }
}

if (!function_exists('ua_theme_legacy_options')) {
  function ua_theme_legacy_options(): array {
    $out = [];
    foreach (ua_theme_registry() as $key => $theme) {
      $out[$key] = [
        (string)($theme['label'] ?? $key),
        (string)($theme['description'] ?? ''),
        $theme['css'] ?? null,
        (string)($theme['accent'] ?? '#f5b000'),
      ];
    }
    return $out;
  }
}

if (!function_exists('ua_theme_css_path')) {
  function ua_theme_css_path(string $theme): string {
    $theme = basename(trim($theme));
    if ($theme === '' || $theme === 'armoury_dark') return '';
    $registry = ua_theme_registry();
    $css = (string)($registry[$theme]['css'] ?? '');
    if ($css === '') return '';
    return is_file(__DIR__ . '/' . $css) ? $css : '';
  }
}
