<?php 

/**
 * Customizer settings
 *
 * @package specter
 */

if ( ! function_exists( 'specter_theme_customizer' ) ) :
  function specter_theme_customizer( $wp_customize ) {

    /* Homepage Sections */
    $wp_customize->add_section( 'specter_homepage' , array(
      'title'       => __( 'Homepage Sections', 'specter' ),
      'priority'    => 30,
      'description' => __( 'Select a page to be assigned for each section', 'specter' ),
    ) );


    $wp_customize->add_setting( 'specter_section_1', array (
      'sanitize_callback' => 'specter_sanitize_dropdown_pages',
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'specter_section_1', array(
      'label'    => __( 'Section 1', 'specter' ),
      'section'  => 'specter_homepage',
      'settings' => 'specter_section_1',
      'type'     => 'dropdown-pages'
    ) ) );

    $wp_customize->add_setting( 'specter_section_2', array (
      'sanitize_callback' => 'specter_sanitize_dropdown_pages',
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'specter_section_2', array(
      'label'    => __( 'Section 2', 'specter' ),
      'section'  => 'specter_homepage',
      'settings' => 'specter_section_2',
      'type'     => 'dropdown-pages'
    ) ) );

    $wp_customize->add_setting( 'specter_section_3', array (
      'sanitize_callback' => 'specter_sanitize_dropdown_pages',
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'specter_section_3', array(
      'label'    => __( 'Section 3', 'specter' ),
      'section'  => 'specter_homepage',
      'settings' => 'specter_section_3',
      'type'     => 'dropdown-pages'
    ) ) );

    $wp_customize->add_setting( 'specter_section_4', array (
      'sanitize_callback' => 'specter_sanitize_dropdown_pages',
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'specter_section_4', array(
      'label'    => __( 'Section 4', 'specter' ),
      'section'  => 'specter_homepage',
      'settings' => 'specter_section_4',
      'type'     => 'dropdown-pages'
    ) ) );

    $wp_customize->add_setting( 'specter_section_5', array (
      'sanitize_callback' => 'specter_sanitize_dropdown_pages',
    ) );

    $wp_customize->add_control( new WP_Customize_Control( $wp_customize, 'specter_section_5', array(
      'label'    => __( 'Section 5', 'specter' ),
      'section'  => 'specter_homepage',
      'settings' => 'specter_section_5',
      'type'     => 'dropdown-pages'
    ) ) );
    
    /* color scheme option */
    $wp_customize->add_setting( 'specter_color_settings', array (
      'default' => '#282e3f',
      'sanitize_callback' => 'sanitize_hex_color',
    ) );
    
    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'specter_color_settings', array(
      'label'    => __( 'Primary Color Scheme', 'specter' ),
      'section'  => 'colors',
      'settings' => 'specter_color_settings',
    ) ) );

    $wp_customize->add_setting( 'specter_color_settings_2', array (
      'default' => '#e0a85d',
      'sanitize_callback' => 'sanitize_hex_color',
    ) );
    
    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'specter_color_settings_2', array(
      'label'    => __( 'Secondary Color Scheme', 'specter' ),
      'section'  => 'colors',
      'settings' => 'specter_color_settings_2',
    ) ) );
  
  }
endif;
add_action('customize_register', 'specter_theme_customizer');


/**
 * Sanitize checkbox
 */
if ( ! function_exists( 'specter_sanitize_checkbox' ) ) :
  function specter_sanitize_checkbox( $input ) {
    if ( $input == 1 ) {
      return 1;
    } else {
      return '';
    }
  }
endif;

/**
 * Sanitize text field html
 */
if ( ! function_exists( 'specter_sanitize_field_html' ) ) :
  function specter_sanitize_field_html( $str ) {
    $allowed_html = array(
    'a' => array(
    'href' => array(),
    ),
    'br' => array(),
    'span' => array(),
    );
    $str = wp_kses( $str, $allowed_html );
    return $str;
  }
endif;

if ( ! function_exists( 'specter_sanitize_dropdown_pages' ) ) :
  function specter_sanitize_dropdown_pages( $page_id, $setting ) {
    // Ensure $input is an absolute integer.
    $page_id = absint( $page_id );

    // If $page_id is an ID of a published page, return it; otherwise, return the default.
    return ( 'publish' == get_post_status( $page_id ) ? $page_id : $setting->default );
  }
endif;