<?php
/**
 * Archive options
 *
 * @package Theme Palace
 * @subpackage  Charity Give
 * @since  Charity Give 1.0.0
 */

// Add archive section
$wp_customize->add_section( 'charity_give_archive_section',
	array(
		'title'             => esc_html__( 'Blog/Archive','charity-give' ),
		'description'       => esc_html__( 'Archive section options.', 'charity-give' ),
		'panel'             => 'charity_give_theme_options_panel',
	)
);

// Your latest posts title setting and control.
$wp_customize->add_setting( 'charity_give_theme_options[your_latest_posts_title]',
	array(
		'default'           => $options['your_latest_posts_title'],
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control( 'charity_give_theme_options[your_latest_posts_title]',
	array(
		'label'             => esc_html__( 'Your Latest Posts Title', 'charity-give' ),
		'description'       => esc_html__( 'This option only works if Static Front Page is set to "Your latest posts."', 'charity-give' ),
		'section'           => 'charity_give_archive_section',
		'type'				=> 'text',
		'active_callback'	=> function( $control ) {
			return !(
				charity_give_is_static_homepage_enable( $control )
			);
		}
	)
);

$wp_customize->add_setting( 'charity_give_theme_options[hide_archive_post_image]', array(
	'default'           => $options['hide_archive_post_image'],
	'sanitize_callback' => 'charity_give_sanitize_switch_control',
) );

$wp_customize->add_control( new Charity_Give_Switch_Control( $wp_customize, 'charity_give_theme_options[hide_archive_post_image]', array(
	'label'             => esc_html__( 'Hide Post Image', 'charity-give' ),
	'section'           => 'charity_give_archive_section',
	'on_off_label' 		=> charity_give_hide_options(),
) ) );

// Archive category setting and control.
$wp_customize->add_setting( 'charity_give_theme_options[hide_archive_title]', array(
	'default'           => $options['hide_archive_title'],
	'sanitize_callback' => 'charity_give_sanitize_switch_control',
) );

$wp_customize->add_control( new Charity_Give_Switch_Control( $wp_customize, 'charity_give_theme_options[hide_archive_title]', array(
	'label'             => esc_html__( 'Hide Post Title', 'charity-give' ),
	'section'           => 'charity_give_archive_section',
	'on_off_label' 		=> charity_give_hide_options(),
) ) );

// Archive category setting and control.
$wp_customize->add_setting( 'charity_give_theme_options[hide_archive_date]', array(
	'default'           => $options['hide_archive_date'],
	'sanitize_callback' => 'charity_give_sanitize_switch_control',
) );

$wp_customize->add_control( new Charity_Give_Switch_Control( $wp_customize, 'charity_give_theme_options[hide_archive_date]', array(
	'label'             => esc_html__( 'Hide Post Date', 'charity-give' ),
	'section'           => 'charity_give_archive_section',
	'on_off_label' 		=> charity_give_hide_options(),
) ) );

// Archive category setting and control.
$wp_customize->add_setting( 'charity_give_theme_options[hide_archive_content]', array(
	'default'           => $options['hide_archive_content'],
	'sanitize_callback' => 'charity_give_sanitize_switch_control',
) );

$wp_customize->add_control( new Charity_Give_Switch_Control( $wp_customize, 'charity_give_theme_options[hide_archive_content]', array(
	'label'             => esc_html__( 'Hide Post Content', 'charity-give' ),
	'section'           => 'charity_give_archive_section',
	'on_off_label' 		=> charity_give_hide_options(),
) ) );

//archive_btn_txt
$wp_customize->add_setting('charity_give_theme_options[archive_btn_txt]',
    array(
        'sanitize_callback' => 'sanitize_text_field',
        'transport'			=> 'postMessage',
        'default'           => $options['archive_btn_txt'],
    )
);

$wp_customize->add_control('charity_give_theme_options[archive_btn_txt]',
    array(
        'section'			=> 'charity_give_archive_section',
        'label'				=> esc_html__( 'Button Text:', 'charity-give' ),
        'type'          	=>'text',
    )
);

// Abort if selective refresh is not available.
if ( isset( $wp_customize->selective_refresh ) ) {
    $wp_customize->selective_refresh->add_partial( 'charity_give_theme_options[archive_btn_txt]',
		array(
			'selector'            => '#inner-content-wrapper .archive-blog-wrapper div.read-more a',
			'settings'            => 'charity_give_theme_options[archive_btn_txt]',
			'fallback_refresh'    => true,
			'container_inclusive' => false,
			'render_callback'     => 'charity_give_archive_btn_txt_partial',
		) 
	);
}