<?php

/**
 * Adore Themes Customizer
 *
 * @package Nice Blog
 *
 * Banner Section
 */

$wp_customize->add_section(
	'nice_blog_banner_section',
	array(
		'title'    => esc_html__( 'Banner Section', 'nice-blog' ),
		'panel'    => 'nice_blog_frontpage_panel',
		'priority' => 10,
	)
);

// Banner enable setting.
$wp_customize->add_setting(
	'nice_blog_banner_section_enable',
	array(
		'default'           => false,
		'sanitize_callback' => 'nice_blog_sanitize_checkbox',
	)
);

$wp_customize->add_control(
	new Nice_Blog_Toggle_Checkbox_Custom_control(
		$wp_customize,
		'nice_blog_banner_section_enable',
		array(
			'label'    => esc_html__( 'Enable Banner Section', 'nice-blog' ),
			'type'     => 'checkbox',
			'settings' => 'nice_blog_banner_section_enable',
			'section'  => 'nice_blog_banner_section',
			'priority' => 10,
		)
	)
);

// Banner bg image.
$wp_customize->add_setting(
	'nice_blog_banner_bg_image',
	array(
		'default'           => '',
		'sanitize_callback' => 'nice_blog_sanitize_image',
	)
);

$wp_customize->add_control(
	new WP_Customize_Image_Control(
		$wp_customize,
		'nice_blog_banner_bg_image',
		array(
			'label'           => esc_html__( 'Background Image', 'nice-blog' ),
			'section'         => 'nice_blog_banner_section',
			'settings'        => 'nice_blog_banner_bg_image',
			'active_callback' => 'nice_blog_if_banner_enabled',
			'priority'        => 20,
		)
	)
);

// Banner title settings.
$wp_customize->add_setting(
	'nice_blog_banner_title',
	array(
		'default'           => __( 'Welcome to a world where curiosity is sparked with every line.', 'nice-blog' ),
		'sanitize_callback' => 'wp_kses_post',
	)
);

$wp_customize->add_control(
	'nice_blog_banner_title',
	array(
		'label'           => esc_html__( 'Section Title', 'nice-blog' ),
		'section'         => 'nice_blog_banner_section',
		'active_callback' => 'nice_blog_if_banner_enabled',
		'type'            => 'textarea',
		'priority'        => 30,
	)
);

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
	$wp_customize->selective_refresh->add_partial(
		'nice_blog_banner_title',
		array(
			'selector'            => '.banner-section h3.banner-title',
			'settings'            => 'nice_blog_banner_title',
			'container_inclusive' => false,
			'fallback_refresh'    => true,
		)
	);
}

// Banner featured meta title settings.
$wp_customize->add_setting(
	'nice_blog_banner_featured_meta_title',
	array(
		'default'           => __( '#Categories:', 'nice-blog' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'nice_blog_banner_featured_meta_title',
	array(
		'label'           => esc_html__( 'Featured Meta Title', 'nice-blog' ),
		'section'         => 'nice_blog_banner_section',
		'active_callback' => 'nice_blog_if_banner_enabled',
		'type'            => 'text',
		'priority'        => 40,
	)
);

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
	$wp_customize->selective_refresh->add_partial(
		'nice_blog_banner_featured_meta_title',
		array(
			'selector'            => '.banner-section .banner-tags-wrapper strong',
			'settings'            => 'nice_blog_banner_featured_meta_title',
			'container_inclusive' => false,
			'fallback_refresh'    => true,
		)
	);
}

/*========================Active Callback==============================*/
function nice_blog_if_banner_enabled( $control ) {
	return $control->manager->get_setting( 'nice_blog_banner_section_enable' )->value();
}
