<?php
/**
 * Adds the Social Icons section and its fields to the General Settings panel.
 * 
 * @package PureNote
 */

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

add_action( 'customize_register', 'purenote_register_social_icons_options' );

if ( ! function_exists( 'purenote_register_social_icons_options' ) ) :

    /**
     * Register theme options for Social Icons section.
     * 
     * @param WP_Customize_Manager $wp_customize Object that holds the customizer data.
     * @since 1.0.0
     */
    function purenote_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 Purenote_Customize_Section (
            $wp_customize, 'purenote_section_social_icons',
                array(
                    'priority'  => 25,
                    'panel'     => 'purenote_panel_general',
                    'title'     => __( 'Social Icons', 'purenote' ),
                )
            )
        );

        /**
         * Toggle option for social icon target.
         *
         * General Settings > Social Icons
         *
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_social_icon_link_target',
            array(
                'default'           => purenote_get_customizer_default( 'purenote_social_icon_link_target' ),
                'sanitize_callback' => 'purenote_sanitize_checkbox'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Toggle(
            $wp_customize, 'purenote_social_icon_link_target',
                array(
                    'priority'      => 10,
                    'section'       => 'purenote_section_social_icons',
                    'settings'      => 'purenote_social_icon_link_target',
                    'label'         => __( 'Open links in new tab', 'purenote' )
                )
            )
        );

        /**
         * Repeater field for Social Icons
         *
         * General Settings > Social Icons
         * 
         * @since 1.0.0
         */
        $wp_customize->add_setting( 'purenote_social_icons', 
            array(
                'default'           => purenote_get_customizer_default( 'purenote_social_icons' ),
                'sanitize_callback' => 'purenote_sanitize_repeater'
            )
        );
        $wp_customize->add_control( new Purenote_Control_Repeater(
            $wp_customize,  'purenote_social_icons',
                array(
                    'priority'        => 20,
                    'section'         => 'purenote_section_social_icons',
                    'settings'        => 'purenote_social_icons',
                    'label'           => __( 'Social Icons', 'purenote' ),
                    'purenote_box_label_text'       => __( 'Social Icons','purenote' ),
                    'purenote_box_add_control_text' => __( 'Add New Icon','purenote' ),
                    'purenote_field_limit'          => 4
                ),
                array(
                    'social_icon' => array(
                        'type'          => 'social_icon',   
                        'label'         => __( 'Social Icon', 'purenote' ),
                        'description'   => __( 'Choose social media icon.', 'purenote' )
                    ),
                    'social_url'  => array(
                        'type'          => 'url',
                        'label'         => __( 'Social Link URL', 'purenote' ),
                        'description'   => __( 'Enter social media url.', 'purenote' )
                    ),
                    'item_visible'   => array(
                        'type'  => 'hidden'
                    )
                )
            )
        );
    }

endif;