<?php
/**
 * Categories Section
 *
 * @package Zenith Blog
 */

$wp_customize->add_section(
	'zenith_blog_categories_section',
	array(
		'panel' => 'zenith_blog_front_page_options',
		'title' => esc_html__( 'Categories Section', 'zenith-blog' ),
	)
);

// Categories Section - Enable Section.
$wp_customize->add_setting(
	'zenith_blog_enable_categories_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'zenith_blog_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Zenith_Blog_Toggle_Switch_Custom_Control(
		$wp_customize,
		'zenith_blog_enable_categories_section',
		array(
			'label'    => esc_html__( 'Enable Categories Section', 'zenith-blog' ),
			'section'  => 'zenith_blog_categories_section',
			'settings' => 'zenith_blog_enable_categories_section',
			'priority' => 10,
		)
	)
);

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

// Categories Section - Section Title.
$wp_customize->add_setting(
	'zenith_blog_categories_title',
	array(
		'default'           => __( 'Categories', 'zenith-blog' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'zenith_blog_categories_title',
	array(
		'label'           => esc_html__( 'Section Title', 'zenith-blog' ),
		'section'         => 'zenith_blog_categories_section',
		'settings'        => 'zenith_blog_categories_title',
		'type'            => 'text',
		'active_callback' => 'zenith_blog_is_categories_section_enabled',
		'priority'        => 20,
	)
);

// Categories Section - Section Subtitle.
$wp_customize->add_setting(
	'zenith_blog_categories_subtitle',
	array(
		'default'           => '',
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'zenith_blog_categories_subtitle',
	array(
		'label'           => esc_html__( 'Section Subtitle', 'zenith-blog' ),
		'section'         => 'zenith_blog_categories_section',
		'settings'        => 'zenith_blog_categories_subtitle',
		'type'            => 'text',
		'active_callback' => 'zenith_blog_is_categories_section_enabled',
		'priority'        => 30,
	)
);

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

	// Categories Section - Select Category.
	$wp_customize->add_setting(
		'zenith_blog_categories_content_category_' . $i,
		array(
			'sanitize_callback' => 'zenith_blog_sanitize_select',
		)
	);

	$wp_customize->add_control(
		'zenith_blog_categories_content_category_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Category %d', 'zenith-blog' ), $i ),
			'section'         => 'zenith_blog_categories_section',
			'settings'        => 'zenith_blog_categories_content_category_' . $i,
			'active_callback' => 'zenith_blog_is_categories_section_enabled',
			'type'            => 'select',
			'choices'         => zenith_blog_get_post_cat_choices(),
			'priority'        => 40,
		)
	);

	// Categories Section - Category Image.
	$wp_customize->add_setting(
		'zenith_blog_category_category_image_' . $i,
		array(
			'sanitize_callback' => 'zenith_blog_sanitize_image',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Image_Control(
			$wp_customize,
			'zenith_blog_category_category_image_' . $i,
			array(
				'label'           => sprintf( esc_html__( 'Category Image %d', 'zenith-blog' ), $i ),
				'section'         => 'zenith_blog_categories_section',
				'settings'        => 'zenith_blog_category_category_image_' . $i,
				'active_callback' => 'zenith_blog_is_categories_section_enabled',
				'priority'        => 50,
			)
		)
	);

}
