<?php

/**
 * @file
 * Theme settings form: Appearance > MWRD Theme > Settings.
 */

use Drupal\Core\Form\FormStateInterface;

/**
 * Implements hook_form_FORM_ID_alter() for system_theme_settings.
 */
function mwrd_theme_form_system_theme_settings_alter(array &$form, FormStateInterface $form_state): void {
  $form['mwrd'] = [
    '#type' => 'details',
    '#title' => t('MWRD Colour Theme'),
    '#open' => TRUE,
  ];

  $form['mwrd']['active_theme'] = [
    '#type' => 'select',
    '#title' => t('Active Theme'),
    '#options' => [
      'navy' => t('Navy (Default)'),
      'red' => t('Red'),
      'green' => t('Green'),
      'blue' => t('Blue'),
      'custom' => t('Custom'),
    ],
    '#default_value' => theme_get_setting('active_theme') ?: 'navy',
  ];

  $fields = [
    'custom_navy'       => ['Custom Primary Color (Navy)', '#0B4A8F'],
    'custom_navy_dark'  => ['Custom Dark Color', '#073366'],
    'custom_navy_mid'   => ['Custom Mid Color', '#0F58A4'],
    'custom_teal'       => ['Custom Accent Color (Teal)', '#D35400'],
    'custom_teal_hover' => ['Custom Accent Hover', '#B84700'],
    'custom_light'      => ['Custom Light Background', '#F4F7FB'],
  ];

  foreach ($fields as $key => [$label, $default]) {
    $form['mwrd'][$key] = [
      '#type' => 'color',
      '#title' => t($label),
      '#default_value' => theme_get_setting($key) ?: $default,
      '#states' => [
        'visible' => [':input[name="active_theme"]' => ['value' => 'custom']],
      ],
    ];
  }
}
