<?php
/**
 * Services Section
 *
 * @package cleaning_services_agent
 */

$wp_customize->add_section(
	'cleaning_services_agent_services_section',
	array(
		'panel'    => 'cleaning_services_agent_front_page_options',
		'title'    => esc_html__( 'Services Section', 'cleaning-services-agent' ),
		'priority' => 10,
	)
);

// Services Section - Enable Section.
$wp_customize->add_setting(
	'cleaning_services_agent_enable_service_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'cleaning_services_agent_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Cleaning_Services_Agent_Toggle_Switch_Custom_Control(
		$wp_customize,
		'cleaning_services_agent_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Services Section', 'cleaning-services-agent' ),
			'section'  => 'cleaning_services_agent_services_section',
			'settings' => 'cleaning_services_agent_enable_service_section',
		)
	)
);

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

// Services Section - Short Heading.
$wp_customize->add_setting(
	'cleaning_services_agent_services_short_heading',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'cleaning_services_agent_services_short_heading',
	array(
		'label'           => esc_html__( 'Short Heading', 'cleaning-services-agent' ),
		'section'         => 'cleaning_services_agent_services_section',
		'settings'        => 'cleaning_services_agent_services_short_heading',
		'type'            => 'text',
		'active_callback' => 'cleaning_services_agent_is_service_section_enabled',
	)
);

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

$wp_customize->add_control(
	'cleaning_services_agent_services_heading',
	array(
		'label'           => esc_html__( 'Heading', 'cleaning-services-agent' ),
		'section'         => 'cleaning_services_agent_services_section',
		'settings'        => 'cleaning_services_agent_services_heading',
		'type'            => 'text',
		'active_callback' => 'cleaning_services_agent_is_service_section_enabled',
	)
);

// Services Section - Content.
$wp_customize->add_setting(
	'cleaning_services_agent_services_content',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'cleaning_services_agent_services_content',
	array(
		'label'           => esc_html__( 'Content', 'cleaning-services-agent' ),
		'section'         => 'cleaning_services_agent_services_section',
		'settings'        => 'cleaning_services_agent_services_content',
		'type'            => 'text',
		'active_callback' => 'cleaning_services_agent_is_service_section_enabled',
	)
);

$cleaning_services_agent_args = array(
	'type'                     => 'post', 
	'child_of'                 => 0,
	'parent'                   => '',
	'orderby'                  => 'term_group',
	'order'                    => 'ASC',
	'hide_empty'               => false,
	'hierarchical'             => 1,
	'number'                   => '',
	'taxonomy'                 => 'category',
	'pad_counts'               => false
);
$cleaning_services_agent_categories = get_categories($cleaning_services_agent_args);
$cleaning_services_agent_cat_posts = array();
$cleaning_services_agent_m = 0;
$cleaning_services_agent_cat_posts[] = 'Select';

foreach($cleaning_services_agent_categories as $cleaning_services_agent_category){
	if($cleaning_services_agent_m == 0){
		$cleaning_services_agent_default = $cleaning_services_agent_category->slug;
		$cleaning_services_agent_m++;
	}
	$cleaning_services_agent_cat_posts[$cleaning_services_agent_category->slug] = $cleaning_services_agent_category->name;
}

$wp_customize->add_setting('cleaning_services_agent_trending_post_category', array(
	'default'	=> 'Services',
	'sanitize_callback' => 'cleaning_services_agent_sanitize_select',
));

$wp_customize->add_control('cleaning_services_agent_trending_post_category', array(
	'type'    => 'select',
	'choices' => $cleaning_services_agent_cat_posts,
	'label'   => __('Select category to display posts ','cleaning-services-agent'),
	'section' => 'cleaning_services_agent_services_section',
	'active_callback' => 'cleaning_services_agent_is_service_section_enabled',
));