<?php
/**
 * Product Section
 *
 * @package jewelry_accessories
 */

$wp_customize->add_section(
	'jewelry_accessories_products_section',
	array(
		'panel'    => 'jewelry_accessories_front_page_options',
		'title'    => esc_html__( 'Product Section', 'jewelry-accessories' ),
		'priority' => 10,
	)
);

// Product Section - Enable Section.
$wp_customize->add_setting(
	'jewelry_accessories_enable_product_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'jewelry_accessories_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Jewelry_Accessories_Toggle_Switch_Custom_Control(
		$wp_customize,
		'jewelry_accessories_enable_product_section',
		array(
			'label'    => esc_html__( 'Enable Product Section', 'jewelry-accessories' ),
			'section'  => 'jewelry_accessories_products_section',
			'settings' => 'jewelry_accessories_enable_product_section',
		)
	)
);

if ( isset( $wp_customize->selective_refresh ) ) {
	$wp_customize->selective_refresh->add_partial(
		'jewelry_accessories_enable_product_section',
		array(
			'selector' => '#jewelry_accessories_service_section .section-link',
			'settings' => 'jewelry_accessories_enable_product_section',
		)
	);
}

// Product Section - Heading.
$wp_customize->add_setting(
	'jewelry_accessories_trending_product_heading',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'jewelry_accessories_trending_product_heading',
	array(
		'label'           => esc_html__( 'Heading', 'jewelry-accessories' ),
		'section'         => 'jewelry_accessories_products_section',
		'settings'        => 'jewelry_accessories_trending_product_heading',
		'type'            => 'text',
		'active_callback' => 'jewelry_accessories_is_product_section_enabled',
	)
);

if(class_exists('woocommerce')){

$jewelry_accessories_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
);
$jewelry_accessories_categories = get_categories($jewelry_accessories_args);
$jewelry_accessories_cat_posts = array();
$jewelry_accessories_m = 0;
$jewelry_accessories_cat_posts[]='Select';
foreach($jewelry_accessories_categories as $jewelry_accessories_category){
	if($jewelry_accessories_m==0){
		$jewelry_accessories_default = $jewelry_accessories_category->slug;
		$jewelry_accessories_m++;
	}
	$jewelry_accessories_cat_posts[$jewelry_accessories_category->slug] = $jewelry_accessories_category->name;
}

$wp_customize->add_setting('jewelry_accessories_trending_product_category',array(
	'default'	=> 'uncategorized',
	'sanitize_callback' => 'jewelry_accessories_sanitize_select',
));
$wp_customize->add_control('jewelry_accessories_trending_product_category',array(
	'type'    => 'select',
	'choices' => $jewelry_accessories_cat_posts,
	'label' => __('Select category to display products ','jewelry-accessories'),
	'section' => 'jewelry_accessories_products_section',
	'active_callback' => 'jewelry_accessories_is_product_section_enabled',
));
}

$wp_customize->add_setting( 
	'jewelry_accessories_product_settings_upgraded_features',
	array(
		'sanitize_callback' => 'sanitize_text_field'
	)
);

$wp_customize->add_control(
	'jewelry_accessories_product_settings_upgraded_features', 
	array(
		'type'=> 'hidden',
		'description' => "
			<div class='customizer-upgraded-features'>
				<i class='fas fa-info-circle'></i>
				<span class='pro-text'>
					Unlock Premium <strong>Features</strong> ?<br>
					<a target='_blank' href='". esc_url(JEWELRY_ACCESSORIES_PREMIUM_PAGE) ." '>Upgrade Pro</a>
				</div>
			</div>
		",
		'section' => 'jewelry_accessories_products_section'
	)
);