<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

/**
 * Extend customizer section.
 *
 * @package leather-house
 *
 * @see     WP_Customize_Section
 * @access  public
 */

function leatherhouse_frontpage_sections_settings( $wp_customize ) {

	$active_callback   = isset( $array['active_callback'] ) ? $array['active_callback'] : null;
	$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';


	/* Frontpage panel */
	$wp_customize->add_panel(
		'leatherhouse_frontpage_settings',
		array(
			'priority'   => 8,
			'capability' => 'edit_theme_options',
			'title'      => __( 'Frontpage Sections', 'leather-house' ),
		)
	);

	/* Hero Settings */
	$wp_customize->add_section(
		'leatherhouse_hero_section',
		array(
			'title'    => __( 'Hero Section', 'leather-house' ),
			'panel'    => 'leatherhouse_frontpage_settings',
			'priority' => 100,
		)
	);

	// Hero Section Image Primary.
	$wp_customize->add_setting(
		'leatherhouse_hero_img',
		array(
			'default'           => get_template_directory_uri() . '/assets/images/slide-1.webp',
			'sanitize_callback' => 'esc_url_raw',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Image_Control(
			$wp_customize,
			'leatherhouse_hero_img',
			array(
				'label'           => __( 'Background Image', 'leather-house' ),
				'priority'        => 16,
				'section'         => 'leatherhouse_hero_section',
				'settings'        => 'leatherhouse_hero_img',
				'active_callback' => 'leatherhouse_hero_img',
			)
		)
	);
	// Hero Section Section Image Primary.

	// Hero Section Link target.
	$wp_customize->add_setting(
		'leatherhouse_link_new_tab',
		array(
			'default'           => '_self',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control(
		new leatherhouse_Customize_Select_Control(
			$wp_customize,
			'leatherhouse_link_new_tab',
			array(
				//'type'            => 'radio',
				'priority'        => 8,
				'label'           => esc_html__( 'Link Target', 'leather-house' ),
				'section'         => 'leatherhouse_hero_section',
				'choices'         => array(
					'_self'  => esc_html__( 'Same Tab', 'leather-house' ),
					'_blank' => esc_html__( 'New Tab', 'leather-house' ),
				),
				'active_callback' => 'leatherhouse_link_new_tab',
			),
		)
	);

	// Hero Section Content Align
	$wp_customize->add_setting(
		'leatherhouse_hero_content_align',
		array(
			'default'           => 'center',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control(
		new leatherhouse_Customize_Select_Control(
			$wp_customize,
			'leatherhouse_hero_content_align',
			array(
				//'type'            => 'radio',
				'priority'        => 9,
				'label'           => esc_html__( 'Content Align', 'leather-house' ),
				'section'         => 'leatherhouse_hero_section',
				'choices'         => array(
					'left'   => esc_html__( 'Left', 'leather-house' ),
					'center' => esc_html__( 'Center', 'leather-house' ),
					'right'  => esc_html__( 'Right', 'leather-house' ),
				),
				'active_callback' => 'leatherhouse_hero_content_align',
			),
		)
	);

		// Hero Section Active Callback.
		include 'frontpage-callback/slider-callback.php';


	if ( class_exists( 'WooCommerce' ) ) {
		/* Woocommerce Settings  */
		$wp_customize->add_section(
			'leatherhouse_theme_woocommerce',
			array(
				'title'    => __( 'Products Section', 'leather-house' ),
				'panel'    => 'leatherhouse_frontpage_settings',
				'priority' => 200,
			)
		);

		// woocommerce Active Callback.
		include 'frontpage-callback/woocommerce-callback.php';
	}

	/* Showcase Settings */
	$wp_customize->add_section(
		'leatherhouse_theme_about',
		array(
			'title'    => __( 'Showcase Section', 'leather-house' ),
			'panel'    => 'leatherhouse_frontpage_settings',
			'priority' => 300,
		)
	);

	$wp_customize->add_setting(
		'leatherhouse_about_editor_content',
		array(
			'default'           => '',
			'sanitize_callback' => 'wp_kses_post',
		)
	);
	$wp_customize->add_control(
		new Skyrocket_TinyMCE_Custom_control(
			$wp_customize,
			'leatherhouse_about_editor_content',
			array(
				'label'           => __( 'Showcase Content', 'leather-house' ),
				'section'         => 'leatherhouse_theme_about',
				'priority'        => 15,
				'input_attrs'     => array(
					'toolbar1'     => 'bold italic bullist numlist alignleft aligncenter alignright link',
					'toolbar2'     => 'formatselect outdent indent | blockquote charmap',
					'mediaButtons' => true,
				),
				'active_callback' => 'leatherhouse_about_editor_content',
			)
		)
	);

		// Showcase Section Image Primary.
			$wp_customize->add_setting(
				'leatherhouse_about_img_prime',
				array(
					'default'           => get_template_directory_uri() . '/assets/images/about-1.webp',
					'sanitize_callback' => 'esc_url_raw',
				)
			);

			$wp_customize->add_control(
				new WP_Customize_Image_Control(
					$wp_customize,
					'leatherhouse_about_img_prime',
					array(
						'label'           => __( 'Primary Image', 'leather-house' ),
						'priority'        => 16,
						'section'         => 'leatherhouse_theme_about',
						'settings'        => 'leatherhouse_about_img_prime',
						'active_callback' => 'leatherhouse_about_img_prime',
					)
				)
			);
		// Showcase Section Image Primary.

		// Showcase Section Image Secondry.
		$wp_customize->add_setting(
			'leatherhouse_about_img_second',
			array(
				'default'           => get_template_directory_uri() . '/assets/images/about-2.webp',
				'sanitize_callback' => 'esc_url_raw',
			)
		);

		$wp_customize->add_control(
			new WP_Customize_Image_Control(
				$wp_customize,
				'leatherhouse_about_img_second',
				array(
					'label'           => __( 'Secondry Image', 'leather-house' ),
					'priority'        => 17,
					'section'         => 'leatherhouse_theme_about',
					'settings'        => 'leatherhouse_about_img_second',
					'active_callback' => 'leatherhouse_about_img_second',
				)
			)
		);
		// Showcase Section Image Secondry.

		// Showcase background Image.
		$wp_customize->add_setting(
			'leatherhouse_about_background',
			array(
				'default'           => '',
				'sanitize_callback' => 'esc_url_raw',
			)
		);

		$wp_customize->add_control(
			new WP_Customize_Image_Control(
				$wp_customize,
				'leatherhouse_about_background',
				array(
					'label'           => __( 'About Section Background Image', 'leather-house' ),
					'priority'        => 50,
					'section'         => 'leatherhouse_theme_about',
					'settings'        => 'leatherhouse_about_background',
					'active_callback' => 'leatherhouse_about_background',
				)
			)
		);
		// Showcase background Image End.

		// Showcase Active Callback.
		include 'frontpage-callback/about-callback.php';

	/* Blog Settings*/
	$wp_customize->add_section(
		'leatherhouse_theme_blog',
		array(
			'title'    => __( 'News Section', 'leather-house' ),
			'panel'    => 'leatherhouse_frontpage_settings',
			'priority' => 900,
		)
	);
	
		// Sanitize callback for category
		function leatherhouse_sanitize_category( $value ) {
			// Sanitize category value, e.g., ensure it's a valid category slug or ID
			$value = sanitize_text_field( $value ); // or you can use sanitize_key() if it's a slug
			return $value;
		}

		// Add setting with the custom sanitize callback
		$wp_customize->add_setting( 'leatherhouse_theme_blog_category', array(
			'capability' => 'edit_theme_options',
			'sanitize_callback' => 'leatherhouse_sanitize_category', // Use custom sanitize function
		) );
		$wp_customize->add_control(
			new leatherhouse_Customize_Category_Control(
				$wp_customize,
				'leatherhouse_theme_blog_category',
				array(
					'label'             => __( 'Choose News Category', 'leather-house' ),
					'section'           => 'leatherhouse_theme_blog',
					'settings'          => 'leatherhouse_theme_blog_category',
					'sanitize_callback' => 'sanitize_text_field',
					'active_callback'   => 'leatherhouse_theme_blog_category',
				)
			)
		);

		// Blog Background Image.
		$wp_customize->add_setting(
			'leatherhouse_blog_background',
			array(
				'default'           => '',
				'sanitize_callback' => 'esc_url_raw',
			)
		);

		$wp_customize->add_control(
			new WP_Customize_Image_Control(
				$wp_customize,
				'leatherhouse_blog_background',
				array(
					'label'           => __( 'Background Image', 'leather-house' ),
					'section'         => 'leatherhouse_theme_blog',
					'priority'        => 300,
					'settings'        => 'leatherhouse_blog_background',
					'active_callback' => 'leatherhouse_blog_background',
				)
			)
		);

		// Blog Active Callback.
		include 'frontpage-callback/blog-callback.php';

	

}
add_action( 'customize_register', 'leatherhouse_frontpage_sections_settings' );


function leatherhouse_Customizer_selective_refresh_settings( $wp_customize ) {

	$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';

	// Hero Title.
	$wp_customize->add_setting(
		'leatherhouse_hero_area_title',
		array(
			'default'           => __( 'Effortless Style, Every Day', 'leather-house' ),
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_hero_area_title',
		array(
			'label'           => esc_html__( 'Title', 'leather-house' ),
			'section'         => 'leatherhouse_hero_section',
			'priority'        => 3,
			'type'            => 'text',
			'active_callback' => 'leatherhouse_hero_area_title',
		)
	);
	
	// Hero Description.
	$wp_customize->add_setting(
		'leatherhouse_hero_area_desc',
		array(
			'default'           => __( 'Take Your Website To New Heights & Build The Website Of Your Dreams', 'leather-house' ),
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_hero_area_desc',
		array(
			'label'           => esc_html__( 'Description', 'leather-house' ),
			'section'         => 'leatherhouse_hero_section',
			'priority'        => 4,
			'type'            => 'textarea',
			'active_callback' => 'leatherhouse_hero_area_desc',
		)
	);

	// Hero Button Title.
	$wp_customize->add_setting(
		'leatherhouse_hero_area_btn_title',
		array(
			'default'           => __( 'Go To Shop', 'leather-house' ),
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_hero_area_btn_title',
		array(
			'label'           => esc_html__( 'Button Title', 'leather-house' ),
			'section'         => 'leatherhouse_hero_section',
			'priority'        => 5,
			'type'            => 'text',
			'active_callback' => 'leatherhouse_hero_area_btn_title',
		)
	);
	
	// Hero Button Link.
	$wp_customize->add_setting(
		'leatherhouse_hero_area_btn_link',
		array(
			'default'           => __( '#', 'leather-house' ),
			'sanitize_callback' => 'esc_url_raw',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_hero_area_btn_link',
		array(
			'label'           => esc_html__( 'Button Link', 'leather-house' ),
			'section'         => 'leatherhouse_hero_section',
			'priority'        => 6,
			'type'            => 'text',
			'active_callback' => 'leatherhouse_hero_area_btn_link',
		)
	);

	// Showcase Title.
	$wp_customize->add_setting(
		'leatherhouse_about_area_title',
		array(
			'default'           => __( 'Sink into the Luxury of Premium Leather Products', 'leather-house' ),
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_about_area_title',
		array(
			'label'           => esc_html__( 'Title', 'leather-house' ),
			'section'         => 'leatherhouse_theme_about',
			'priority'        => 4,
			'type'            => 'text',
			'active_callback' => 'leatherhouse_about_area_title',
		)
	);

	// Showcase Desc.
	$wp_customize->add_setting(
		'leatherhouse_about_area_des',
		array(
			'default'           => __( 'Experience the ultimate in comfort. Our showcase highlights pure leather goods, renowned for their unparalleled softness and luxurious feel.', 'leather-house' ),
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_about_area_des',
		array(
			'label'           => esc_html__( 'Description', 'leather-house' ),
			'section'         => 'leatherhouse_theme_about',
			'priority'        => 5,
			'type'            => 'textarea',
			'active_callback' => 'leatherhouse_about_area_des',
		)
	);

	// Showcase Button Title.
	$wp_customize->add_setting(
		'leatherhouse_about_area_btn_title',
		array(
			'default'           => __( 'See all Collections', 'leather-house' ),
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_about_area_btn_title',
		array(
			'label'           => esc_html__( 'Button Title', 'leather-house' ),
			'section'         => 'leatherhouse_theme_about',
			'priority'        => 5,
			'type'            => 'text',
			'active_callback' => 'leatherhouse_about_area_btn_title',
		)
	);

	// Showcase Button Link.
	$wp_customize->add_setting(
		'leatherhouse_about_area_btn_link',
		array(
			'default'           => __( '#', 'leather-house' ),
			'sanitize_callback' => 'esc_url_raw',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_about_area_btn_link',
		array(
			'label'           => esc_html__( 'Button Link', 'leather-house' ),
			'section'         => 'leatherhouse_theme_about',
			'priority'        => 5,
			'type'            => 'text',
			'active_callback' => 'leatherhouse_about_area_btn_link',
		)
	);

	// News Title.
	$wp_customize->add_setting(
		'leatherhouse_blog_area_title',
		array(
			'default'           => __( 'News From Our Wearhouse', 'leather-house' ),
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_blog_area_title',
		array(
			'label'           => esc_html__( 'Section Title', 'leather-house' ),
			'section'         => 'leatherhouse_theme_blog',
			'priority'        => 4,
			'type'            => 'text',
			'active_callback' => 'leatherhouse_blog_area_title',
		)
	);
	// News Description.
	$wp_customize->add_setting(
		'leatherhouse_blog_area_des',
		array(
			'default'           => __( 'Stay updated with the latest news by reading our articles written by content writers in the industry.', 'leather-house' ),
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_blog_area_des',
		array(
			'label'           => esc_html__( 'Section Description', 'leather-house' ),
			'section'         => 'leatherhouse_theme_blog',
			'priority'        => 5,
			'type'            => 'textarea',
			'active_callback' => 'leatherhouse_blog_area_des',
		)
	);

	// News Button Title.
	$wp_customize->add_setting(
		'leatherhouse_blog_button_text',
		array(
			'default'           => __( 'Show More', 'leather-house' ),
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_blog_button_text',
		array(
			'label'           => esc_html__( 'Button Title', 'leather-house' ),
			'section'         => 'leatherhouse_theme_blog',
			'priority'        => 5,
			'type'            => 'text',
			'active_callback' => 'leatherhouse_blog_button_text',
		)
	);

	// News Button Link.
	$wp_customize->add_setting(
		'leatherhouse_blog_button_link',
		array(
			'default'           => __( '#', 'leather-house' ),
			'sanitize_callback' => 'esc_url_raw',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_blog_button_link',
		array(
			'label'           => esc_html__( 'Button Link', 'leather-house' ),
			'section'         => 'leatherhouse_theme_blog',
			'priority'        => 5,
			'type'            => 'text',
			'active_callback' => 'leatherhouse_blog_button_link',
		)
	);

	// Woocommerce Title.
	$wp_customize->add_setting(
		'leatherhouse_woocommerce_area_title',
		array(
			'default'           => 'FEATURED PRODUCTS',
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_woocommerce_area_title',
		array(
			'label'           => esc_html__( 'Title', 'leather-house' ),
			'section'         => 'leatherhouse_theme_woocommerce',
			'priority'        => 6,
			'type'            => 'text',
			'active_callback' => 'leatherhouse_woocommerce_area_title',
		)
	);

	// Woocommerce Description.
	$wp_customize->add_setting(
		'leatherhouse_woocommerce_area_desc',
		array(
			'default'           => 'Showcase your products in this beautiful shop section',
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_woocommerce_area_desc',
		array(
			'label'           => esc_html__( 'Description', 'leather-house' ),
			'section'         => 'leatherhouse_theme_woocommerce',
			'priority'        => 6,
			'type'            => 'textarea',
			'active_callback' => 'leatherhouse_woocommerce_area_desc',
		)
	);


	// Contact Page Title.
	$wp_customize->add_setting(
		'leatherhouse_contact_area_title',
		array(
			'default'           => 'Get in Touch with Leather House',
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_contact_area_title',
		array(
			'label'           => esc_html__( 'Title', 'leather-house' ),
			'section'         => 'leatherhouse_template_contact_us',
			'priority'        => 5,
			'type'            => 'text',
		)
	);

	// Contact Page Desc.
	$wp_customize->add_setting(
		'leatherhouse_contact_area_des',
		array(
			'default'           => 'Reach out to us with any questions, inquiries, or feedback. Our team is here to assist you promptly and ensure your experience with Leather House is exceptional. Let"s connect and explore the world of fine leather craftsmanship together.',
			'sanitize_callback' => 'sanitize_text_field',
			'transport'         => $selective_refresh,
		)
	);
	$wp_customize->add_control(
		'leatherhouse_contact_area_des',
		array(
			'label'           => esc_html__( 'Description', 'leather-house' ),
			'section'         => 'leatherhouse_template_contact_us',
			'priority'        => 10,
			'type'            => 'textarea',
		)
	);	
}
add_action( 'customize_register', 'leatherhouse_Customizer_selective_refresh_settings' );
