<?php
/**
 * Instagram Settings
 *
 * @package Chic Lifestyle
 */

add_action( 'customize_register', 'chic_lifestyle_customize_instagram_section' );

function chic_lifestyle_customize_instagram_section( $wp_customize ) {

    // Add the Instagram Section under Theme Options (Homepage Options panel).
    $wp_customize->add_section( 'chic_lifestyle_instagram_section', array(
        'title'       => esc_html__( 'Instagram Section', 'chic-lifestyle' ),
        'description' => esc_html__( 'Configure the Instagram section settings.', 'chic-lifestyle' ),
        'panel'       => 'chic_lifestyle_homepage_panel', // Adjust if your panel ID is different.
        'priority'    => 4,
    ) );

    // 1. Toggle: Hide / Show Instagram Section.
    $wp_customize->add_setting( 'instagram_display_option', array(
        'default'           => true,
        'sanitize_callback' => 'chic_lifestyle_sanitize_checkbox',
    ) );
    $wp_customize->add_control( new Chic_Lifestyle_Toggle_Control( $wp_customize, 'instagram_display_option', array(
        'label'    => esc_html__( 'Hide / Show Instagram Section', 'chic-lifestyle' ),
        'section'  => 'chic_lifestyle_instagram_section',
        'settings' => 'instagram_display_option',
        'type'     => 'toggle',
    ) ) );

    $wp_customize->selective_refresh->add_partial( 'instagram_display_option', array(
        'selector' => '#chic_lifestyle_instagram_section > .container',
    ) );

    // 2. Text Field: Instagram Section Title.
    $wp_customize->add_setting( 'instagram_section_title', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
    ) );
    $wp_customize->add_control( 'instagram_section_title', array(
        'label'    => esc_html__( 'Section Title', 'chic-lifestyle' ),
        'section'  => 'chic_lifestyle_instagram_section',
        'settings' => 'instagram_section_title',
        'type'     => 'text',
    ) );

    // 3. Color Picker: Background Color.
    $wp_customize->add_setting( 'instagram_bg_color', array(
        'default'           => '#66d6d2',
        'sanitize_callback' => 'sanitize_hex_color',
    ) );
    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'instagram_bg_color', array(
        'label'    => esc_html__( 'Background Color', 'chic-lifestyle' ),
        'section'  => 'chic_lifestyle_instagram_section',
        'settings' => 'instagram_bg_color',
    ) ) );

    // 4. Text Area: Instagram Shortcode.
    $wp_customize->add_setting( 'instagram_shortcode', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_textarea_field', // Alternatively, create your own callback if needed.
    ) );
    $wp_customize->add_control( 'instagram_shortcode', array(
        'label'       => esc_html__( 'Shortcode', 'chic-lifestyle' ),
        'description' => esc_html__( 'Use external plugin to display your Instagram content here. Insert the plugin shortcode below:', 'chic-lifestyle' ),
        'section'     => 'chic_lifestyle_instagram_section',
        'settings'    => 'instagram_shortcode',
        'type'        => 'textarea',
    ) );
}
