<?php
/**
 * Adds the Main Area section and its fields to the Header Settings panel.
 * 
 * @package Purenote
 */

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

add_action( 'customize_register', 'purenote_register_main_area_options' );

if ( ! function_exists( 'purenote_register_main_area_options' ) ) :

    /**
     * Register theme options for Main Area section.
     * 
     * @param WP_Customize_Manager $wp_customize Object that holds the customizer data.
     * @since 1.0.0
     */
    function purenote_register_main_area_options( $wp_customize ) {

        /*
         * Failsafe is safe
         */
        if ( ! isset( $wp_customize ) ) {
            return;
        }

        /**
         * Add Main Area Section
         * 
         * Header Settings > Main Area
         * 
         * @uses $wp_customize->add_section() https://developer.wordpress.org/reference/classes/wp_customize_manager/add_section/
         * @since 1.0.0
         */
        $wp_customize->add_section( new Purenote_Customize_Section (
            $wp_customize, 'purenote_section_header_main_area',
                array(
                    'priority'  => 20,
                    'panel'     => 'purenote_panel_header',
                    'title'     => __( 'Main Area', 'purenote' ),
                )
            )
        );

        /**
         * Toggle option for header site mode switcher.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_site_mode_switcher_option',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_site_mode_switcher_option' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_site_mode_switcher_option',
                array(
                    'priority'      => 5,
                    'section'       => 'purenote_section_header_main_area',
                    'settings'      => 'purenote_site_mode_switcher_option',
                    'label'         => __( 'Enable site mode switcher', 'purenote' )
                )
            )
        );
        
        /**
         * Toggle option for header search icon.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_header_search_enable',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_header_search_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_header_search_enable',
                array(
                    'priority'      => 15,
                    'section'       => 'purenote_section_header_main_area',
                    'settings'      => 'purenote_header_search_enable',
                    'label'         => __( 'Enable Search Icon', 'purenote' )
                )
            )
        );

        /**
         * Toggle option for header sticky.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_header_sticky_enable',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_header_sticky_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_header_sticky_enable',
                array(
                    'priority'      => 20,
                    'section'       => 'purenote_section_header_main_area',
                    'settings'      => 'purenote_header_sticky_enable',
                    'label'         => __( 'Enable Header Sticky', 'purenote' )
                )
            )
        );

        /**
         * Heading field for custom button
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_header_custom_button_heading',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new purenote_Control_Heading(
            $wp_customize, 'purenote_header_custom_button_heading',
                array(
                    'priority'          => 25,
                    'section'           => 'purenote_section_header_main_area',
                    'settings'          => 'purenote_header_custom_button_heading',
                    'label'             => __( 'Custom Button', 'purenote' )
                )
            )
        );

        /**
         * Text field for custom button label
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_header_custom_button_label',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_header_custom_button_label' ),
                'transport'         => 'refresh',
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( 'purenote_header_custom_button_label',
            array(
                'priority'          => 30,
                'section'           => 'purenote_section_header_main_area',
                'settings'          => 'purenote_header_custom_button_label',
                'label'             => __( 'Custom Button Label', 'purenote' ),
                'type'              => 'text',
            )
        );

        /**
         * Url field for custom button link
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_header_custom_button_link',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_header_custom_button_link' ),
                'sanitize_callback' => 'esc_url_raw'
            )
        );
        $wp_customize->add_control( 'purenote_header_custom_button_link',
            array(
                'priority'          => 35,
                'section'           => 'purenote_section_header_main_area',
                'settings'          => 'purenote_header_custom_button_link',
                'label'             => __( 'Custom Button Link', 'purenote' ),
                'type'              => 'url',
            )
        );

         /**
         * Toggle option for primary menu description
         *
         * Header Settings > Primary Menu
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_primary_menu_description_enable',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_primary_menu_description_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new purenote_Control_Toggle(
            $wp_customize, 'purenote_primary_menu_description_enable',
                array(
                    'priority'      => 45,
                    'section'       => 'purenote_section_header_main_area',
                    'settings'      => 'purenote_primary_menu_description_enable',
                    'label'         => __( 'Enable Menu Description', 'purenote' )
                )
            )
        );

    }

endif;