<?php
/**
 * Service Section options
 *
 * @package Theme Palace
 * @subpackage Kompany
 * @since Kompany 1.0.0
 */

// Add Service section
$wp_customize->add_section( 'kompany_service_section', array(
	'title'             => esc_html__( 'Services','kompany' ),
	'description'       => esc_html__( 'Services Section options.', 'kompany' ),
	'panel'             => 'kompany_front_page_panel',
) );

// Service content enable control and setting
$wp_customize->add_setting( 'kompany_theme_options[service_section_enable]', array(
	'default'			=> 	$options['service_section_enable'],
	'sanitize_callback' => 'kompany_sanitize_switch_control',
) );

$wp_customize->add_control( new Kompany_Switch_Control( $wp_customize, 'kompany_theme_options[service_section_enable]', array(
	'label'             => esc_html__( 'Service Section Enable', 'kompany' ),
	'section'           => 'kompany_service_section',
	'on_off_label' 		=> kompany_switch_options(),
) ) );

// service title setting and control
$wp_customize->add_setting( 'kompany_theme_options[service_title]',
	array(
		'default'       		=> $options['service_title'],
		'sanitize_callback'		=> 'sanitize_text_field',
		'transport'				=> 'postMessage',
	)
);
$wp_customize->add_control( 'kompany_theme_options[service_title]',
    array(
		'label'      			=> esc_html__( 'Section Title', 'kompany' ),
		'section'    			=> 'kompany_service_section',
		'type'		 			=> 'text',
		'active_callback'		=> 'kompany_is_service_section_enable',
    )
);

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'kompany_theme_options[service_title]', array(
		'selector'            => '#kompany_service_section h2.section-title',
		'settings'            => 'kompany_theme_options[service_title]',
		'container_inclusive' => false,
		'fallback_refresh'    => true,
		'render_callback'     => 'kompany_service_title_partial',
    ) );
}

for ( $i = 1; $i <= 2; $i++ ) :

	// service posts drop down chooser control and setting
	$wp_customize->add_setting( 'kompany_theme_options[service_content_post_' . $i . ']', array(
		'sanitize_callback' => 'kompany_sanitize_page',
	) );

	$wp_customize->add_control( new Kompany_Dropdown_Chooser( $wp_customize, 'kompany_theme_options[service_content_post_' . $i . ']', array(
		'label'             => sprintf( esc_html__( 'Select Post %d', 'kompany' ), $i ),
		'section'           => 'kompany_service_section',
		'choices'			=> kompany_post_choices(),
		'active_callback'	=> 'kompany_is_service_section_enable',
	) ) );

endfor;