<?php

/**
 * Sika Theme Customizer
 *
 * @package Sika
 */

/**
 * Add postMessage support for site title and description for the Theme Customizer.
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */

function sika_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' => 'sika_customize_partial_blogname',
			)
		);
		$wp_customize->selective_refresh->add_partial(
			'blogdescription',
			array(
				'selector'        => '.site-description',
				'render_callback' => 'sika_customize_partial_blogdescription',
			)
		);
	}

	/*
    * Theme Options Panel
    */
	$wp_customize->add_panel('sika_panel', array(
		'priority' => 25,
		'capability' => 'edit_theme_options',
		'title' => __('Sika Theme Options', 'sika'),
	));

	/*
	* Customizer top header section
	*/
	/*Top Header Options*/
	$wp_customize->add_section('sika_header_section', array(
		'priority'       => 5,
		'capability'     => 'edit_theme_options',
		'theme_supports' => '',
		'title'          => __('Top Header Options', 'sika'),
		'panel'       => 'sika_panel',
	));

	/*Top header section enable*/
	$wp_customize->add_setting(
		'sika_enable_top_header',
		array(
			'capability'        => 'edit_theme_options',
			'transport'         => 'refresh',
			'default'           => 1,
			'sanitize_callback' => 'sika_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		'sika_enable_top_header',
		array(
			'label'       => __('Enable Top Header', 'sika'),
			'description' => __('Checked to show the top header section.', 'sika'),
			'section'     => 'sika_header_section',
			'type'        => 'checkbox',
		)
	);

	/*Enable Menu at the top*/
	$wp_customize->add_setting(
		'sika_enable_top_menu',
		array(
			'capability'        => 'edit_theme_options',
			'transport'         => 'refresh',
			'default'           => 1,
			'sanitize_callback' => 'sika_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		'sika_enable_top_menu',
		array(
			'label'       => __('Enable Top Menu', 'sika'),
			'description' => __('Top menu will be enabled from here.', 'sika'),
			'section'     => 'sika_header_section',
			'type'        => 'checkbox',
		)
	);

	/*Enable Social Menu at the top*/
	$wp_customize->add_setting(
		'sika_enable_top_social_menu',
		array(
			'capability'        => 'edit_theme_options',
			'transport'         => 'refresh',
			'default'           => 1,
			'sanitize_callback' => 'sika_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		'sika_enable_top_social_menu',
		array(
			'label'       => __('Enable Top Social Menu', 'sika'),
			'description' => __('Checked to show the top social menu.', 'sika'),
			'section'     => 'sika_header_section',
			'type'        => 'checkbox',
		)
	);

	/*Enable Search Icon at the top*/
	$wp_customize->add_setting(
		'sika_enable_top_search_icon',
		array(
			'capability'        => 'edit_theme_options',
			'transport'         => 'refresh',
			'default'           => 1,
			'sanitize_callback' => 'sika_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		'sika_enable_top_search_icon',
		array(
			'label'       => __('Enable Top Search Section', 'sika'),
			'description' => __('Checked to show the Search icon.', 'sika'),
			'section'     => 'sika_header_section',
			'type'        => 'checkbox',
		)
	);

	/* Homepage Featured Post Slider Options*/
	$wp_customize->add_section('sika_slider_section', array(
		'priority'       => 5,
		'capability'     => 'edit_theme_options',
		'theme_supports' => '',
		'title'          => __('Featured Post Slider', 'sika'),
		'panel'       => 'sika_panel',
	));

	$wp_customize->add_setting(
		'sika_feat_slider_setting',
		array(
			'capability'        => 'edit_theme_options',
			'transport' => 'refresh',
			'default'           => 0,
			'sanitize_callback' => 'absint'
		)
	);

	$wp_customize->add_control(
		new Sika_Customize_Category_Dropdown_Control(
			$wp_customize,
			'sika_feat_slider_setting',
			array(
				'label'     => __('Select Category For Featured Slider Section', 'sika'),
				'description' => __('From the dropdown select the category for the featured slider section. Category having post will display in below dropdown.', 'sika'),
				'section'   => 'sika_slider_section',
				'settings'  => 'sika_feat_slider_setting',
				'type'      => 'category_dropdown',
				'priority'  => 10,
			)
		)
	);

	// /* Homepage Featured Post Grid Options*/
	$wp_customize->add_section('sika_post_grid_section', array(
		'priority'       => 5,
		'capability'     => 'edit_theme_options',
		'theme_supports' => '',
		'title'          => __('Featured Post Grid', 'sika'),
		'panel'       => 'sika_panel',
	));

	$wp_customize->add_setting(
		'sika_feat_post_grid_setting',
		array(
			'capability'        => 'edit_theme_options',
			'transport' => 'refresh',
			'default'           => 0,
			'sanitize_callback' => 'absint'
		)
	);

	$wp_customize->add_control(
		new Sika_Customize_Category_Dropdown_Control(
			$wp_customize,
			'sika_feat_post_grid_setting',
			array(
				'label'     => __('Select Category For Featured Grid Section', 'sika'),
				'description' => __('From the dropdown select the category for the featured grid section. Category having post will display in below dropdown.', 'sika'),
				'section'   => 'sika_post_grid_section',
				'settings'  => 'sika_feat_post_grid_setting',
				'type'      => 'category_dropdown',
				'priority'  => 10,
			)
		)
	);

	/*
	* Customizer Footer Section
	*/
	/*Footer Options*/
	$wp_customize->add_section('sika_footer_section', array(
		'priority'       => 5,
		'capability'     => 'edit_theme_options',
		'theme_supports' => '',
		'title'          => __('Footer Options', 'sika'),
		'panel'       => 'sika_panel',
	));


	/*Footer Social Menu Option*/
	$wp_customize->add_setting(
		'sika_footer_social_menu',
		array(
			'capability'        => 'edit_theme_options',
			'transport'         => 'refresh',
			'default'           => 1,
			'sanitize_callback' => 'sika_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		'sika_footer_social_menu',
		array(
			'label'       => __('Enable Footer Social Menu', 'sika'),
			'description' => __('Checked to show the Footer Social Menu.', 'sika'),
			'section'     => 'sika_footer_section',
			'type'        => 'checkbox',
		)
	);

	/*Footer Copyright Text Enable*/
	$wp_customize->add_setting(
		'sika_copyright_option',
		array(
			'capability'        => 'edit_theme_options',
			'transport'         => 'refresh',
			'default'           => '© Copyright 2025, All Rights Reserved By',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'sika_copyright_option',
		array(
			'label'       => __('Edit Copyright Text', 'sika'),
			'description' => __('Edit the Footer Copyright Section.', 'sika'),
			'section'     => 'sika_footer_section',
			'type'        => 'text',
		)
	);

	/*Go To Top Option*/
	$wp_customize->add_setting(
		'sika_enable_go_to_top_option',
		array(
			'capability'        => 'edit_theme_options',
			'transport'         => 'refresh',
			'default'           => 1,
			'sanitize_callback' => 'sika_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		'sika_enable_go_to_top_option',
		array(
			'label'       => __('Enable Go To Top', 'sika'),
			'description' => __('Checked to enable Go To Top option.', 'sika'),
			'section'     => 'sika_footer_section',
			'type'        => 'checkbox',
		)
	);

	/*Extra Options*/
	$wp_customize->add_section('sika_extra_section', array(
		'capability'     => 'edit_theme_options',
		'theme_supports' => '',
		'title'          => __('Extra Options', 'sika'),
		'panel'        => 'sika_panel',
	));

	/*Breadcrumb settings*/
	$wp_customize->add_setting(
		'sika_breadcrumb_options',
		array(
			'capability'        => 'edit_theme_options',
			'transport' => 'refresh',
			'default'           => 'disable',
			'sanitize_callback' => 'sika_sanitize_select'
		)
	);
	$wp_customize->add_control('sika_breadcrumb_options', array(
		'choices' => array(
			'disable'   => __('Disable Breadcrumb', 'sika'),
			'rank-math'   => __('Rank Math Breadcrumb', 'sika'),
			'yoast-seo'   => __('Yoast SEO Breadcrumb', 'sika'),
		),
		'label'     => __('Breadcrumb Option in Single and Blog Page', 'sika'),
		'description' => __('You can use any of the breadcrumb from the option. You need to install and activate Yoast or Rank Math plugin. ', 'sika'),
		'section'   => 'sika_extra_section',
		'settings'  => 'sika_breadcrumb_options',
		'type'      => 'select',
	));
}
add_action('customize_register', 'sika_customize_register');

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

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

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