<?php

/**
 * Banner Section
 *
 * @package moving_truck_rental
 */

$wp_customize->add_section(
	'moving_truck_rental_banner_section',
	array(
		'panel'    => 'moving_truck_rental_front_page_options',
		'title'    => esc_html__( 'Banner Section', 'moving-truck-rental' ),
		'priority' => 10,
	)
);

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

$wp_customize->add_control(
	new Moving_Truck_Rental_Toggle_Switch_Custom_Control(
		$wp_customize,
		'moving_truck_rental_enable_banner_section',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'moving-truck-rental' ),
			'section'  => 'moving_truck_rental_banner_section',
			'settings' => 'moving_truck_rental_enable_banner_section',
		)
	)
);

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

// Banner Section - Banner Slider Content Type.
$wp_customize->add_setting(
	'moving_truck_rental_banner_slider_content_type',
	array(
		'default'           => 'post',
		'sanitize_callback' => 'moving_truck_rental_sanitize_select',
	)
);

$wp_customize->add_control(
	'moving_truck_rental_banner_slider_content_type',
	array(
		'label'           => esc_html__( 'Select Banner Slider Content Type', 'moving-truck-rental' ),
		'section'         => 'moving_truck_rental_banner_section',
		'settings'        => 'moving_truck_rental_banner_slider_content_type',
		'type'            => 'select',
		'active_callback' => 'moving_truck_rental_is_banner_slider_section_enabled',
		'choices'         => array(
			'page' => esc_html__( 'Page', 'moving-truck-rental' ),
			'post' => esc_html__( 'Post', 'moving-truck-rental' ),
		),
	)
);

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

	// Banner Section - Select Banner Post.
	$wp_customize->add_setting(
		'moving_truck_rental_banner_slider_content_post_' . $moving_truck_rental_i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'moving_truck_rental_banner_slider_content_post_' . $moving_truck_rental_i,
		array(
			/* translators: %d: Posts Count. */
			'label'           => sprintf( esc_html__( 'Select Post %d', 'moving-truck-rental' ), $moving_truck_rental_i ),
			'section'         => 'moving_truck_rental_banner_section',
			'settings'        => 'moving_truck_rental_banner_slider_content_post_' . $moving_truck_rental_i,
			'active_callback' => 'moving_truck_rental_is_banner_slider_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => moving_truck_rental_get_post_choices(),
		)
	);

	// Banner Section - Select Banner Page.
	$wp_customize->add_setting(
		'moving_truck_rental_banner_slider_content_page_' . $moving_truck_rental_i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'moving_truck_rental_banner_slider_content_page_' . $moving_truck_rental_i,
		array(
			/* translators: %d: Pages Count. */
			'label'           => sprintf( esc_html__( 'Select Page %d', 'moving-truck-rental' ), $moving_truck_rental_i ),
			'section'         => 'moving_truck_rental_banner_section',
			'settings'        => 'moving_truck_rental_banner_slider_content_page_' . $moving_truck_rental_i,
			'active_callback' => 'moving_truck_rental_is_banner_slider_section_and_content_type_page_enabled',
			'type'            => 'select',
			'choices'         => moving_truck_rental_get_page_choices(),
		)
	);

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

	$wp_customize->add_control(
		'moving_truck_rental_banner_button_label_' . $moving_truck_rental_i,
		array(
			/* translators: %d: Button Label. */
			'label'           => sprintf( esc_html__( 'Button Label 1', 'moving-truck-rental' )),
			'section'         => 'moving_truck_rental_banner_section',
			'settings'        => 'moving_truck_rental_banner_button_label_' . $moving_truck_rental_i,
			'type'            => 'text',
			'active_callback' => 'moving_truck_rental_is_banner_slider_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		'moving_truck_rental_banner_button_link_' . $moving_truck_rental_i,
		array(
			/* translators: %d: Button Link Count. */
			'label'           => sprintf( esc_html__( 'Button Link 1', 'moving-truck-rental' )  ),
			'section'         => 'moving_truck_rental_banner_section',
			'settings'        => 'moving_truck_rental_banner_button_link_' . $moving_truck_rental_i,
			'type'            => 'url',
			'active_callback' => 'moving_truck_rental_is_banner_slider_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		'moving_truck_rental_banner_button_label_1' . $moving_truck_rental_i,
		array(
			'label'           => sprintf( esc_html__( 'Button Label 2', 'moving-truck-rental' ) ),
			'section'         => 'moving_truck_rental_banner_section',
			'settings'        => 'moving_truck_rental_banner_button_label_1' . $moving_truck_rental_i,
			'type'            => 'text',
			'active_callback' => 'moving_truck_rental_is_banner_slider_section_enabled',
		)
	);

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

	$wp_customize->add_control(
		'moving_truck_rental_banner_button_link_1' . $moving_truck_rental_i,
		array(
			'label'           => sprintf( esc_html__( 'Button Link 2', 'moving-truck-rental' ) ),
			'section'         => 'moving_truck_rental_banner_section',
			'settings'        => 'moving_truck_rental_banner_button_link_1' . $moving_truck_rental_i,
			'type'            => 'url',
			'active_callback' => 'moving_truck_rental_is_banner_slider_section_enabled',
		)
	);
}
