<?php

/**
 * Service Section
 *
 * @package social_blog
 */

$wp_customize->add_section(
	'social_blog_service_section',
	array(
		'panel'    => 'social_blog_front_page_options',
		'title'    => esc_html__( 'Trending Video Section', 'social-blog' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Social_Blog_Toggle_Switch_Custom_Control(
		$wp_customize,
		'social_blog_enable_service_section',
		array(
			'label'    => esc_html__( 'Enable Trending Video Section', 'social-blog' ),
			'section'  => 'social_blog_service_section',
			'settings' => 'social_blog_enable_service_section',
		)
	)
);

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

// Popular Video Section - Title.
$wp_customize->add_setting(
	'social_blog_video_section_title',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'social_blog_video_section_title',
	array(
		'label'           => esc_html__( 'Section Title', 'social-blog' ),
		'section'         => 'social_blog_service_section',
		'settings'        => 'social_blog_video_section_title',
		'type'            => 'text',
		'active_callback' => 'social_blog_is_service_section_enabled',
	)
);

// Popular Video Section - Text.
$wp_customize->add_setting(
	'social_blog_video_section_text',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'social_blog_video_section_text',
	array(
		'label'           => esc_html__( 'Section Text', 'social-blog' ),
		'section'         => 'social_blog_service_section',
		'settings'        => 'social_blog_video_section_text',
		'type'            => 'text',
		'active_callback' => 'social_blog_is_service_section_enabled',
	)
);


// Popular Video Section - Content Type.
$wp_customize->add_setting(
	'social_blog_service_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'social_blog_sanitize_select',
	)
);

$wp_customize->add_control(
	'social_blog_service_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'social-blog' ),
		'section'         => 'social_blog_service_section',
		'settings'        => 'social_blog_service_content_type',
		'type'            => 'select',
		'active_callback' => 'social_blog_is_service_section_enabled',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'social-blog' ),
			'post' => esc_html__( 'Post', 'social-blog' ),
		),
	)
);

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

// Add custom control for Services Category with conditional visibility.
$wp_customize->add_control(new Social_Blog_Customize_Category_Dropdown_Control($wp_customize, 'social_blog_services_category', array(
	'label'    => __('Select Services Category', 'social-blog'),
	'section'  => 'social_blog_service_section',
	'settings' => 'social_blog_services_category',
	'active_callback' => function() use ($wp_customize) {
		return $wp_customize->get_setting('social_blog_service_content_type')->value() === 'post';
	},
)));

for ( $social_blog_i = 1; $social_blog_i <= 4; $social_blog_i++ ) {

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

	$wp_customize->add_control(
		'social_blog_service_content_post_' . $social_blog_i,
		array(
			'label'           => esc_html__( 'Select Post ', 'social-blog' ) . $social_blog_i,
			'description'     => sprintf( esc_html__( 'Kindly :- Select a Post based on the category selected in the upper settings', 'social-blog' ), $social_blog_i ),
			'section'         => 'social_blog_service_section',
			'settings'        => 'social_blog_service_content_post_' . $social_blog_i,
			'active_callback' => 'social_blog_is_service_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => social_blog_get_post_choices(),
		)
	);

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

	$wp_customize->add_control(
		'social_blog_service_content_page_' . $social_blog_i,
		array(
			'label'           => esc_html__( 'Select Page ', 'social-blog' ) . $social_blog_i,
			'section'         => 'social_blog_service_section',
			'settings'        => 'social_blog_service_content_page_' . $social_blog_i,
			'active_callback' => 'social_blog_is_service_section_and_content_type_page_enabled',
			'type'            => 'select',
			'choices'         => social_blog_get_page_choices(),
		)
	);
}
// Service Video Section - Enable Section.
$wp_customize->add_setting(
	'social_blog_enable_service_video_section',
	array(
		'default'           => true,
		'sanitize_callback' => 'social_blog_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Social_Blog_Toggle_Switch_Custom_Control(
		$wp_customize,
		'social_blog_enable_service_video_section',
		array(
			'label'    => esc_html__( 'Enable Video Icon Setting', 'social-blog' ),
			'section'  => 'social_blog_service_section',
			'settings' => 'social_blog_enable_service_video_section',
		)
	)
);