<?php
function pet_house_blog_setting( $wp_customize ) {

$wp_customize->register_control_type( 'Pet_House_Control_Upgrade' );

$selective_refresh = isset( $wp_customize->selective_refresh ) ? 'postMessage' : 'refresh';
	$wp_customize->add_panel(
		'pet_house_frontpage_sections', array(
			'priority' => 1,
			'title' => esc_html__( 'Frontpage Sections', 'pet-house' ),
		)
	);
	
	/*=========================================
	Slider Section
	=========================================*/
	$wp_customize->add_section(
		'pet_house_slider_section', array(
			'title' => esc_html__( 'Slider Section', 'pet-house' ),
			'priority' => 13,
			'panel' => 'pet_house_frontpage_sections',
		)
	);

	// Slider Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'pet_house_slider_setting' , 
			array(
			'default' => false,
			'sanitize_callback' => 'pet_house_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'pet_house_slider_setting', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'pet-house' ),
			'section'     => 'pet_house_slider_section',
			'settings'    => 'pet_house_slider_setting',
			'type'        => 'checkbox'
		) 
	);
	
	// Slider 1
	$wp_customize->add_setting( 
    	'pet_house_slider1',
    	array(
            'default'           => get_page_id_by_slug('slider-page'), // This function should be defined (see below)
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'wp_kses_post',
			'priority'      => 1,
		)
	);	

	$wp_customize->add_control( 
		'pet_house_slider1',
		array(
		    'label'   		=> __('Slider 1','pet-house'),
		    'section'		=> 'pet_house_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);		

	// Slider 2
	$wp_customize->add_setting(
    	'pet_house_slider2',
    	array(
            'default'           => get_page_id_by_slug('slider-pages'),
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'wp_kses_post',
			'priority'      => 2,
		)
	);

	$wp_customize->add_control( 
		'pet_house_slider2',
		array(
		    'label'   		=> __('Slider 2','pet-house'),
		    'section'		=> 'pet_house_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

	// Slider 3
	$wp_customize->add_setting(
    	'pet_house_slider3',
    	array(
            'default'           => get_page_id_by_slug('slider-pagess'),
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'wp_kses_post',
			'priority'      => 3,
		)
	);

	$wp_customize->add_control( 
		'pet_house_slider3',
		array(
		    'label'   		=> __('Slider 3','pet-house'),
		    'section'		=> 'pet_house_slider_section',
			'type' 			=> 'dropdown-pages',
			'transport'         => $selective_refresh,
		)  
	);

	// Slider Text
	$wp_customize->add_setting( 
    	'pet_house_slider_text',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'sanitize_text_field',
			'priority'      => 1,
		)
	);	

	$wp_customize->add_control( 
		'pet_house_slider_text',
		array(
		    'label'   		=> __('Add Slider Top Text','pet-house'),
		    'section'		=> 'pet_house_slider_section',
			'type' 			=> 'text',
			'transport'         => $selective_refresh,
		)
	);
	
	$wp_customize->add_setting( 'pet_house_upgrade_page_settings_1111',
	array(
		'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Pet_House_Control_Upgrade(
		$wp_customize, 'pet_house_upgrade_page_settings_1111',
			array(
				'priority'      => 200,
				'section'       => 'pet_house_slider_section',
				'settings'      => 'pet_house_upgrade_page_settings_1111',
				'label'         => __( 'Pet House Pro comes with additional features.', 'pet-house' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'pet-house' ), __( 'One-Click Demo Import', 'pet-house' ), __( 'WooCommerce Integrated', 'pet-house' ), __( 'Drag & Drop Section Reordering', 'pet-house' ),__( 'Advanced Typography Control', 'pet-house' ),__( 'Intuitive Customization Options', 'pet-house' ),__( '24/7 Support', 'pet-house' ), )
			)
		)
	); 


	/*=========================================
	product Section
	=========================================*/
	$wp_customize->add_section(
		'pet_house_our_products_section', array(
			'title' => esc_html__( 'Trending Products Section', 'pet-house' ),
			'priority' => 13,
			'panel' => 'pet_house_frontpage_sections',
		)
	);

	// About Us Hide/ Show Setting // 
	$wp_customize->add_setting( 
		'pet_house_our_products_show_hide_section' , 
			array(
				'default' => false,
			'sanitize_callback' => 'pet_house_sanitize_checkbox',
			'capability' => 'edit_theme_options',
			'priority' => 2,
		) 
	);
	
	$wp_customize->add_control(
	'pet_house_our_products_show_hide_section', 
		array(
			'label'	      => esc_html__( 'Hide / Show Section', 'pet-house' ),
			'section'     => 'pet_house_our_products_section',
			'settings'    => 'pet_house_our_products_show_hide_section',
			'type'        => 'checkbox'
		) 
	);

	// About Heading
	$wp_customize->add_setting( 
    	'pet_house_our_products_heading_section',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);	

	$wp_customize->add_control( 
		'pet_house_our_products_heading_section',
		array(
		    'label'   		=> __('Add Heading','pet-house'),
		    'section'		=> 'pet_house_our_products_section',
			'type' 			=> 'text',
		)
	);

	$wp_customize->add_setting( 
    	'pet_house_our_products_short_heading_section',
    	array(
			'capability'     	=> 'edit_theme_options',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);	

	$wp_customize->add_control( 
		'pet_house_our_products_short_heading_section',
		array(
		    'label'   		=> __('Add Short Heading','pet-house'),
		    'section'		=> 'pet_house_our_products_section',
			'type' 			=> 'text',
		)
	);

	$pet_house_args = array(
	    'type'           => 'product',
	    'child_of'       => 0,
	    'parent'         => '',
	    'orderby'        => 'term_group',
	    'order'          => 'ASC',
	    'hide_empty'     => false,
	    'hierarchical'   => 1,
	    'number'         => '',
	    'taxonomy'       => 'product_cat',
	    'pad_counts'     => false
	);
	$pet_house_categories = get_categories($pet_house_args);
	$pet_house_cats = array();
	$pet_house_i = 0;
	foreach ($pet_house_categories as $pet_house_category) {
	    if ($pet_house_i == 0) {
	        $pet_house_default = $pet_house_category->slug;
	        $pet_house_i++;
	    }
	    $pet_house_cats[$pet_house_category->slug] = $pet_house_category->name;
	}

	// Set the default value to "none"
	$pet_house_default_value = 'product_cat1';

	$wp_customize->add_setting(
	    'pet_house_our_product_product_category',
	    array(
	        'default'           => $pet_house_default_value,
	        'sanitize_callback' => 'pet_house_sanitize_select',
	    )
	);

	// Add "None" as an option in the select dropdown
	$pet_house_cats_with_none = array_merge(array('none' => 'None'), $pet_house_cats);

	$wp_customize->add_control(
	    'pet_house_our_product_product_category',
	    array(
	        'type'    => 'select',
	        'choices' => $pet_house_cats_with_none,
	        'label'   => __('Select Trending Products Category', 'pet-house'),
	        'section' => 'pet_house_our_products_section',
	    )
	);

	$wp_customize->add_setting( 'pet_house_upgrade_page_settings_101',
	array(
		'sanitize_callback' => 'sanitize_text_field'
		)
	);
	$wp_customize->add_control( new Pet_House_Control_Upgrade(
		$wp_customize, 'pet_house_upgrade_page_settings_101',
			array(
				'priority'      => 200,
				'section'       => 'pet_house_our_products_section',
				'settings'      => 'pet_house_upgrade_page_settings_101',
				'label'         => __( 'Pet House Pro comes with additional features.', 'pet-house' ),
				'choices'       => array( __( '15+ Ready-Made Sections', 'pet-house' ), __( 'One-Click Demo Import', 'pet-house' ), __( 'WooCommerce Integrated', 'pet-house' ), __( 'Drag & Drop Section Reordering', 'pet-house' ),__( 'Advanced Typography Control', 'pet-house' ),__( 'Intuitive Customization Options', 'pet-house' ),__( '24/7 Support', 'pet-house' ), )
			)
		)
	); 


}

add_action( 'customize_register', 'pet_house_blog_setting' );

// service selective refresh
function pet_house_blog_section_partials( $wp_customize ){	
	// blog_title
	$wp_customize->selective_refresh->add_partial( 'blog_title', array(
		'selector'            => '.home-blog .title h6',
		'settings'            => 'blog_title',
		'render_callback'  => 'pet_house_blog_title_render_callback',
	
	) );
	
	// blog_subtitle
	$wp_customize->selective_refresh->add_partial( 'blog_subtitle', array(
		'selector'            => '.home-blog .title h2',
		'settings'            => 'blog_subtitle',
		'render_callback'  => 'pet_house_blog_subtitle_render_callback',
	
	) );
	
	// blog_description
	$wp_customize->selective_refresh->add_partial( 'blog_description', array(
		'selector'            => '.home-blog .title p',
		'settings'            => 'blog_description',
		'render_callback'  => 'pet_house_blog_description_render_callback',
	
	) );	
	}

add_action( 'customize_register', 'pet_house_blog_section_partials' );

// blog_title
function pet_house_blog_title_render_callback() {
	return get_theme_mod( 'blog_title' );
}

// blog_subtitle
function pet_house_blog_subtitle_render_callback() {
	return get_theme_mod( 'blog_subtitle' );
}

// service description
function pet_house_blog_description_render_callback() {
	return get_theme_mod( 'blog_description' );
}