<?php
/**
 * Banner Section
 *
 * @package Construktly
 */

$wp_customize->add_section(
	'construktly_banner_section',
	array(
		'panel' => 'construktly_front_page_options',
		'title' => esc_html__( 'Banner Slider Section', 'construktly' ),
	)
);

// Banner Section - Enable Section.
$wp_customize->add_setting(
	'construktly_enable_banner_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'construktly_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Construktly_Toggle_Switch_Custom_Control(
		$wp_customize,
		'construktly_enable_banner_section',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'construktly' ),
			'section'  => 'construktly_banner_section',
			'settings' => 'construktly_enable_banner_section',
		)
	)
);

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

// Banner Section - Content Type.
$wp_customize->add_setting(
	'construktly_banner_content',
	array(
		'default'           => 'page',
		'sanitize_callback' => 'construktly_sanitize_select',
	)
);

$wp_customize->add_control(
	'construktly_banner_content',
	array(
		'label'           => esc_html__( 'Select Content Type', 'construktly' ),
		'section'         => 'construktly_banner_section',
		'settings'        => 'construktly_banner_content',
		'type'            => 'select',
		'active_callback' => 'construktly_is_banner_section_enabled',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'construktly' ),
			'post' => esc_html__( 'Post', 'construktly' ),
		),
	)
);

// List out selected number of fields.
for ( $i = 1; $i <= 3; $i++ ) {

	// Banner Section - Content Type Post.
	$wp_customize->add_setting(
		'construktly_banner_content_post_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'construktly_banner_content_post_' . $i,
		array(
			/* translators: %d: count. */
			'label'           => sprintf( esc_html__( 'Select Post %d', 'construktly' ), $i ),
			'section'         => 'construktly_banner_section',
			'settings'        => 'construktly_banner_content_post_' . $i,
			'active_callback' => 'construktly_is_banner_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => construktly_get_post_choices(),
		)
	);

	// Banner Section - Content Type Page.
	$wp_customize->add_setting(
		'construktly_banner_content_page_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'construktly_banner_content_page_' . $i,
		array(
			/* translators: %d: count. */
			'label'           => sprintf( esc_html__( 'Select Page %d', 'construktly' ), $i ),
			'section'         => 'construktly_banner_section',
			'settings'        => 'construktly_banner_content_page_' . $i,
			'active_callback' => 'construktly_is_banner_section_and_content_type_page_enabled',
			'type'            => 'select',
			'choices'         => construktly_get_page_choices(),
		)
	);

	// Banner Section - Button Label.
	$wp_customize->add_setting(
		'construktly_banner_button_label' . $i,
		array(
			'default'           => __( 'Read More', 'construktly' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'construktly_banner_button_label' . $i,
		array(
			/* translators: %d: count. */
			'label'           => sprintf( esc_html__( 'Button Label %d', 'construktly' ), $i ),
			'section'         => 'construktly_banner_section',
			'settings'        => 'construktly_banner_button_label' . $i,
			'type'            => 'text',
			'active_callback' => 'construktly_is_banner_section_enabled',
		)
	);

	// Banner Section - Button Link.
	$wp_customize->add_setting(
		'construktly_banner_button_link' . $i,
		array(
			'default'           => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);

	$wp_customize->add_control(
		'construktly_banner_button_link' . $i,
		array(
			/* translators: %d: count. */
			'label'           => sprintf( esc_html__( 'Button Link %d', 'construktly' ), $i ),
			'section'         => 'construktly_banner_section',
			'settings'        => 'construktly_banner_button_link' . $i,
			'type'            => 'url',
			'active_callback' => 'construktly_is_banner_section_enabled',
		)
	);

}
