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

$wp_customize->add_section(
	'mindful_blog_categories_section',
	array(
		'panel' => 'mindful_blog_front_page_options',
		'title' => esc_html__( 'Categories Section', 'mindful-blog' ),
	)
);

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

$wp_customize->add_control(
	new Mindful_Blog_Toggle_Switch_Custom_Control(
		$wp_customize,
		'mindful_blog_enable_categories_section',
		array(
			'label'    => esc_html__( 'Enable Categories Section', 'mindful-blog' ),
			'section'  => 'mindful_blog_categories_section',
			'settings' => 'mindful_blog_enable_categories_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'mindful_blog_categories_title',
	array(
		'label'           => esc_html__( 'Section Title', 'mindful-blog' ),
		'section'         => 'mindful_blog_categories_section',
		'settings'        => 'mindful_blog_categories_title',
		'type'            => 'text',
		'active_callback' => 'mindful_blog_is_categories_section_enabled',
	)
);

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

	// Categories Section - Select Category.
	$wp_customize->add_setting(
		'mindful_blog_categories_content_category_' . $mindful_blog_i,
		array(
			'sanitize_callback' => 'mindful_blog_sanitize_select',
		)
	);

	$wp_customize->add_control(
		'mindful_blog_categories_content_category_' . $mindful_blog_i,
		array(
			'label'           => sprintf( esc_html__( 'Select Category %d', 'mindful-blog' ), $mindful_blog_i ),
			'section'         => 'mindful_blog_categories_section',
			'settings'        => 'mindful_blog_categories_content_category_' . $mindful_blog_i,
			'active_callback' => 'mindful_blog_is_categories_section_enabled',
			'type'            => 'select',
			'choices'         => mindful_blog_get_post_cat_choices(),
		)
	);

	// Categories Section - Category Image.
	$wp_customize->add_setting(
		'mindful_blog_category_category_image_' . $mindful_blog_i,
		array(
			'sanitize_callback' => 'mindful_blog_sanitize_image',
		)
	);

	$wp_customize->add_control(
		new WP_Customize_Image_Control(
			$wp_customize,
			'mindful_blog_category_category_image_' . $mindful_blog_i,
			array(
				'label'           => sprintf( esc_html__( 'Category Image %d', 'mindful-blog' ), $mindful_blog_i ),
				'section'         => 'mindful_blog_categories_section',
				'settings'        => 'mindful_blog_category_category_image_' . $mindful_blog_i,
				'active_callback' => 'mindful_blog_is_categories_section_enabled',
			)
		)
	);

	// Categories Section - Horizontal Line.
	$wp_customize->add_setting(
		'mindful_blog_categories_horizontal_line_' . $mindful_blog_i,
		array(
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		new Mindful_Blog_Customize_Horizontal_Line(
			$wp_customize,
			'mindful_blog_categories_horizontal_line_' . $mindful_blog_i,
			array(
				'section'         => 'mindful_blog_categories_section',
				'settings'        => 'mindful_blog_categories_horizontal_line_' . $mindful_blog_i,
				'active_callback' => 'mindful_blog_is_categories_section_enabled',
				'type'            => 'hr',
			)
		)
	);

}
