<?php

/**
 * Service Section
 *
 * @package cat_groomer
 */

$wp_customize->add_section(
	'cat_groomer_products_section',
	array(
		'panel'    => 'cat_groomer_front_page_options',
		'title'    => esc_html__( 'Product Section', 'cat-groomer' ),
		'priority' => 10,
	)
);

// Service Section - Enable Section.
$wp_customize->add_setting(
	'cat_groomer_enable_service_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'cat_groomer_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Cat_Groomer_Toggle_Switch_Custom_Control(
		$wp_customize,
		'cat_groomer_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Product Section', 'cat-groomer' ),
			'section'  => 'cat_groomer_products_section',
			'settings' => 'cat_groomer_enable_service_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'cat_groomer_trending_product_heading',
	array(
		'label'           => esc_html__( 'Heading', 'cat-groomer' ),
		'section'         => 'cat_groomer_products_section',
		'settings'        => 'cat_groomer_trending_product_heading',
		'type'            => 'text',
		'active_callback' => 'cat_groomer_is_product_section_enabled',
	)
);

if(class_exists('woocommerce')){

$cat_groomer_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
);
$cat_groomer_categories = get_categories($cat_groomer_args);
$cat_groomer_cat_posts = array();
$cat_groomer_m = 0;
$cat_groomer_cat_posts[]='Select';
foreach($cat_groomer_categories as $cat_groomer_category){
	if($cat_groomer_m==0){
		$cat_groomer_default = $cat_groomer_category->slug;
		$cat_groomer_m++;
	}
	$cat_groomer_cat_posts[$cat_groomer_category->slug] = $cat_groomer_category->name;
}

$wp_customize->add_setting('cat_groomer_trending_product_category',array(
	'default'	=> 'uncategorized',
	'sanitize_callback' => 'cat_groomer_sanitize_select',
));
$wp_customize->add_control('cat_groomer_trending_product_category',array(
	'type'    => 'select',
	'choices' => $cat_groomer_cat_posts,
	'label' => __('Select category to display products ','cat-groomer'),
	'section' => 'cat_groomer_products_section',
	'active_callback' => 'cat_groomer_is_product_section_enabled',
));
}