<?php
/**
 * Add news ticker inside header panel.
 * 
 * @package Purenote
 */

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

add_action( 'customize_register', 'purenote_register_ticker_options' );

if ( ! function_exists( 'purenote_register_ticker_options' ) ):

    /**
     * Register a theme options for News Ticker.
     * 
      * @param WP_Customize_Manager $wp_customize Object that holds the customizer data.
     * @since 1.0.0
     */
    function purenote_register_ticker_options( $wp_customize ) {

        /**
         * Failsafe is safe
         */
        if ( !isset( $wp_customize ) ) {
            return;
        }
         
        /**
         * Add News Ticker Section
         * 
         * Header Settings > News Ticker
         * 
         * @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_ticker',
                array(
                    'priority'  => 15, 
                    'panel'     =>  'purenote_panel_header',
                    'title'     => __( 'News Ticker', 'purenote' ),
                )
            )
        );

        /**
          * Toggle option for news ticker.
          * 
          * Header Settings > News Ticker
          * 
          * @since 1.0.0
          */
        $wp_customize-> add_setting( 'purenote_header_ticker_enable',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_header_ticker_enable' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle (
            $wp_customize, 'purenote_header_ticker_enable',
                array(
                    'priority'  => 15,
                    'section'   => 'purenote_section_header_ticker',
                    'settings'  => 'purenote_header_ticker_enable',
                    'label'     => __( 'Enable News Ticker', 'purenote' )
                )
            )
        );

        /**
          * Text field for news ticker label
          * 
          * Header Settings > News Ticker
          * 
          * @since 1.0.0
          */
        $wp_customize-> add_setting( 'purenote_header_ticker_label',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_header_ticker_label' ),
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize-> add_control( new Purenote_Customize_Control (
            $wp_customize, 'purenote_header_ticker_label',
                array(
                    'priority'  => 20,
                    'section'   => 'purenote_section_header_ticker',
                    'settings'  => 'purenote_header_ticker_label',
                    'label'     => __( 'Ticker Label', 'purenote' ),
                    'type'      => 'text',
                    // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_header_ticker_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );

        /**
          * Select option for ticker posts date filter
          * 
          * Header Settings > News Ticker
          * 
          * @since 1.0.0
          */
         $wp_customize-> add_setting( 'purenote_ticker_posts_date_filter',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_ticker_posts_date_filter' ),
                'sanitize_callback' => 'purenote_sanitize_select'
            )
        );
        $wp_customize-> add_control( new Purenote_Customize_Control (
            $wp_customize, 'purenote_ticker_posts_date_filter',
                array(
                    'priority'  => 35,
                    'section'   => 'purenote_section_header_ticker',
                    'settings'  => 'purenote_ticker_posts_date_filter',
                    'label'     => __( 'Posts Date Filter', 'purenote' ),
                    'type'      => 'select',
                    'choices'   => purenote_posts_date_filter_choices(),
                    // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'purenote_header_ticker_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    )
                )
            )
        );
    }

endif;