<?php
/**
 * Adds the Banner section and its fields to the Frontpage Settings panel.
 * 
 * Provides options for configuring banner settings on the front page.
 *
 * @package Yaatra
 */

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

add_action( 'customize_register', 'yaatra_register_frontpage_banner_options' );

if ( ! function_exists( 'yaatra_register_frontpage_banner_options' ) ) :

    /**
	 * Registers theme options for the Banner section in the Customizer.
	 * 
	 * Adds and configures settings related to the banner within the WordPress Customizer.
	 *
	 * @param WP_Customize_Manager $wp_customize The Customizer object for managing theme options.
	 * @since 1.0.0
	 */
    function yaatra_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 Yaatra_Customize_Section (
            $wp_customize, 'yaatra_section_frontpage_banner',
                array(
                    'priority'  => 5,
                    'panel'     => 'yaatra_panel_frontpage',
                    'title'     => __( 'Banner Settings', 'yaatra' ),
                )
            )
        );

        /**
         * Toggle option for banner.
         *
         * Frontpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_front_banner_option',
            array(
                'default'           => yaatra_get_customizer_default( 'yaatra_front_banner_option' ),
                'sanitize_callback' => 'yaatra_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Yaatra_Control_Toggle(
            $wp_customize, 'yaatra_front_banner_option',
                array(
                    'priority'      => 15,
                    'section'       => 'yaatra_section_frontpage_banner',
                    'settings'      => 'yaatra_front_banner_option',
                    'label'         => __( 'Enable Banner', 'yaatra' )
                )
            )
        );

        /**
         * Image field for background image in banner section
         *
         * Frongpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_front_banner_image',
            array(
                'default'           => yaatra_get_customizer_default( 'yaatra_front_banner_image' ),
                'sanitize_callback' => 'esc_url_raw'
            )
        );
        $wp_customize->add_control( new WP_Customize_Image_Control(
            $wp_customize, 'yaatra_front_banner_image',
                array(
                    'priority'          => 20,
                    'section'           => 'yaatra_section_frontpage_banner',
                    'settings'          => 'yaatra_front_banner_image',
                    'label'             => __( 'Upload Banner Image', 'yaatra' ),
                    'type'              => 'upload',
                    'active_callback'   => 'yaatra_front_banner_option_active_callback'
                )
            )
        );

        /**
         * Text field for banner title
         * 
         * Frongpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_banner_title',
            array(
                'default'           => yaatra_get_customizer_default( 'yaatra_banner_title' ),
                'sanitize_callback' => 'sanitize_text_field',
            )
        );
        $wp_customize->add_control( 'yaatra_banner_title',
            array(
                'priority'          => 25,
                'section'           => 'yaatra_section_frontpage_banner',
                'settings'          => 'yaatra_banner_title',
                'label'             => __( 'Banner Title', 'yaatra' ),
                'type'              => 'text',
                'active_callback'   => 'yaatra_front_banner_option_active_callback'
            )
        );

        /**
         * Textarea field for banner content
         * 
         * Frongpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_banner_content',
            array(
                'default'           => yaatra_get_customizer_default( 'yaatra_banner_content' ),
                'sanitize_callback' => 'wp_kses_post',
            )
        );
        $wp_customize->add_control( 'yaatra_banner_content',
            array(
                'priority'          => 30,
                'section'           => 'yaatra_section_frontpage_banner',
                'settings'          => 'yaatra_banner_content',
                'label'             => __( 'Banner Content', 'yaatra' ),
                'description'       => __( 'Enter the text or content that will appear on the banner. This could include a message, description, or any other relevant information.', 'yaatra' ),
                'type'              => 'textarea',
                'active_callback'   => 'yaatra_front_banner_option_active_callback'
            )
        );

        /**
         * Text field for banner button text
         * 
         * Frongpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_banner_btn_text',
            array(
                'default'           => yaatra_get_customizer_default( 'yaatra_banner_btn_text' ),
                'sanitize_callback' => 'sanitize_text_field',
            )
        );
        $wp_customize->add_control( 'yaatra_banner_btn_text',
            array(
                'priority'          => 35,
                'section'           => 'yaatra_section_frontpage_banner',
                'settings'          => 'yaatra_banner_btn_text',
                'label'             => __( 'Banner Button Label', 'yaatra' ),
                'type'              => 'text',
                'active_callback'   => 'yaatra_front_banner_option_active_callback'
            )
        );

        /**
         * Text field for banner button text
         * 
         * Frongpage Settings > Banner
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_banner_btn_link',
            array(
                'default'           => yaatra_get_customizer_default( 'yaatra_banner_btn_link' ),
                'sanitize_callback' => 'esc_url_raw',
            )
        );
        $wp_customize->add_control( 'yaatra_banner_btn_link',
            array(
                'priority'          => 40,
                'section'           => 'yaatra_section_frontpage_banner',
                'settings'          => 'yaatra_banner_btn_link',
                'label'             => __( 'Banner Button Link', 'yaatra' ),
                'type'              => 'text',
                'active_callback'   => 'yaatra_front_banner_option_active_callback'
            )
        );

        /**
         * Upgrade field for banner section
         * 
         * Frongpage Settings > Banner
         *
         * @since 1.0.0
         */ 
        $wp_customize->add_setting( 'upgrade_frontpage_banner',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Yaatra_Control_Upgrade(
            $wp_customize, 'upgrade_frontpage_banner',
                array(
                    'priority'      => 70,
                    'section'       => 'yaatra_section_frontpage_banner',
                    'settings'      => 'upgrade_frontpage_banner',
                    'label'         => __( 'More features with Yaatra Pro', 'yaatra' ),
                    'choices'       => yaatra_upgrade_choices( 'yaatra_frontpage_banner' )
                )
            )
        );

    }

endif;