<?php
/**
 * Add Banner section and it's fields inside Frontpage Settings panel.
 * 
 * @package Purenote
 */

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

add_action( 'customize_register', 'purenote_register_frontpage_banner_options' );

if ( ! function_exists( 'purenote_register_frontpage_banner_options' ) ) :

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

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

        /**
         * Add Banner Section
         * 
         * Frontpage Settings > Banner
         * 
         * @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_frontpage_banner',
                array(
                    'priority'  => 5,
                    'panel'     => 'purenote_panel_front_page',
                    'title'     => __( 'Main Banner', 'purenote' ),
                )
            )
        );


        /**
         * Tabs field for Banner section
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_frontpage_banner_tabs',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_frontpage_banner_tabs' ),
                'sanitize_callback' => 'sanitize_text_field',
            )
        );
        $wp_customize->add_control( new Purenote_Control_Tabs(
            $wp_customize, 'purenote_frontpage_banner_tabs',
                array(
                    'priority'      => 10,
                    'section'       => 'purenote_section_frontpage_banner',
                    'settings'      => 'purenote_frontpage_banner_tabs',
                    'choices'       => purenote_frontpage_banner_tabs_choices()
                )
            )
        );
             
        /**
         * Heading field for banner slider settings
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_banner_slider_heading',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Heading(
            $wp_customize, 'purenote_banner_slider_heading',
                array(
                    'priority'          => 20,
                    'section'           => 'purenote_section_frontpage_banner',
                    'settings'          => 'purenote_banner_slider_heading',
                    'label'             => __( 'Slider Settings', 'purenote' ),
                    // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_banner_slider_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );

        /**
          * Toggle option for banner
          * 
          * Frontpage Settings > banner Slider
          * 
          * @since 1.0.0
          */
        $wp_customize-> add_setting( 'purenote_banner_slider_enable',
            array(
                'default'   => purenote_get_customizer_default( 'purenote_banner_slider_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_banner_slider_enable',
                array(
                    'priority'  => 25,
                    'section'   => 'purenote_section_frontpage_banner',
                    'settings'  => 'purenote_banner_slider_enable',
                    'label' => __( 'Enable Banner Slider', 'purenote' )
                )
            )
        );

        /**
         * Select option of category for slider posts
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_banner_slider_category',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_banner_slider_category' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Dropdown_Categories(
            $wp_customize, 'purenote_banner_slider_category',
                array(
                    'priority'          => 30,
                    'section'           => 'purenote_section_frontpage_banner',
                    'settings'          => 'purenote_banner_slider_category',
                    'label'             => __( 'Slider Category', 'purenote' ),
                    // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_banner_slider_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );

        /**
         * Select option for slider posts order by
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_banner_slider_order_by',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_banner_slider_order_by' ),
                'sanitize_callback' => 'purenote_sanitize_select'
            )
        );
        $wp_customize->add_control( new Purenote_Customize_Control (
            $wp_customize, 'purenote_banner_slider_order_by',
                array(
                    'priority'          => 35,
                    'section'           => 'purenote_section_frontpage_banner',
                    'settings'          => 'purenote_banner_slider_order_by',
                    'label'             => __( 'Posts Order By', 'purenote' ),
                    'type'              => 'select',
                    'choices'           => purenote_posts_order_by_choices(),
                    // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_banner_slider_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );

        /**
         * Select option for slider posts date filter
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_banner_slider_date_filter',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_banner_slider_date_filter' ),
                'sanitize_callback' => 'purenote_sanitize_select'
            )
        );
        $wp_customize->add_control( new Purenote_Customize_Control (
            $wp_customize, 'purenote_banner_slider_date_filter',
                array(
                    'priority'          => 40,
                    'section'           => 'purenote_section_frontpage_banner',
                    'settings'          => 'purenote_banner_slider_date_filter',
                    'label'             => __( 'Posts Date Filter', 'purenote' ),
                    'type'              => 'select',
                    'choices'           => purenote_posts_date_filter_choices(),
                    // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_banner_slider_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );

        /**
         * Heading field for banner timeline settings
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_banner_timeline_heading',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Heading(
            $wp_customize, 'purenote_banner_timeline_heading',
                array(
                    'priority'          => 45,
                    'section'           => 'purenote_section_frontpage_banner',
                    'settings'          => 'purenote_banner_timeline_heading',
                    'label'             => __( 'Timeline Settings', 'purenote' ),
                     // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_banner_timeline_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );

        /**
          * Toggle option for banner
          * 
          * Frontpage Settings > banner timeline
          * 
          * @since 1.0.0
          */
        $wp_customize-> add_setting( 'purenote_banner_timeline_enable',
            array(
                'default'   => purenote_get_customizer_default( 'purenote_banner_timeline_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_banner_timeline_enable',
                array(
                    'priority'  => 50,
                    'section'   => 'purenote_section_frontpage_banner',
                    'settings'  => 'purenote_banner_timeline_enable',
                    'label' => __( 'Enable Banner timeline', 'purenote' )
                )
            )
        );

        /**
         * Text field for banner timeline
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_banner_timeline_title',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_banner_timeline_title' ),
                'sanitize_callback' => 'purenote_sanitize_title'
            )
        );
        $wp_customize->add_control( new Purenote_Customize_Control (
            $wp_customize,  'purenote_banner_timeline_title',
            array(
                'priority'          => 55,
                'section'           => 'purenote_section_frontpage_banner',
                'settings'          => 'purenote_banner_timeline_title',
                'label'             => __( 'Section Title', 'purenote' ),
                'type'              => 'text',
                // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_banner_timeline_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );

        /**
         * Select option of categories for timeline posts
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_banner_timeline_categories',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_banner_timeline_categories' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Dropdown_Categories(
            $wp_customize, 'purenote_banner_timeline_categories',
                array(
                    'priority'          => 60,
                    'section'           => 'purenote_section_frontpage_banner',
                    'settings'          => 'purenote_banner_timeline_categories',
                    'label'             => __( 'Timeline Category', 'purenote' ),
                     // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_banner_timeline_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );

        /**
         * Select option for timeline posts order by
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_banner_timeline_order_by',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_banner_timeline_order_by' ),
                'sanitize_callback' => 'purenote_sanitize_select'
            )
        );
        $wp_customize->add_control( new Purenote_Customize_Control (
            $wp_customize, 'purenote_banner_timeline_order_by',
            array(
                'priority'          => 65,
                'section'           => 'purenote_section_frontpage_banner',
                'settings'          => 'purenote_banner_timeline_order_by',
                'label'             => __( 'Posts Order By', 'purenote' ),
                'type'              => 'select',
                'choices'           => purenote_posts_order_by_choices(),
                // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_banner_timeline_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );
       
        /**
         * Select option for banner background option
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_banner_bg_type',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_banner_bg_type' ),
                'sanitize_callback' => 'purenote_sanitize_select'
            )
        );
        $wp_customize->add_control( 'purenote_banner_bg_type',
            array(
                'priority'          => 95,
                'section'           => 'purenote_section_frontpage_banner',
                'settings'          => 'purenote_banner_bg_type',
                'label'             => __( 'Banner Background Type', 'purenote' ),
                'type'              => 'select',
                'choices'           => purenote_bg_type_choices()
            )
        );
        
        /**
         * Color Picker field for Footer Main Area background color
         * 
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_banner_bg_color',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_banner_bg_color' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_hex_color',
            )
        );
        $wp_customize->add_control( new Purenote_Customize_Color_Control(
            $wp_customize, 'purenote_banner_bg_color',
                array(
                    'priority'          => 100,
                    'section'           => 'purenote_section_frontpage_banner',
                    'settings'          => 'purenote_banner_bg_color',
                    'label'             => __( 'Background Color', 'purenote' ),
                    // Required Dependency
                    'required'        => array(
                        array(
                            'control'  => 'purenote_banner_bg_type',
                            'value'    => 'bg-color',
                            'operator' => '==',
                        )
                    )
                )
            )
        );

        /**
         * Cropped Image field for footer main area background image
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_banner_bg_image',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_banner_bg_image' ),
                'sanitize_callback' => 'absint'
            )
        );
        $wp_customize->add_control( new Purenote_Customize_Cropped_Image_Control(
            $wp_customize, 'purenote_banner_bg_image',
                array(
                    'priority'          => 105,
                    'section'           => 'purenote_section_frontpage_banner',
                    'settings'          => 'purenote_banner_bg_image',
                    'label'             => __( 'Background Image', 'purenote' ),
                    'height'            => 270,
                    'width'             => 1320,
                    'flex_width'        =>true,
                    // Required Dependency
                    'required'        => array(
                        array(
                            'control'  => 'purenote_banner_bg_type',
                            'value'    => 'bg-image',
                            'operator' => '==',
                        )
                    )
                )
            )
        );

    }

endif;