<?php

/**
 * Service Section
 *
 * @package dark_fitness
 */

$wp_customize->add_section(
	'dark_fitness_service_section',
	array(
		'panel'    => 'dark_fitness_front_page_options',
		'title'    => esc_html__( 'Service Section', 'dark-fitness' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Dark_Fitness_Toggle_Switch_Custom_Control(
		$wp_customize,
		'dark_fitness_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Service Section', 'dark-fitness' ),
			'section'  => 'dark_fitness_service_section',
			'settings' => 'dark_fitness_enable_service_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'dark_fitness_service_button_label',
	array(
		'label'           => esc_html__( 'Button Label', 'dark-fitness' ),
		'section'         => 'dark_fitness_service_section',
		'settings'        => 'dark_fitness_service_button_label',
		'type'            => 'text',
		'active_callback' => 'dark_fitness_is_service_section_enabled',
	)
);


// Banner Section - Services Content Type.
$wp_customize->add_setting(
	'dark_fitness_service_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'dark_fitness_sanitize_select',
	)
);

$wp_customize->add_control(
	'dark_fitness_service_content_type',
	array(
		'label'           => esc_html__( 'Select Services Content Type', 'dark-fitness' ),
		'section'         => 'dark_fitness_service_section',
		'settings'        => 'dark_fitness_service_content_type',
		'type'            => 'select',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'dark-fitness' ),
			'post' => esc_html__( 'Post', 'dark-fitness' ),
		),
	)
);

// Services Category Setting.
$wp_customize->add_setting('dark_fitness_services_category', array(
	'default'           => 'services',
	'sanitize_callback' => 'sanitize_text_field',
));

// Add custom control for Services Category with conditional visibility.
$wp_customize->add_control(new Dark_Fitness_Customize_Category_Dropdown_Control($wp_customize, 'dark_fitness_services_category', array(
	'label'    => __('Select Services Category', 'dark-fitness'),
	'section'  => 'dark_fitness_service_section',
	'settings' => 'dark_fitness_services_category',
	'active_callback' => function() use ($wp_customize) {
		return $wp_customize->get_setting('dark_fitness_service_content_type')->value() === 'post';
	},
)));




for ( $dark_fitness_i = 1; $dark_fitness_i <= 3; $dark_fitness_i++ ) {

	// Service Section - Services Icons.
	$wp_customize->add_setting(
		'dark_fitness_service_icon_' . $dark_fitness_i,
		array(
			'sanitize_callback' => 'dark_fitness_sanitize_image',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Image_Control(
			$wp_customize,
			'dark_fitness_service_icon_' . $dark_fitness_i,
			array(
				/* translators: %d: Service Image Count. */
				'label'           => sprintf( esc_html__( 'Service Image %d', 'dark-fitness' ), $dark_fitness_i ),
				'section'         => 'dark_fitness_service_section',
				'settings'        => 'dark_fitness_service_icon_' . $dark_fitness_i,
				'active_callback' => 'dark_fitness_is_service_section_enabled',
			)
		)
	);

	// Service Section - Select Post.
	$wp_customize->add_setting(
		'dark_fitness_service_content_post_' . $dark_fitness_i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'dark_fitness_service_content_post_' . $dark_fitness_i,
		array(
			'label'           => esc_html__( 'Select Post ', 'dark-fitness' ) . $dark_fitness_i,
			'description'     => sprintf( esc_html__( 'Kindly :- Select a Post based on the category selected in the upper settings', 'dark-fitness' ), $dark_fitness_i ),
			'section'         => 'dark_fitness_service_section',
			'settings'        => 'dark_fitness_service_content_post_' . $dark_fitness_i,
			'active_callback' => 'dark_fitness_is_service_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => dark_fitness_get_post_choices(),
		)
	);

	// Service Section - Select Page.
	$wp_customize->add_setting(
		'dark_fitness_service_content_page_' . $dark_fitness_i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'dark_fitness_service_content_page_' . $dark_fitness_i,
		array(
			'label'           => esc_html__( 'Select Page ', 'dark-fitness' ) . $dark_fitness_i,
			'section'         => 'dark_fitness_service_section',
			'settings'        => 'dark_fitness_service_content_page_' . $dark_fitness_i,
			'active_callback' => 'dark_fitness_is_service_section_and_content_type_page_enabled',
			'type'            => 'select',
			'choices'         => dark_fitness_get_page_choices(),
		)
	);
}


// icon // 
$wp_customize->add_setting(
	'dark_fitness_service_icon',
	array(
        'default' => 'fa fa-dumbbell',
		'sanitize_callback' => 'sanitize_text_field',
		'capability' => 'edit_theme_options',
		
	)
);	

$wp_customize->add_control(new Dark_Fitness_Change_Icon_Control($wp_customize, 
	'dark_fitness_service_icon',
	array(
	    'label'   		=> __('Service  Icon','dark-fitness'),
	    'section' 		=> 'dark_fitness_service_section',
		'iconset' => 'fa',
		'active_callback' => 'dark_fitness_is_service_section_enabled',
	))  
);