<?php

/**
 * Blog Customizer Settings
 * @package Glaciers
 * @since 1.0.0
 */

if (!defined('ABSPATH')) {
	exit; // Exit if accessed directly.
}

if (!function_exists('glaciers_customize_register_blog')) :
	function glaciers_customize_register_blog($wp_customize)
	{

		/** Blog Options */
		$wp_customize->add_section(
			'glaciers_blog_options',
			array(
				'title'    => esc_html__('Blog Options', 'glaciers'),
				'priority' => 22,
			)
		);

		// Heading - blog excerpts
		$wp_customize->add_control(new Glaciers_Note_Control(
			$wp_customize,
			'glaciers_blog_excerpts_note',
			array(
				'label' => esc_html__('Blog Excerpts', 'glaciers'),
				'section' => 'glaciers_blog_options',
				'priority' => 2,
				'settings' => array(),
			)
		));

		/** Blog Excerpt */
		$wp_customize->add_setting(
			'glaciers_blog_excerpt',
			array(
				'default'  => true,
				'sanitize_callback' => 'glaciers_sanitize_checkbox',
			)
		);

		$wp_customize->add_control(
			new Glaciers_Toggle_Control(
				$wp_customize,
				'glaciers_blog_excerpt',
				array(
					'section'     => 'glaciers_blog_options',
					'priority' => 2,
					'label'	      => esc_html__('Enable Blog Excerpts', 'glaciers'),
					'description' => esc_html__('Enable to show excerpts or disable to show full post content.', 'glaciers'),
				)
			)
		);

		/** Excerpt Length */
		$wp_customize->add_setting(
			'glaciers_excerpt_length',
			array(
				'default' => 35,
				'sanitize_callback' => 'glaciers_sanitize_number_absint',
			)
		);

		$wp_customize->add_control(
			new Glaciers_Slider_Control(
				$wp_customize,
				'glaciers_excerpt_length',
				array(
					'section' => 'glaciers_blog_options',
					'priority' => 3,
					'label' => esc_html__('Excerpt Length', 'glaciers'),
					'description' => esc_html__('Automatically generated excerpt length (in words).', 'glaciers'),
					'choices' => array(
						'min' => 10,
						'max' => 100,
						'step' => 5,
					)
				)
			)
		);


		// Add Partial for Blog Layout and Excerpt Length.
		$wp_customize->selective_refresh->add_partial('glaciers_blog_content_partial', array(
			'selector' => '.site-main',
			'settings' => array(
				'glaciers_blog_layout',
				'glaciers_blog_excerpt',
				'glaciers_excerpt_length',
			),
			'render_callback'  => 'glaciers_customize_partial_blog_content',
			'fallback_refresh' => false,
		));
	}
endif;

add_action('customize_register', 'glaciers_customize_register_blog');
