<?php
/**
 * Add Top Header Area section and it's fields inside Header Settings Panel.
 * 
 * @package purenote
 */

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

add_action( 'customize_register', 'purenote_register_top_area_options' );

if ( ! function_exists( 'purenote_register_top_area_options' ) ) :

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

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

        /**
         * Add Top Header Area Section
         *
         * Header Settings > Top Header
         */
        $wp_customize->add_section( new purenote_Customize_Section (
            $wp_customize, 'purenote_section_header_area',
                array(
                    'priority' => 5,
                    'panel'    => 'purenote_panel_header',
                    'title'    => __( 'Top Header', 'purenote' ),
                )
            )
        );

        /**
         * Tabs field for Top Header section
         *
         * Header Settings > Top Header
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_header_area_tabs',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_header_area_tabs' ),
                'sanitize_callback' => 'sanitize_text_field',
            )
        );
        $wp_customize->add_control( new purenote_Control_Tabs (
            $wp_customize, 'purenote_header_area_tabs',
                array(
                    'priority' => 5,
                    'section'  => 'purenote_section_header_area',
                    'settings' => 'purenote_header_area_tabs',
                    'choices'  => purenote_header_area_tabs_choices(),
                    'required' => array(
                        array(
                            'control'  => 'purenote_header_top_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    ),
                )
            )
        );

        /**
         * Toggle option for enable the top header area.
         *
         * Header Settings > Top Header
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_header_top_enable',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_header_top_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox',
            )
        );
        $wp_customize->add_control( new purenote_Control_Toggle (
            $wp_customize, 'purenote_header_top_enable',
                array(
                    'priority' => 10,
                    'section'  => 'purenote_section_header_area',
                    'settings' => 'purenote_header_top_enable',
                    'label'    => __( 'Enable Top Header', 'purenote' ),
                )
            )
        );

        /**
         * Toggle option for enable date and time in the top header area.
         *
         * Header Settings > Top Header
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_header_date_enable',
            array(
                'default'           => purenote_get_customizer_default('purenote_header_date_enable'),
                'sanitize_callback' => 'purenote_sanitize_checkbox',
            )
        );
        $wp_customize->add_control( new purenote_Control_Toggle (
            $wp_customize, 'purenote_header_date_enable',
                array(
                    'priority' => 15,
                    'section'  => 'purenote_section_header_area',
                    'settings' => 'purenote_header_date_enable',
                    'label'    => __( 'Enable Date - Time', 'purenote' ),
                    'required' => array(
                        array(
                            'control'  => 'purenote_header_top_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    ),
                )
            )
        );

        /**
         * Select option for date format.
         *
         * Header Settings > Top Header
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_header_date_format',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_header_date_format' ),
                'sanitize_callback' => 'purenote_sanitize_select',
            )
        );
        $wp_customize->add_control( new purenote_Customize_Control(
            $wp_customize, 'purenote_header_date_format',
                array(
                    'priority' => 20,
                    'section'  => 'purenote_section_header_area',
                    'settings' => 'purenote_header_date_format',
                    'label'    => __( 'Date Format', 'purenote' ),
                    'type'     => 'select',
                    'choices'  => purenote_header_date_format_choices(),
                    'required' => array(
                        array(
                            'control'  => 'purenote_header_top_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );

        /**
         * Toggle option for header social icon.
         *
         * Header Settings > Top Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_header_social_icons_enable',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_header_social_icons_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_header_social_icons_enable',
                array(
                    'priority'      => 30,
                    'section'       => 'purenote_section_header_area',
                    'settings'      => 'purenote_header_social_icons_enable',
                    'label'         => __( 'Enable Social Icons', 'purenote' ),
                    'required' => array(
                        array(
                            'control'  => 'purenote_header_top_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );

        /**
         * Color Picker field for Top Header background color
         * 
         * Header Settings > Top Header
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_header_bg_color',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_header_bg_color' ),
                'sanitize_callback' => 'sanitize_hex_color',
            )
        );
        $wp_customize->add_control( new WP_Customize_Color_Control(
            $wp_customize, 'purenote_header_bg_color',
                array(
                    'priority' => 100,
                    'section'  => 'purenote_section_header_area',
                    'settings' => 'purenote_header_bg_color',
                    'label'    => __( 'Background Color', 'purenote' )
                )
            )
        );

        /**
         * Color Picker field for Top Header text color
         * 
         * Header Settings > Top Header
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_top_header_text_color',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_top_header_text_color' ),
                'sanitize_callback' => 'sanitize_hex_color',
            )
        );
        $wp_customize->add_control( new WP_Customize_Color_Control (
            $wp_customize, 'purenote_top_header_text_color',
                array(
                    'label'    => __( 'Text Color', 'purenote' ),
                    'section'  => 'purenote_section_header_area',
                    'settings' => 'purenote_top_header_text_color'
                )
            )
        );
    }

endif;