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

 $wp_customize->add_section(
	'jeweler_shop_product_section',
	array(
		'panel'    => 'jeweler_shop_front_page_options',
		'title'    => esc_html__( 'Product Section', 'jeweler-shop' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Jeweler_Shop_Toggle_Switch_Custom_Control(
		$wp_customize,
		'jeweler_shop_enable_product_section',
		array(
			'label'    => esc_html__( 'Enable Product Section', 'jeweler-shop' ),
			'section'  => 'jeweler_shop_product_section',
			'settings' => 'jeweler_shop_enable_product_section'
		)
	)
);

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

$wp_customize->add_control(
	'jeweler_shop_trending_product_heading',
	array(
		'label'           => esc_html__( 'Heading', 'jeweler-shop' ),
		'section'         => 'jeweler_shop_product_section',
		'settings'        => 'jeweler_shop_trending_product_heading',
		'type'            => 'text',
		'active_callback' => 'jeweler_shop_is_product_section_enabled',
	)
);

// Product Section - Button Label.
$wp_customize->add_setting(
	'jeweler_shop_product_button_label_',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'jeweler_shop_product_button_label_',
	array(
		'label'           => esc_html__( 'Button Label', 'jeweler-shop'  ),
		'section'         => 'jeweler_shop_product_section',
		'settings'        => 'jeweler_shop_product_button_label_',
		'type'            => 'text',
		'active_callback' => 'jeweler_shop_is_product_section_enabled',
	)
);

// Product Section - Button Link.
$wp_customize->add_setting(
	'jeweler_shop_product_button_link_',
	array(
		'default'           => '',
		'sanitize_callback' => 'esc_url_raw',
	)
);

$wp_customize->add_control(
	'jeweler_shop_product_button_link_',
	array(
		'label'           => esc_html__( 'Button Link', 'jeweler-shop' ),
		'section'         => 'jeweler_shop_product_section',
		'settings'        => 'jeweler_shop_product_button_link_',
		'type'            => 'url',
		'active_callback' => 'jeweler_shop_is_product_section_enabled',
	)
);

// Add Separator Custom Control
$wp_customize->add_setting( 'jeweler_shop_product_separators', array(
	'sanitize_callback' => 'sanitize_text_field',
) );

$wp_customize->add_control( new Jeweler_Shop_Separator_Custom_Control( $wp_customize, 'jeweler_shop_product_separators', array(
	'label' => __( 'Select Product Category', 'jeweler-shop' ),
	'section' => 'jeweler_shop_product_section',
	'settings' => 'jeweler_shop_product_separators',
	'active_callback' => 'jeweler_shop_is_product_section_enabled',
)));


if(class_exists('woocommerce')){

	$jeweler_shop_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
	);
	$jeweler_shop_categories = get_categories($jeweler_shop_args);
	$jeweler_shop_cat_posts = array();
	$jeweler_shop_m = 0;
	$jeweler_shop_cat_posts[]='Select';
	foreach($jeweler_shop_categories as $jeweler_shop_category){
		if($jeweler_shop_m==0){
			$jeweler_shop_default = $jeweler_shop_category->slug;
			$jeweler_shop_m++;
		}
		$jeweler_shop_cat_posts[$jeweler_shop_category->slug] = $jeweler_shop_category->name;
	}
	
	$wp_customize->add_setting('jeweler_shop_trending_product_category',array(
		'default'	=> 'uncategorized',
		'sanitize_callback' => 'jeweler_shop_sanitize_select',
	));
	$wp_customize->add_control('jeweler_shop_trending_product_category',array(
		'type'    => 'select',
		'choices' => $jeweler_shop_cat_posts,
		'label' => __('Select category to display products ','jeweler-shop'),
		'section' => 'jeweler_shop_product_section',
		'active_callback' => 'jeweler_shop_is_product_section_enabled',
	));
}

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

$wp_customize->add_control(
	'jeweler_shop_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(JEWELER_SHOP_PREMIUM_PAGE) ." '>Upgrade Pro</a>
				</div>
			</div>
		",
		'section' => 'jeweler_shop_product_section'
	)
);