<?php
/**
 * Adds the Social Icons section and its fields to the General Settings panel.
 * This section allows users to configure social media icons and their links.
 * 
 * @package Yaatra
 */

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

add_action( 'customize_register', 'yaatra_register_social_icons_options' );

if ( ! function_exists( 'yaatra_register_social_icons_options' ) ) :

    /**
     * Registers theme options for the Social Icons section in the WordPress Customizer.
     * 
     * @param WP_Customize_Manager $wp_customize The Customizer object that manages theme settings.
     * @since 1.0.0
     */
    function yaatra_register_social_icons_options( $wp_customize ) {

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

        /**
         * Add Social Icons Section
         * 
         * General Settings > Social Icons
         * 
         * @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_social_icons',
                array(
                    'priority'  => 25,
                    'panel'     => 'yaatra_panel_general',
                    'title'     => __( 'Social Icons', 'yaatra' ),
                )
            )
        );

        /**
         * Repeater field for Social Icons
         *
         * General Settings > Social Icons
         * 
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'social_media_icons', 
            array(
                'default'           => yaatra_get_customizer_default( 'social_media_icons' ),
                'sanitize_callback' => 'yaatra_sanitize_repeater'
            )
        );
        $wp_customize->add_control( new Yaatra_Control_Repeater(
            $wp_customize,  'social_media_icons',
                array(
                    'priority'        => 10,
                    'section'         => 'yaatra_section_social_icons',
                    'settings'        => 'social_media_icons',
                    'label'           => __( 'Social Icons', 'yaatra' ),
                    'yaatra_box_label_text'       => __( 'Social Icons','yaatra' ),
                    'yaatra_box_add_control_text' => __( 'Add New Icon','yaatra' ),
                    'yaatra_field_limit'          => 6
                ),
                array(
                    'cv_icons_list' => array(
                        'type'          => 'social_icon',   
                        'label'         => __( 'Social Icon', 'yaatra' ),
                        'description'   => __( 'Choose social media icon.', 'yaatra' )
                    ),
                    'cv_url_field'  => array(
                        'type'          => 'url',
                        'label'         => __( 'Social Link URL', 'yaatra' ),
                        'description'   => __( 'Enter social media url.', 'yaatra' )
                    ),
                    'item_visible'   => array(
                        'type'  => 'hidden'
                    )
                )
            )
        );

        /**
         * Upgrade field for social icon section
         * 
         * General Settings > Social Icons
         *
         * @since 1.2.0
         */ 
        $wp_customize->add_setting( 'upgrade_social_icons',
            array(
                'sanitize_callback' => 'sanitize_text_field'
            )
        );
        $wp_customize->add_control( new Yaatra_Control_Upgrade(
            $wp_customize, 'upgrade_social_icons',
                array(
                    'priority'      => 70,
                    'section'       => 'yaatra_section_social_icons',
                    'settings'      => 'upgrade_social_icons',
                    'label'         => __( 'More features with Yaatra Pro', 'yaatra' ),
                    'choices'       => yaatra_upgrade_choices( 'yaatra_social_icon' )
                )
            )
        );

    }

endif;