<?php
/**
 * Archive Page and its fields within the Innerpage Settings panel.
 * 
 * Provides options for configuring the appearance and behavior of archive pages.
 *
 * @package Yaatra
 */


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

add_action( 'customize_register', 'yaatra_register_archive_options' );

if ( ! function_exists( 'yaatra_register_archive_options' ) ) :

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

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

        /**
         * Archive Section
         * 
         * Innerpage Settings > Archive Pages
         * 
         * @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_page_archive',
                array(
                    'priority'  => 5,
                    'panel'     => 'yaatra_panel_innerpage',
                    'title'     => __( 'Archive Pages', 'yaatra' ),
                )
            )
        );

        /**
         * Radio image field for archive layout
         * 
         * Innerpage Settings > Archive Pages
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'yaatra_archive_layout',
            array(
                'default'           => yaatra_get_customizer_default( 'yaatra_archive_layout' ),
                'sanitize_callback' => 'yaatra_sanitize_select',
            )
        );
        $wp_customize->add_control( new Yaatra_Control_Radio_Image(
            $wp_customize, 'yaatra_archive_layout',
                array(
                    'priority'      => 15,
                    'section'       => 'yaatra_section_page_archive',
                    'settings'      => 'yaatra_archive_layout',
                    'label'         => __( 'Archive Layouts', 'yaatra' ),
                    'description'   => __( 'Choose layout from available layouts', 'yaatra' ),
                    'choices'       => yaatra_archive_pages_layout_choices()
                )
            )
        );

        /**
         * Upgrade field for archive pages section
         * 
         * General Settings > Archive Pages
         *
         * @since 1.2.0
         */ 
        $wp_customize->add_setting( 'upgrade_archive',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Yaatra_Control_Upgrade(
            $wp_customize, 'upgrade_archive',
                array(
                    'priority'      => 70,
                    'section'       => 'yaatra_section_page_archive',
                    'settings'      => 'upgrade_archive',
                    'label'         => __( 'More features with Yaatra Pro', 'yaatra' ),
                    'choices'       => yaatra_upgrade_choices( 'yaatra_archive' )
                )
            )
        );

    }

endif;