<?php

/**
 * Blog Section
 *
 * @package Charity_Elite
 */

$wp_customize->add_section(
	'charity_elite_blog_section',
	array(
		'panel'    => 'charity_elite_front_page_options',
		'title'    => esc_html__( 'Blog Section', 'charity-elite' ),
		'priority' => 80,
	)
);

// Blog Section - Enable Section.
$wp_customize->add_setting(
	'charity_elite_enable_blog_section',
	array(
		'default'           => false,
		'sanitize_callback' => 'charity_elite_sanitize_switch',
	)
);

$wp_customize->add_control(
	new Charity_Elite_Toggle_Switch_Custom_Control(
		$wp_customize,
		'charity_elite_enable_blog_section',
		array(
			'label'    => esc_html__( 'Enable Blog Section', 'charity-elite' ),
			'section'  => 'charity_elite_blog_section',
			'settings' => 'charity_elite_enable_blog_section',
		)
	)
);

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

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

$wp_customize->add_control(
	'charity_elite_blog_subtitle',
	array(
		'label'           => esc_html__( 'Section Subtitle', 'charity-elite' ),
		'section'         => 'charity_elite_blog_section',
		'settings'        => 'charity_elite_blog_subtitle',
		'type'            => 'text',
		'active_callback' => 'charity_elite_is_blog_section_enabled',
	)
);

// Blog Section - Section Title.
$wp_customize->add_setting(
	'charity_elite_blog_title',
	array(
		'default'           => __( 'News and Articles', 'charity-elite' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'charity_elite_blog_title',
	array(
		'label'           => esc_html__( 'Section Title', 'charity-elite' ),
		'section'         => 'charity_elite_blog_section',
		'settings'        => 'charity_elite_blog_title',
		'type'            => 'text',
		'active_callback' => 'charity_elite_is_blog_section_enabled',
	)
);

// Blog Section - Content Type.
$wp_customize->add_setting(
	'charity_elite_blog_content_type',
	array(
		'default'           => 'category',
		'sanitize_callback' => 'charity_elite_sanitize_select',
	)
);

$wp_customize->add_control(
	'charity_elite_blog_content_type',
	array(
		'label'           => esc_html__( 'Select Content Type', 'charity-elite' ),
		'section'         => 'charity_elite_blog_section',
		'settings'        => 'charity_elite_blog_content_type',
		'type'            => 'select',
		'active_callback' => 'charity_elite_is_blog_section_enabled',
		'choices'         => array(
			'post'     => esc_html__( 'Post', 'charity-elite' ),
			'category' => esc_html__( 'Category', 'charity-elite' ),
		),
	)
);

for ( $i = 1; $i <= 3; $i++ ) {
	// Blog Section - Select Post.
	$wp_customize->add_setting(
		'charity_elite_blog_content_post_' . $i,
		array(
			'sanitize_callback' => 'absint',
		)
	);

	$wp_customize->add_control(
		'charity_elite_blog_content_post_' . $i,
		array(
			'label'           => sprintf( esc_html__( 'Select Post %d', 'charity-elite' ), $i ),
			'section'         => 'charity_elite_blog_section',
			'settings'        => 'charity_elite_blog_content_post_' . $i,
			'active_callback' => 'charity_elite_is_blog_section_and_content_type_post_enabled',
			'type'            => 'select',
			'choices'         => charity_elite_get_post_choices(),
		)
	);

}

// Blog Section - Select Category.
$wp_customize->add_setting(
	'charity_elite_blog_content_category',
	array(
		'sanitize_callback' => 'charity_elite_sanitize_select',
	)
);

$wp_customize->add_control(
	'charity_elite_blog_content_category',
	array(
		'label'           => esc_html__( 'Select Category', 'charity-elite' ),
		'section'         => 'charity_elite_blog_section',
		'settings'        => 'charity_elite_blog_content_category',
		'active_callback' => 'charity_elite_is_blog_section_and_content_type_category_enabled',
		'type'            => 'select',
		'choices'         => charity_elite_get_post_cat_choices(),
	)
);

// Blog Section - Button Label.
$wp_customize->add_setting(
	'charity_elite_blog_button_label',
	array(
		'default'           => __( 'Read More', 'charity-elite' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'charity_elite_blog_button_label',
	array(
		'label'           => esc_html__( 'Button Label', 'charity-elite' ),
		'section'         => 'charity_elite_blog_section',
		'settings'        => 'charity_elite_blog_button_label',
		'type'            => 'text',
		'active_callback' => 'charity_elite_is_blog_section_enabled',
	)
);
