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

$wp_customize->add_section(
	'roof_water_proofing_services_section',
	array(
		'panel'    => 'roof_water_proofing_front_page_options',
		'title'    => esc_html__( 'Services Section', 'roof-water-proofing' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Roof_Water_Proofing_Toggle_Switch_Custom_Control(
		$wp_customize,
		'roof_water_proofing_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Services Section', 'roof-water-proofing' ),
			'section'  => 'roof_water_proofing_services_section',
			'settings' => 'roof_water_proofing_enable_service_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'roof_water_proofing_services_short_heading',
	array(
		'label'           => esc_html__( 'Short Heading', 'roof-water-proofing' ),
		'section'         => 'roof_water_proofing_services_section',
		'settings'        => 'roof_water_proofing_services_short_heading',
		'type'            => 'text',
		'active_callback' => 'roof_water_proofing_is_service_section_enabled',
	)
);

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

$wp_customize->add_control(
	'roof_water_proofing_services_heading',
	array(
		'label'           => esc_html__( 'Heading', 'roof-water-proofing' ),
		'section'         => 'roof_water_proofing_services_section',
		'settings'        => 'roof_water_proofing_services_heading',
		'type'            => 'text',
		'active_callback' => 'roof_water_proofing_is_service_section_enabled',
	)
);

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

$wp_customize->add_control(
	'roof_water_proofing_services_content',
	array(
		'label'           => esc_html__( 'Content', 'roof-water-proofing' ),
		'section'         => 'roof_water_proofing_services_section',
		'settings'        => 'roof_water_proofing_services_content',
		'type'            => 'text',
		'active_callback' => 'roof_water_proofing_is_service_section_enabled',
	)
);

$roof_water_proofing_args = array(
	'type'                     => 'post', 
	'child_of'                 => 0,
	'parent'                   => '',
	'orderby'                  => 'term_group',
	'order'                    => 'ASC',
	'hide_empty'               => false,
	'hierarchical'             => 1,
	'number'                   => '',
	'taxonomy'                 => 'category',
	'pad_counts'               => false
);
$roof_water_proofing_categories = get_categories($roof_water_proofing_args);
$roof_water_proofing_cat_posts = array();
$roof_water_proofing_m = 0;
$roof_water_proofing_cat_posts[] = 'Select';

foreach($roof_water_proofing_categories as $roof_water_proofing_category){
	if($roof_water_proofing_m == 0){
		$roof_water_proofing_default = $roof_water_proofing_category->slug;
		$roof_water_proofing_m++;
	}
	$roof_water_proofing_cat_posts[$roof_water_proofing_category->slug] = $roof_water_proofing_category->name;
}

$wp_customize->add_setting('roof_water_proofing_trending_post_category', array(
	'default'	=> 'Services',
	'sanitize_callback' => 'roof_water_proofing_sanitize_select',
));

$wp_customize->add_control('roof_water_proofing_trending_post_category', array(
	'type'    => 'select',
	'choices' => $roof_water_proofing_cat_posts,
	'label'   => __('Select category to display posts ','roof-water-proofing'),
	'section' => 'roof_water_proofing_services_section',
	'active_callback' => 'roof_water_proofing_is_service_section_enabled',
));