<?php
/**
 * Add Scroll Top section and it's fields inside General Settings panel.
 * 
 * @package Blogbuster
 */

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

add_action( 'customize_register', 'blogbuster_register_scroll_top_options' );

if ( ! function_exists( 'blogbuster_register_scroll_top_options' ) ) :

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

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

        /**
         * Add Scroll Top Section
         * 
         * General Settings > Scroll Top
         * 
         * @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 Blogbuster_Customize_Section (
            $wp_customize, 'blogbuster_section_scroll_top',
                array(
                    'priority'  => 50,
                    'panel'     => 'blogbuster_panel_general',
                    'title'     => __( 'Scroll Top', 'blogbuster' ),
                )
            )
        );

        /**
         * Toggle option for scroll top.
         *
         * General Settings > Scroll Top
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_scroll_top_enable',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_scroll_top_enable' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'blogbuster_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Toggle(
            $wp_customize, 'blogbuster_scroll_top_enable',
                array(
                    'priority'      => 10,
                    'section'       => 'blogbuster_section_scroll_top',
                    'settings'      => 'blogbuster_scroll_top_enable',
                    'label'         => __( 'Enable Scroll Top', 'blogbuster' )
                )
            )
        );

        /**
         * Radio icons field for scroll top arrow
         *
         * General Settings > Scroll Top
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'blogbuster_scroll_top_arrow',
            array(
                'default'           => blogbuster_get_customizer_default( 'blogbuster_scroll_top_arrow' ),
                'transport'         => 'postMessage',
                'sanitize_callback' => 'sanitize_text_field',
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Radio_Icons(
            $wp_customize, 'blogbuster_scroll_top_arrow',
                array(
                    'priority'          => 20,
                    'section'           => 'blogbuster_section_scroll_top',
                    'settings'          => 'blogbuster_scroll_top_arrow',
                    'label'             => __( 'Arrow Icon', 'blogbuster' ),
                    'description'       => __( 'Choose required arrow from available lists.', 'blogbuster' ),
                    'choices'           => blogbuster_scroll_top_arrow_choices(),
                    // Required Dependency
                    'required'          => array(
                        array(
                            'control'  => 'blogbuster_scroll_top_enable',
                            'value'    => true,
                            'operator' => '==',
                        ),
                    ),
                )
            )
        );

        /**
         * Upgrade field for scroll top section
         * 
         * General Settings > Scroll Top
         *
         * @since 1.0.0
         */ 
        $wp_customize->add_setting( 'blogbuster_upgrade_scroll_top',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Blogbuster_Control_Upgrade(
            $wp_customize, 'blogbuster_upgrade_scroll_top',
                array(
                    'priority'      => 70,
                    'section'       => 'blogbuster_section_scroll_top',
                    'settings'      => 'blogbuster_upgrade_scroll_top',
                    'label'         => __( 'More features with Blogbuster Pro', 'blogbuster' ),
                    'choices'       => blogbuster_upgrade_choices( 'blogbuster_scroll_top' )
                )
            )
        );

    }

endif;