<?php
/**
 * Add Main Area section and it's fields inside Header Settings panel.
 * 
 * @package Ogma News
 */

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

add_action( 'customize_register', 'ogma_news_register_main_area_options' );

if ( ! function_exists( 'ogma_news_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 ogma_news_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 ogma_news_Customize_Section (
            $wp_customize, 'ogma_news_section_header_main_area',
                array(
                    'priority'  => 20,
                    'panel'     => 'ogma_news_panel_header',
                    'title'     => __( 'Main Area', 'ogma-news' ),
                )
            )
        );

        /**
         * Tabs field for Main Area section
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_main_area_tabs',
            array(
                'default'           => ogma_news_get_customizer_default( 'ogma_news_header_main_area_tabs' ),
                'sanitize_callback' => 'sanitize_text_field',
            )
        );
        $wp_customize->add_control( new Ogma_News_Control_Tabs(
            $wp_customize, 'ogma_news_header_main_area_tabs',
                array(
                    'priority'      => 5,
                    'section'       => 'ogma_news_section_header_main_area',
                    'settings'      => 'ogma_news_header_main_area_tabs',
                    'choices'       => ogma_news_header_main_area_tabs_choices()
                )
            )
        );

        /**
         * Toggle option for primary menu sticky.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_sticky_enable',
            array(
                'default'           => ogma_news_get_customizer_default( 'ogma_news_header_sticky_enable' ),
                'sanitize_callback' => 'ogma_news_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Ogma_News_Control_Toggle(
            $wp_customize, 'ogma_news_header_sticky_enable',
                array(
                    'priority'      => 10,
                    'section'       => 'ogma_news_section_header_main_area',
                    'settings'      => 'ogma_news_header_sticky_enable',
                    'label'         => __( 'Enable Header Sticky', 'ogma-news' )
                )
            )
        );

        /**
         * Toggle option for header site mode switcher.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_site_mode_switch_enable',
            array(
                'default'           => ogma_news_get_customizer_default( 'ogma_news_header_site_mode_switch_enable' ),
                'sanitize_callback' => 'ogma_news_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Ogma_News_Control_Toggle(
            $wp_customize, 'ogma_news_header_site_mode_switch_enable',
                array(
                    'priority'      => 15,
                    'section'       => 'ogma_news_section_header_main_area',
                    'settings'      => 'ogma_news_header_site_mode_switch_enable',
                    'label'         => __( 'Enable site mode switcher', 'ogma-news' )
                )
            )
        );

        /**
         * Toggle option for header search icon.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_search_enable',
            array(
                'default'           => ogma_news_get_customizer_default( 'ogma_news_header_search_enable' ),
                'sanitize_callback' => 'ogma_news_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Ogma_News_Control_Toggle(
            $wp_customize, 'ogma_news_header_search_enable',
                array(
                    'priority'      => 20,
                    'section'       => 'ogma_news_section_header_main_area',
                    'settings'      => 'ogma_news_header_search_enable',
                    'label'         => __( 'Enable Search Icon', 'ogma-news' )
                )
            )
        );

        /**
         * Toggle option for header sticky sidebar toggle.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_sticky_sidebar_toggle_enable',
            array(
                'default'           => ogma_news_get_customizer_default( 'ogma_news_header_sticky_sidebar_toggle_enable' ),
                'sanitize_callback' => 'ogma_news_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Ogma_News_Control_Toggle(
            $wp_customize, 'ogma_news_header_sticky_sidebar_toggle_enable',
                array(
                    'priority'      => 25,
                    'section'       => 'ogma_news_section_header_main_area',
                    'settings'      => 'ogma_news_header_sticky_sidebar_toggle_enable',
                    'label'         => __( 'Enable sticky sidebar toggle', 'ogma-news' )
                )
            )
        );

        /**
         * Redirect field for sticky sidebar widget area.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_sticky_sidebar_redirect',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Ogma_News_Control_Redirect(
            $wp_customize, 'ogma_news_header_sticky_sidebar_redirect',
                array(
                    'priority'      => 25,
                    'section'       => 'ogma_news_section_header_main_area',
                    'settings'      => 'ogma_news_header_sticky_sidebar_redirect',
                    'choices'       => array(
                        'ogma_news_header_sticky_sidebar_redirect' => array(
                            'type'          => 'section',
                            'type_id'       => 'sidebar-widgets-header-sticky-sidebar',
                            'type_label'    => __( 'Manage sidebar from here', 'ogma-news' )
                        )
                    ),
                    'active_callback'   => 'ogma_news_cb_has_sticky_sidebar_toggle_enable'
                )
            )
        );

        /**
         * Heading field for custom button
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_custom_button_heading',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Ogma_News_Control_Heading(
            $wp_customize, 'ogma_news_header_custom_button_heading',
                array(
                    'priority'          => 30,
                    'section'           => 'ogma_news_section_header_main_area',
                    'settings'          => 'ogma_news_header_custom_button_heading',
                    'label'             => __( 'Custom Button', 'ogma-news' )
                )
            )
        );

        /**
         * Text field for custom button label
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_custom_button_label',
            array(
                'default'           => ogma_news_get_customizer_default( 'ogma_news_header_custom_button_label' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( 'ogma_news_header_custom_button_label',
            array(
                'priority'          => 30,
                'section'           => 'ogma_news_section_header_main_area',
                'settings'          => 'ogma_news_header_custom_button_label',
                'label'             => __( 'Custom Button Label', 'ogma-news' ),
                'type'              => 'text',
            )
        );

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


        /**
         * Radio image field for header main area layout.
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_main_area_layout',
            array(
                'default'           => ogma_news_get_customizer_default( 'ogma_news_header_main_area_layout' ),
                'sanitize_callback' => 'ogma_news_sanitize_select',
            )
        );
        $wp_customize->add_control( new Ogma_News_Control_Radio_Image(
            $wp_customize, 'ogma_news_header_main_area_layout',
                array(
                    'priority'      => 55,
                    'section'       => 'ogma_news_section_header_main_area',
                    'settings'      => 'ogma_news_header_main_area_layout',
                    'label'         => __( 'Main Area Layout', 'ogma-news' ),
                    'choices'       => ogma_news_header_main_area_layout_choices(),
                )
            )
        );

        /**
         * Select option for header main background type
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_main_bg_type',
            array(
                'default'           => ogma_news_get_customizer_default( 'ogma_news_header_main_bg_type' ),
                'sanitize_callback' => 'ogma_news_sanitize_select'
            )
        );
        $wp_customize->add_control( 'ogma_news_header_main_bg_type',
            array(
                'priority'          => 60,
                'section'           => 'ogma_news_section_header_main_area',
                'settings'          => 'ogma_news_header_main_bg_type',
                'label'             => __( 'Background Type', 'ogma-news' ),
                'type'              => 'select',
                'choices'           => ogma_news_bg_type_choices()
            )
        );

        /**
         * Color Picker field for Main Area background color
         * 
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_main_bg_color',
            array(
                'default'           => ogma_news_get_customizer_default( 'ogma_news_header_main_bg_color' ),
                'sanitize_callback' => 'sanitize_hex_color',
            )
        );
        $wp_customize->add_control( new WP_Customize_Color_Control(
            $wp_customize, 'ogma_news_header_main_bg_color',
                array(
                    'priority'          => 65,
                    'section'           => 'ogma_news_section_header_main_area',
                    'settings'          => 'ogma_news_header_main_bg_color',
                    'label'             => __( 'Background Color', 'ogma-news' ),
                    'active_callback'   => 'ogma_news_cb_has_bg_type_color',
                )
            )
        );

        /**
         * Cropped Image field for header main area background image
         *
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'ogma_news_header_main_bg_image',
            array(
                'default'           => ogma_news_get_customizer_default( 'ogma_news_header_main_bg_image' ),
                'sanitize_callback' => 'absint'
            )
        );
        $wp_customize->add_control( new WP_Customize_Cropped_Image_Control(
            $wp_customize, 'ogma_news_header_main_bg_image',
                array(
                    'priority'          => 70,
                    'section'           => 'ogma_news_section_header_main_area',
                    'settings'          => 'ogma_news_header_main_bg_image',
                    'label'             => __( 'Background Image', 'ogma-news' ),
                    'height'            => 270,
                    'width'             => 1320,
                    'flex_width'        =>true,
                    'active_callback'   => 'ogma_news_cb_has_bg_type_image'
                )
            )
        );

        /**
         * Upgrade field for Header Main
         * 
         * Header Settings > Main Area
         *
         * @since 1.0.0
         */ 
        $wp_customize->add_setting( 'upgrade_header_main',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Ogma_News_Control_Upgrade(
            $wp_customize, 'upgrade_header_main',
                array(
                    'priority'      => 100,
                    'section'       => 'ogma_news_section_header_main_area',
                    'settings'      => 'upgrade_header_main',
                    'label'         => __( 'More Features with Ogma Pro', 'ogma-news' ),
                    'choices'       => ogma_news_upgrade_choices( 'ogma_news_header_main' )
                )
            )
        );

    }

endif;