<?php

/**
 * Customizer Color Setting
 * @package Glaciers
 * @since 1.0.0
 */

if (!defined('ABSPATH')) {
  exit; // Exit if accessed directly.
}

function glaciers_customize_register_colour($wp_customize)
{

  // Colour Options Panel
  $wp_customize->add_panel('colors', array(
    'priority' => 40,
    'title'    => esc_html__('Colours', 'glaciers'),
  ));

  // SECTION - PRESET COLOURS 
  $wp_customize->add_section('glaciers_preset_colours', array(
    'title' => esc_html__('Preset Colours', 'glaciers'),
    'priority' => 10,
    'panel' => 'colors'
  ));

  // SECTION - CONTENT COLOURS 
  $wp_customize->add_section('glaciers_content_colours', array(
    'title' => esc_html__('Content Colors', 'glaciers'),
    'priority' => 15,
    'panel' => 'colors'
  ));

  // SECTION - NAV COLOURS
  $wp_customize->add_section('glaciers_nav_colours', array(
    'title' => esc_html__('Navigation Colors', 'glaciers'),
    'priority' => 20,
    'panel' => 'colors'
  ));

  /* PRESET SETTINGS
@since 1.0.0
==================================================== */
  // Presets
  $wp_customize->add_setting(
    'glaciers_presets',
    array(
      'default' => 'preset1',
      'sanitize_callback' => 'glaciers_sanitize_select',
    )
  );

  $wp_customize->add_control(
    new Glaciers_Radio_Image_Control(
      $wp_customize,
      'glaciers_presets',
      array(
        'label' => esc_html__('Preset Groups', 'glaciers'),
        'description' => esc_html__('Choose a preset colour palette for your theme. This will load a variety of accent colours for select elements in your page.', 'glaciers'),
        'section' => 'glaciers_preset_colours',
        'type' => 'radio-image',
        'choices' => glaciers_colour_preset_options()
      )
    )
  );


  /** Enable Custom Accent Colours */
  $wp_customize->add_setting(
    'glaciers_custom_accent_colours',
    array(
      'default'           => false,
      'sanitize_callback' => 'glaciers_sanitize_checkbox',
    )
  );

  $wp_customize->add_control(
    new Glaciers_Toggle_Control(
      $wp_customize,
      'glaciers_custom_accent_colours',
      array(
        'section'     => 'glaciers_preset_colours',
        'label'        => esc_html__('Custom Accent Colours', 'glaciers'),
        'description' => esc_html__('Enable to change the theme accent colours to be your own.', 'glaciers'),
      )
    )
  );


  // Custom Primary Colour
  $wp_customize->add_setting('glaciers_custom_primary_colour', array(
    'default'           => '#35a0a7',
    'transport' => 'postMessage',
    'sanitize_callback' => 'glaciers_sanitize_hex_colour'
  ));

  $wp_customize->add_control(new WP_Customize_Color_Control(
    $wp_customize,
    'glaciers_custom_primary_colour',
    array(
      'label'       => esc_html__('Primary Colour', 'glaciers'),
      'description' => esc_html__('Sets a custom primary accent colour for your theme.', 'glaciers'),
      'section'     => 'glaciers_preset_colours',
      'active_callback' => 'glaciers_custom_accent_colours_show',
    )
  ));

  // Custom Secondary Colour
  $wp_customize->add_setting('glaciers_custom_secondary_colour', array(
    'default'           => '#c6975e',
    'transport' => 'postMessage',
    'sanitize_callback' => 'glaciers_sanitize_hex_colour'
  ));

  $wp_customize->add_control(new WP_Customize_Color_Control(
    $wp_customize,
    'glaciers_custom_secondary_colour',
    array(
      'label'       => esc_html__('Secondary Colour', 'glaciers'),
      'description' => esc_html__('Sets a custom secondary accent colour for your theme.', 'glaciers'),
      'section'     => 'glaciers_preset_colours',
      'active_callback' => 'glaciers_custom_accent_colours_show',
    )
  ));

  // Custom Tertiary Colour
  $wp_customize->add_setting('glaciers_custom_tertiary_colour', array(
    'default'           => '#145559',
    'transport' => 'postMessage',
    'sanitize_callback' => 'glaciers_sanitize_hex_colour'
  ));

  $wp_customize->add_control(new WP_Customize_Color_Control(
    $wp_customize,
    'glaciers_custom_tertiary_colour',
    array(
      'label'       => esc_html__('Tertiary Colour', 'glaciers'),
      'description' => esc_html__('Sets a custom tertiary (third) accent colour for your theme.', 'glaciers'),
      'section'     => 'glaciers_preset_colours',
      'active_callback' => 'glaciers_custom_accent_colours_show',
    )
  ));

  /* CONTENT COLOUR SETTINGS
==================================================== */
  $wp_customize->add_setting('glaciers_content_bg_colour', array(
    'default'           => '#ffffff',
    'transport' => 'postMessage',
    'sanitize_callback' => 'glaciers_sanitize_hex_colour'
  ));

  $wp_customize->add_control(new WP_Customize_Color_Control(
    $wp_customize,
    'glaciers_content_bg_colour',
    array(
      'label'       => esc_html__('Content Area Background', 'glaciers'),
      'description' => esc_html__('Unless a preset changes the colour, you can customize your content area background colour.', 'glaciers'),
      'section'     => 'colors',
    )
  ));

  // Body text colour
  $wp_customize->add_setting(
    'glaciers_content_area_text_colour',
    array(
      'default' => '#646464',
      'sanitize_callback' => 'glaciers_sanitize_hex_colour',
      'transport' => 'postMessage'
    )
  );

  $wp_customize->add_control(
    new WP_Customize_Color_Control(
      $wp_customize,
      'glaciers_content_area_text_colour',
      array(
        'label' => esc_html__('Body Text Colour', 'glaciers'),
        'section' => 'colors',
        'settings' => 'glaciers_content_area_text_colour',
      )
    )
  );

  // Headings colour
  $wp_customize->add_setting(
    'glaciers_headings_colour',
    array(
      'default' => '#292929',
      'sanitize_callback' => 'glaciers_sanitize_hex_colour',
      'transport' => 'postMessage'
    )
  );

  $wp_customize->add_control(
    new WP_Customize_Color_Control(
      $wp_customize,
      'glaciers_headings_colour',
      array(
        'label' => esc_html__('Headings Colour', 'glaciers'),
        'section' => 'colors',
        'settings' => 'glaciers_headings_colour',
      )
    )
  );


  // Content links
  $wp_customize->add_setting(
    'glaciers_content_links',
    array(
      'default' => '#35a0a7',
      'sanitize_callback' => 'glaciers_sanitize_hex_colour',
      'transport' => 'postMessage'
    )
  );

  $wp_customize->add_control(
    new WP_Customize_Color_Control(
      $wp_customize,
      'glaciers_content_links',
      array(
        'label' => esc_html__('Content Links', 'glaciers'),
        'section' => 'colors',
        'settings' => 'glaciers_content_links',
      )
    )
  );

  // Category prefix
  $wp_customize->add_setting(
    'glaciers_category_prefix',
    array(
      'default' => '#c6975e',
      'sanitize_callback' => 'glaciers_sanitize_hex_colour',
      'transport' => 'postMessage'
    )
  );

  $wp_customize->add_control(
    new WP_Customize_Color_Control(
      $wp_customize,
      'glaciers_category_prefix',
      array(
        'label' => esc_html__('Category Title Prefix', 'glaciers'),
        'section' => 'colors',
        'settings' => 'glaciers_category_prefix',
      )
    )
  );

  // Banner caption bg background
  $wp_customize->add_setting(
    'glaciers_image_bg_caption',
    array(
      'default' => '#000000',
      'sanitize_callback' => 'glaciers_sanitize_hex_colour',
      'transport' => 'postMessage'
    )
  );

  $wp_customize->add_control(
    new WP_Customize_Color_Control(
      $wp_customize,
      'glaciers_image_bg_caption',
      array(
        'label' => esc_html__('Image Caption Background Colour', 'glaciers'),
        'section' => 'colors',
        'settings' => 'glaciers_image_bg_caption',
      )
    )
  );

  // Image overlay caption text
  $wp_customize->add_setting(
    'glaciers_caption_text_color',
    array(
      'default' => '#292929',
      'sanitize_callback' => 'glaciers_sanitize_hex_colour',
      'transport' => 'postMessage'
    )
  );

  $wp_customize->add_control(
    new WP_Customize_Color_Control(
      $wp_customize,
      'glaciers_caption_text_color',
      array(
        'label' => esc_html__('Caption Overlay Text Colour', 'glaciers'),
        'section' => 'colors',
        'settings' => 'glaciers_caption_text_color',
      )
    )
  );

  // Footer text
  $wp_customize->add_setting(
    'glaciers_footer_text',
    array(
      'default' => '#9ba4ad',
      'sanitize_callback' => 'glaciers_sanitize_hex_colour',
      'transport' => 'postMessage'
    )
  );

  $wp_customize->add_control(
    new WP_Customize_Color_Control(
      $wp_customize,
      'glaciers_footer_text',
      array(
        'label' => esc_html__('Footer Area Text', 'glaciers'),
        'section' => 'colors',
        'settings' => 'glaciers_footer_text',
      )
    )
  );

  /* NAVIGATION COLOUR SETTINGS
==================================================== */
  $wp_customize->add_setting('glaciers_nav_link_colour', array(
    'default'           => '#495057',
    'transport' => 'postMessage',
    'sanitize_callback' => 'glaciers_sanitize_hex_colour'
  ));

  $wp_customize->add_control(new WP_Customize_Color_Control(
    $wp_customize,
    'glaciers_nav_link_colour',
    array(
      'label'       => esc_html__('Primary Nav Link Colour', 'glaciers'),
      'description' => esc_html__('This sets the colour for your primary menu links.', 'glaciers'),
      'section'     => 'glaciers_nav_colours',
    )
  ));
}
add_action('customize_register', 'glaciers_customize_register_colour');


/* CALLBACKS
==================================================== */
// Show custom accent colour selectors callback
function glaciers_custom_accent_colours_show($control)
{
  if ($control->manager->get_setting('glaciers_custom_accent_colours')->value() == 'true') {
    return true;
  } else {
    return false;
  }
}
