<?php

/**
 * Service Section
 *
 * @package aster_ebooks
 */

$wp_customize->add_section(
	'aster_ebooks_product_section',
	array(
		'panel'    => 'aster_ebooks_front_page_options',
		'title'    => esc_html__( 'Trending Product Section', 'aster-ebooks' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Aster_Ebooks_Toggle_Switch_Custom_Control(
		$wp_customize,
		'aster_ebooks_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Trending Product Section', 'aster-ebooks' ),
			'section'  => 'aster_ebooks_product_section',
			'settings' => 'aster_ebooks_enable_service_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'aster_ebooks_trending_product_heading',
	array(
		'label'           => esc_html__( 'Heading', 'aster-ebooks' ),
		'section'         => 'aster_ebooks_product_section',
		'settings'        => 'aster_ebooks_trending_product_heading',
		'type'            => 'text',
		'active_callback' => 'aster_ebooks_is_service_section_enabled',
	)
);

if(class_exists('woocommerce')){

$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
);
$aster_ebooks_categories = get_categories($args);
$aster_ebooks_cat_posts = array();
$aster_ebooks_m = 0;
$aster_ebooks_cat_posts[]='Select';
foreach($aster_ebooks_categories as $aster_ebooks_category){
	if($aster_ebooks_m==0){
		$aster_ebooks_default = $aster_ebooks_category->slug;
		$aster_ebooks_m++;
	}
	$aster_ebooks_cat_posts[$aster_ebooks_category->slug] = $aster_ebooks_category->name;
}

$wp_customize->add_setting('aster_ebooks_trending_product_category',array(
	'default'	=> 'uncategorized',
	'sanitize_callback' => 'aster_ebooks_sanitize_select',
));
$wp_customize->add_control('aster_ebooks_trending_product_category',array(
	'type'    => 'select',
	'choices' => $aster_ebooks_cat_posts,
	'label' => __('Select category to display products ','aster-ebooks'),
	'section' => 'aster_ebooks_product_section',
	'active_callback' => 'aster_ebooks_is_service_section_enabled',
));
}