<?php
/**
 * freshaura Theme Customizer
 *
 * @package freshaura
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function freshaura_customize_register( $wp_customize ) {
	$wp_customize->get_setting( 'blogname' )->transport         = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport  = 'postMessage';
	$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage';

	if ( isset( $wp_customize->selective_refresh ) ) {
		$wp_customize->selective_refresh->add_partial(
			'blogname',
			array(
				'selector'        => '.site-title a',
				'render_callback' => 'freshaura_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'freshaura_customize_partial_blogdescription',
			)
		);

		// adding copyright section to the customizer 

		$wp_customize->add_section('freshaura_footer_section', array(
			'title'    => __('Footer Settings', 'freshaura'),
			'priority' => 130,
		));
	
		// Add a setting for the footer copyright text
		$wp_customize->add_setting('freshaura_footer_copyright', array(
			'default'           => '',
			'sanitize_callback' => 'sanitize_text_field',
		));
	
		// Add a control for the footer copyright text
		$wp_customize->add_control('freshaura_footer_copyright', array(
			'label'    => __('Copyright Text', 'freshaura'),
			'section'  => 'freshaura_footer_section',
			'type'     => 'text',
		));

			// adding copyright section to the customizer 

			$wp_customize->add_section('freshaura_layout_section', array(
				'title'    => __('Layout Settings', 'freshaura'),
				'priority' => 30,
			));
		
			$wp_customize->add_setting('freshaura_sidebar_set', array(
				'default'           => '', // default to empty (no sidebar)
				'sanitize_callback' => 'sanitize_text_field',
			));
		
			$wp_customize->add_control('freshaura_sidebar_set', array(
				'label'   => __('Sidebar Position', 'freshaura'),
				'section' => 'freshaura_layout_section',
				'type'    => 'select',
				'choices' => array(
					''      => __('No Sidebar', 'freshaura'),
					'left'  => __('Left Sidebar', 'freshaura'),
					'right' => __('Right Sidebar', 'freshaura'),
				),
			));
			

			// blog Layout type

			$wp_customize->add_section('freshaura_layout_sec', array(
				'title'       => __('Blog Layout', 'freshaura'),
				'description' => __('Choose your preferred blog layout.', 'freshaura'),
			));
		
			// Add a setting to store the selected layout
			$wp_customize->add_setting('freshaura_layout_set', array(
				'default'           => 'classic', // Default layout option
				'type'              => 'theme_mod',
				'sanitize_callback' => 'sanitize_key', // Sanitize the input
			));
		
			// Add a control to select between 'Classic' and 'Grid' layouts
			$wp_customize->add_control('freshaura_ctrl_layout', array(
				'label'    => __('Select Layout', 'freshaura'),
				'section'  => 'freshaura_layout_sec',
				'settings' => 'freshaura_layout_set',
				'type'     => 'radio',
				'choices'  => array(
					'classic' => __('Classic', 'freshaura'),
					'grid'    => __('Grid', 'freshaura'),
				),
			));
		}
	}
	add_action( 'customize_register', 'freshaura_customize_register' );



/**
 * Render the site title for the selective refresh partial.
 *
 * @return void
 */
function freshaura_customize_partial_blogname() {
	bloginfo( 'name' );
}


/**
 * Render the site tagline for the selective refresh partial.
 *
 * @return void
 */
function freshaura_customize_partial_blogdescription() {
	bloginfo( 'description' );
}

/**
 * Binds JS handlers to make Theme Customizer preview reload changes asynchronously.
 */
function freshaura_customize_preview_js() {
	wp_enqueue_script( 'freshaura-customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), _S_VERSION, true );
}
add_action( 'customize_preview_init', 'freshaura_customize_preview_js' );

