<?php
/**
 * Pagination setting
 */

// Pagination setting.
$wp_customize->add_section(
	'nostalgic_blog_pagination',
	array(
		'title' => esc_html__( 'Pagination', 'nostalgic-blog' ),
		'panel' => 'nostalgic_blog_theme_options_panel',
	)
);

// Pagination enable setting.
$wp_customize->add_setting(
	'nostalgic_blog_pagination_enable',
	array(
		'default'           => true,
		'sanitize_callback' => 'nostalgic_blog_sanitize_checkbox',
	)
);

$wp_customize->add_control(
	new Nostalgic_Blog_Toggle_Checkbox_Custom_control(
		$wp_customize,
		'nostalgic_blog_pagination_enable',
		array(
			'label'    => esc_html__( 'Enable Pagination.', 'nostalgic-blog' ),
			'settings' => 'nostalgic_blog_pagination_enable',
			'section'  => 'nostalgic_blog_pagination',
			'type'     => 'checkbox',
		)
	)
);

// Pagination - Pagination Style.
$wp_customize->add_setting(
	'nostalgic_blog_pagination_type',
	array(
		'default'           => 'loadmore',
		'sanitize_callback' => 'nostalgic_blog_sanitize_select',
	)
);

$wp_customize->add_control(
	'nostalgic_blog_pagination_type',
	array(
		'label'           => esc_html__( 'Pagination Style', 'nostalgic-blog' ),
		'section'         => 'nostalgic_blog_pagination',
		'type'            => 'select',
		'choices'         => array(
			'default'  => __( 'Default (Older/Newer)', 'nostalgic-blog' ),
			'numeric'  => __( 'Numeric', 'nostalgic-blog' ),
			'loadmore' => __( 'Load More Button', 'nostalgic-blog' ),
		),
		'active_callback' => 'nostalgic_blog_pagination_enabled',
	)
);

// Loadmore text label.
$wp_customize->add_setting(
	'nostalgic_blog_loadmore_text_label',
	array(
		'default'           => __( 'Load More', 'nostalgic-blog' ),
		'sanitize_callback' => 'sanitize_text_field',
	)
);

$wp_customize->add_control(
	'nostalgic_blog_loadmore_text_label',
	array(
		'label'           => esc_html__( 'Load More Button Label', 'nostalgic-blog' ),
		'settings'        => 'nostalgic_blog_loadmore_text_label',
		'section'         => 'nostalgic_blog_pagination',
		'active_callback' => 'nostalgic_blog_loadmore_text_label_enabled',
	)
);

/*========================Active Callback==============================*/
function nostalgic_blog_pagination_enabled( $control ) {
	return $control->manager->get_setting( 'nostalgic_blog_pagination_enable' )->value();
}
function nostalgic_blog_loadmore_text_label_enabled( $control ) {
	$pagination = $control->manager->get_setting( 'nostalgic_blog_pagination_type' )->value();
	return nostalgic_blog_pagination_enabled( $control ) && ( 'loadmore' === $pagination );
}
