<?php
/**
 * Service Section
 *
 * @package clothing_marketplace
 */

 $wp_customize->add_section(
	'clothing_marketplace_services_section',
	array(
		'panel'    => 'clothing_marketplace_front_page_options',
		'title'    => esc_html__( 'WooCommerce Products Section', 'clothing-marketplace' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Clothing_Marketplace_Toggle_Switch_Custom_Control(
		$wp_customize,
		'clothing_marketplace_enable_services_section',
		array(
			'label'    => esc_html__( 'Enable Products Section', 'clothing-marketplace' ),
			'section'  => 'clothing_marketplace_services_section',
			'settings' => 'clothing_marketplace_enable_services_section'
		)
	)
);

// Service Section - Content Label.
$wp_customize->add_setting(
	'clothing_marketplace_trending_post_content',
	array(
		'default'           => __( 'Mid-Season Sale', 'clothing-marketplace' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'clothing_marketplace_trending_post_content',
	array(
		'label'           => esc_html__( 'Section Title', 'clothing-marketplace' ),
		'section'         => 'clothing_marketplace_services_section',
		'settings'        => 'clothing_marketplace_trending_post_content',
		'type'            => 'text',
		'active_callback' => 'clothing_marketplace_is_services_section_enabled',
	)
);

// Number of Products to Show.
$wp_customize->add_setting('clothing_marketplace_services_post_count',array(
	'default'	=> 6,
	'sanitize_callback'	=> 'absint',
));
$wp_customize->add_control('clothing_marketplace_services_post_count',array(
	'label'	=> __('Number of Products to Show','clothing-marketplace'),
	'section'	=> 'clothing_marketplace_services_section',
	'type'		=> 'number',
	'active_callback' => 'clothing_marketplace_is_services_section_enabled',
	'input_attrs' => array(
		'step'             => 1,
		'min'              => 1,
		'max'              => 12,
	)
));

// Product Category Slug.
$wp_customize->add_setting(
	'clothing_marketplace_services_product_category',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'clothing_marketplace_services_product_category',
	array(
		'label'           => esc_html__( 'Select Product Category', 'clothing-marketplace' ),
		'description'     => esc_html__( 'Choose a category to display products.', 'clothing-marketplace' ),
		'section'         => 'clothing_marketplace_services_section',
		'settings'        => 'clothing_marketplace_services_product_category',
		'type'            => 'select',
		'choices'         => clothing_marketplace_get_product_categories(),
		'active_callback' => 'clothing_marketplace_is_services_section_enabled',
	)
);

// Partial Refresh
if ( isset( $wp_customize->selective_refresh ) ) {
	$wp_customize->selective_refresh->add_partial(
		'clothing_marketplace_enable_services_section',
		array(
			'selector' => '#clothing_marketplace_services_section .section-link',
			'settings' => 'clothing_marketplace_enable_services_section',
		)
	);
}