<?php
/**
 * Theme Customizer Class
 *
 * @package Wira
 * @since 1.0.0
 */

namespace Wira;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! class_exists( 'Customizer' ) ) {

	class Customizer {

		/**
		 * Constructor.
		 *
		 * Registers hooks.
		 *
		 * @since 1.0.0
		 */
		public function __construct() {
			$this->load_hooks();
		}

		/**
		 * Register hooks
		 *
		 * @since 1.0.0
		 * @return void
		 */
		private function load_hooks() {
			add_action( 'customize_register', array( $this, 'register_customizer' ) );
			add_action( 'customize_controls_print_styles', array( $this, 'toggle_css' ) );
		}

		/**
		 * Register Customizer
		 */
		public function register_customizer( $wp_customize ) {

			// Control Toggle Class
			if ( ! class_exists( '\Wira\Toggle_Control' ) ) {
				require_once WIRA_DIR . '/inc/class/customizer/class-toggle-control.php';
			}
			// Alpha Color Control
			if ( ! class_exists( '\Wira\Alpha_Color_Control' ) ) {
				require_once WIRA_DIR . '/inc/class/customizer/class-alpha-color-control.php';
			}

			// === Panel ===
			$wp_customize->add_panel(
				'wira_panel',
				array(
					'title'    => __( 'Wira Customizer', 'wira' ),
					'priority' => 10,
				)
			);

			$wp_customize->add_section(
				'wira_theme_color',
				array(
					'title'    => __( 'Theme Color', 'wira' ),
					'priority' => 10,
					'panel'    => 'wira_panel',
				)
			);

			$colors = array(
				array(
					'id'      => 'wira_color_primary',
					'default' => '#F98400',
				),
				array(
					'id'      => 'wira_color_secondary',
					'default' => '#1090D2',
				),
				array(
					'id'      => 'wira_color_secondary20',
					'default' => '#1090D233',
				),
				array(
					'id'      => 'wira_color_text',
					'default' => '#6e6e6e',
				),
				array(
					'id'      => 'wira_color_accent',
					'default' => '#00050a',
				),
				array(
					'id'      => 'wira_color_placeholder',
					'default' => '#A0A0A0',
				),
				array(
					'id'      => 'wira_color_tertiary',
					'default' => '#004da3',
				),
				array(
					'id'      => 'wira_color_secondaryaccent',
					'default' => '#53b1ff',
				),
				array(
					'id'      => 'wira_color_primaryaccent',
					'default' => '#ffcfb2',
				),
				array(
					'id'      => 'wira_color_primary20',
					'default' => '#F9840033',
				),
				array(
					'id'      => 'wira_color_border',
					'default' => '#dee2e6',
				),
				array(
					'id'      => 'wira_color_borderoverlay',
					'default' => '#ffffff38',
				),
				array(
					'id'      => 'wira_color_whitesmoke',
					'default' => '#f4fbfe',
				),
				array(
					'id'      => 'wira_color_white',
					'default' => '#ffffff',
				),
				array(
					'id'      => 'wira_color_whiteoverlay',
					'default' => '#ffffffc2',
				),
				array(
					'id'      => 'wira_color_white10',
					'default' => '#ffffff1a',
				),
				array(
					'id'      => 'wira_color_tertiarydark',
					'default' => '#001D3D',
				),
				array(
					'id'      => 'wira_color_tertiarydark90',
					'default' => '#001D3De6',
				),
				array(
					'id'      => 'wira_color_tertiarydark60',
					'default' => '#001D3D99',
				),
				array(
					'id'      => 'wira_color_tertiarydark20',
					'default' => '#001D3D33',
				),
				array(
					'id'      => 'wira_color_transparent',
					'default' => '#ffffff00',
				),
			);

			// Array label i18n-safe
			$color_labels = array(
				'wira_color_primary'         => __( 'Primary Color', 'wira' ),
				'wira_color_secondary'       => __( 'Secondary Color', 'wira' ),
				'wira_color_secondary20'     => __( 'Secondary 20%', 'wira' ),
				'wira_color_text'            => __( 'Text Color', 'wira' ),
				'wira_color_accent'          => __( 'Heading Color', 'wira' ),
				'wira_color_placeholder'     => __( 'Placeholder Color', 'wira' ),
				'wira_color_tertiary'        => __( 'Tertiary Color', 'wira' ),
				'wira_color_secondaryaccent' => __( 'Secondary Accent', 'wira' ),
				'wira_color_primaryaccent'   => __( 'Primary Accent', 'wira' ),
				'wira_color_primary20'       => __( 'Primary 20%', 'wira' ),
				'wira_color_border'          => __( 'Border Color', 'wira' ),
				'wira_color_borderoverlay'   => __( 'Border Overlay', 'wira' ),
				'wira_color_whitesmoke'      => __( 'Whitesmoke', 'wira' ),
				'wira_color_white'           => __( 'White', 'wira' ),
				'wira_color_whiteoverlay'    => __( 'White Overlay', 'wira' ),
				'wira_color_white10'         => __( 'White 10%', 'wira' ),
				'wira_color_tertiarydark'    => __( 'Tertiary Dark', 'wira' ),
				'wira_color_tertiarydark90'  => __( 'Tertiary Dark 90%', 'wira' ),
				'wira_color_tertiarydark60'  => __( 'Tertiary Dark 60%', 'wira' ),
				'wira_color_tertiarydark20'  => __( 'Tertiary Dark 20%', 'wira' ),
				'wira_color_transparent'     => __( 'Transparent', 'wira' ),
			);

			foreach ( $colors as $color ) {
				$wp_customize->add_setting(
					$color['id'],
					array(
						'default'           => $color['default'],
						'transport'         => 'refresh',
						'sanitize_callback' => array( $this, 'sanitize_rgba_color' ),
					)
				);

				$wp_customize->add_control(
					new \Wira\Alpha_Color_Control(
						$wp_customize,
						$color['id'],
						array(
							'label'    => $color_labels[ $color['id'] ], // i18n-safe
							'section'  => 'wira_theme_color',
							'settings' => $color['id'],
						)
					)
				);
			}

			// === Header Section ===
			$wp_customize->add_section(
				'wira_header_settings',
				array(
					'title'       => __( 'Header Settings', 'wira' ),
					'priority'    => 10,
					'description' => __( 'Customize the header content', 'wira' ),
					'panel'       => 'wira_panel',
				)
			);

			// = Navbar Overlay =
			$this->add_navbar_overlay_toggle( $wp_customize );

			// = Navbar Background Change =
			$this->add_navbar_bg_change_toggle( $wp_customize );

			// = Sticky Header =
			$this->add_sticky_header_toggle( $wp_customize );

			// = Navbar Button =
			$this->add_navbar_btn_toggle( $wp_customize );

			// = Navbar Button
			$wp_customize->add_setting(
				'wira_navbar_button_text',
				array(
					'default'           => __( 'Get Started', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_navbar_button_text',
				array(
					'label'           => __( 'Navbar Button Text', 'wira' ),
					'section'         => 'wira_header_settings',
					'type'            => 'text',
					'active_callback' => function () {
						return get_theme_mod( 'wira_enable_navbar_btn', false );
					},
				)
			);

			$wp_customize->add_setting(
				'wira_navbar_button_link',
				array(
					'default'           => '#',
					'sanitize_callback' => 'esc_url_raw',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_navbar_button_link',
				array(
					'label'           => __( 'Navbar Button Link', 'wira' ),
					'section'         => 'wira_header_settings',
					'type'            => 'url',
					'active_callback' => function () {
						return get_theme_mod( 'wira_enable_navbar_btn', false );
					},
				)
			);

			// === Topbar Settings ===

			$this->add_topbar_toggle( $wp_customize );

			// Email
			$wp_customize->add_setting(
				'wira_email_text',
				array(
					'default'           => __( 'info@example.com', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_email_text',
				array(
					'label'           => __( 'Email', 'wira' ),
					'section'         => 'wira_header_settings',
					'type'            => 'text',
					'active_callback' => function () {
						return get_theme_mod( 'wira_enable_topbar', false );
					},
				)
			);

			// Phone
			$wp_customize->add_setting(
				'wira_telephone_text',
				array(
					'default'           => __( '+62 123 456 789', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_telephone_text',
				array(
					'label'           => __( 'Telephone', 'wira' ),
					'section'         => 'wira_header_settings',
					'type'            => 'text',
					'active_callback' => function () {
						return get_theme_mod( 'wira_enable_topbar', false );
					},
				)
			);

			// Social Media Label
			$wp_customize->add_control(
				new \WP_Customize_Control(
					$wp_customize,
					'wira_social_link_heading',
					array(
						'type'            => 'hidden',
						'label'           => __( 'Social Media Links', 'wira' ),
						'description'     => __( 'Enable or disable and change social links setting for topbar.', 'wira' ),
						'section'         => 'wira_header_settings',
						'settings'        => array(),
						'active_callback' => function () {
							return get_theme_mod( 'wira_enable_topbar', false );
						},
					)
				)
			);

			// === SOCIALS ===
			$this->add_social_toggle( $wp_customize, 'facebook' );
			$this->add_social_toggle( $wp_customize, 'twitter' );
			$this->add_social_toggle( $wp_customize, 'linkedin' );
			$this->add_social_toggle( $wp_customize, 'pinterest' );

			// === Blog Home Section ===
			$wp_customize->add_section(
				'wira_blog_home_section',
				array(
					'title'       => __( 'Blog', 'wira' ),
					'priority'    => 20,
					'description' => __( 'Customize the blog home content', 'wira' ),
					'panel'       => 'wira_panel',
				)
			);

			$wp_customize->add_setting(
				'wira_blog_home_heading',
				array(
					'default'           => __( 'Blog Home', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_blog_home_heading',
				array(
					'label'   => __( 'Blog Home Heading Text', 'wira' ),
					'section' => 'wira_blog_home_section',
					'type'    => 'text',
				)
			);

			$wp_customize->add_setting(
				'wira_empty_heading_content_text',
				array(
					'default'           => __( 'No Articles Available', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_empty_heading_content_text',
				array(
					'label'   => __( 'Empty Content Heading', 'wira' ),
					'section' => 'wira_blog_home_section',
					'type'    => 'text',
				)
			);

			$wp_customize->add_setting(
				'wira_empty_content_text',
				array(
					'default'           => __( 'We couldn’t find any articles matching your criteria. Try adjusting your search or come back later.', 'wira' ),
					'sanitize_callback' => 'wp_kses_post',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_empty_content_text',
				array(
					'label'   => __( 'Empty Content Paragraph Text', 'wira' ),
					'section' => 'wira_blog_home_section',
					'type'    => 'textarea',
				)
			);

			// Archive Result Label
			$wp_customize->add_control(
				new \WP_Customize_Control(
					$wp_customize,
					'wira_archive_label_count',
					array(
						'type'        => 'hidden',
						'label'       => __( 'Archive Result Label', 'wira' ),
						'description' => __( 'Archive count result label', 'wira' ),
						'section'     => 'wira_blog_home_section',
						'settings'    => array(),
					)
				)
			);

			$wp_customize->add_setting(
				'wira_archive_before_count',
				array(
					'default'           => __( 'Found', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_archive_before_count',
				array(
					'label'   => __( 'Before Count', 'wira' ),
					'section' => 'wira_blog_home_section',
					'type'    => 'text',
				)
			);

			$wp_customize->add_setting(
				'wira_archive_after_count',
				array(
					'default'           => __( 'post result on', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_archive_after_count',
				array(
					'label'   => __( 'After Count', 'wira' ),
					'section' => 'wira_blog_home_section',
					'type'    => 'text',
				)
			);

			// Search Result Label
			$wp_customize->add_control(
				new \WP_Customize_Control(
					$wp_customize,
					'wira_search_label_count',
					array(
						'type'        => 'hidden',
						'label'       => __( 'Search Result Label', 'wira' ),
						'description' => __( 'Search count result label', 'wira' ),
						'section'     => 'wira_blog_home_section',
						'settings'    => array(),
					)
				)
			);

			$wp_customize->add_setting(
				'wira_search_before_count',
				array(
					'default'           => __( 'Found', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_search_before_count',
				array(
					'label'   => __( 'Before Count', 'wira' ),
					'section' => 'wira_blog_home_section',
					'type'    => 'text',
				)
			);

			$wp_customize->add_setting(
				'wira_search_after_count',
				array(
					'default'           => __( 'post search result on', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_search_after_count',
				array(
					'label'   => __( 'After Count', 'wira' ),
					'section' => 'wira_blog_home_section',
					'type'    => 'text',
				)
			);

			// === 404 Section ===
			$wp_customize->add_section(
				'wira_notfound_section',
				array(
					'title'       => __( '404', 'wira' ),
					'priority'    => 20,
					'description' => __( 'Customize the 404 content', 'wira' ),
					'panel'       => 'wira_panel',
				)
			);

			$wp_customize->add_setting(
				'wira_notfound_code_text',
				array(
					'default'           => __( '404', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_notfound_code_text',
				array(
					'label'   => __( '404 Text', 'wira' ),
					'section' => 'wira_notfound_section',
					'type'    => 'text',
				)
			);

			$wp_customize->add_setting(
				'wira_notfound_heading_text',
				array(
					'default'           => __( 'Page Not Found', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_notfound_heading_text',
				array(
					'label'   => __( 'Not Found Text', 'wira' ),
					'section' => 'wira_notfound_section',
					'type'    => 'text',
				)
			);

			$wp_customize->add_setting(
				'wira_notfound_wrong_text',
				array(
					'default'           => __( 'Oops... Something went wrong, please go back.', 'wira' ),
					'sanitize_callback' => 'wp_kses_post',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_notfound_wrong_text',
				array(
					'label'   => __( 'Not Found Wrong Text', 'wira' ),
					'section' => 'wira_notfound_section',
					'type'    => 'textarea',
				)
			);

			$wp_customize->add_setting(
				'wira_goback_text',
				array(
					'default'           => __( 'Back to Home', 'wira' ),
					'sanitize_callback' => 'sanitize_text_field',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_goback_text',
				array(
					'label'   => __( 'Button Text', 'wira' ),
					'section' => 'wira_notfound_section',
					'type'    => 'text',
				)
			);

			// === Footer Section ===
			$wp_customize->add_section(
				'wira_footer_section',
				array(
					'title'       => __( 'Footer Settings', 'wira' ),
					'priority'    => 30,
					'description' => __( 'Customize the footer credit text.', 'wira' ),
					'panel'       => 'wira_panel',
				)
			);

			$wp_customize->add_setting(
				'wira_footer_credit',
				array(
					'default'           => sprintf(
						__( '© %s All rights reserved - Wira Theme by Wirastudio', 'wira' ),
						date( 'Y' )
					),
					'sanitize_callback' => 'wp_kses_post',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				'wira_footer_credit',
				array(
					'label'   => __( 'Footer Credit Text', 'wira' ),
					'section' => 'wira_footer_section',
					'type'    => 'textarea',
				)
			);

			// = Add Scroll Top =
			$this->add_scroll_top_toggle( $wp_customize );

			/**
			 * Add Partial selective refresh
			 */
			if ( isset( $wp_customize->selective_refresh ) ) {
				// Email partial
				$wp_customize->selective_refresh->add_partial(
					'wira_email_text',
					array(
						'selector'         => '.theme-topbar-email span',
						'render_callback'  => function () {
							return esc_html( get_theme_mod( 'wira_email_text', 'info@example.com' ) );
						},
						'fallback_refresh' => false,
					)
				);

				// Telephone partial
				$wp_customize->selective_refresh->add_partial(
					'wira_telephone_text',
					array(
						'selector'         => '.theme-topbar-phone span',
						'render_callback'  => function () {
							return esc_html( get_theme_mod( 'wira_telephone_text', '+62 123 456 789' ) );
						},
						'fallback_refresh' => false,
					)
				);

				// Social Link Facebook
				$wp_customize->selective_refresh->add_partial(
					'wira_facebook_social_link',
					array(
						'selector'         => '.theme-social-facebook a',
						'render_callback'  => function () {
							return esc_html( get_theme_mod( 'wira_facebook_social_link', '#' ) );
						},
						'fallback_refresh' => false,
					)
				);

				// Social Link Twitter
				$wp_customize->selective_refresh->add_partial(
					'wira_twitter_social_link',
					array(
						'selector'         => '.theme-social-twitter a',
						'render_callback'  => function () {
							return esc_html( get_theme_mod( 'wira_twitter_social_link', '#' ) );
						},
						'fallback_refresh' => false,
					)
				);

				// Social Link LinkedIn
				$wp_customize->selective_refresh->add_partial(
					'wira_linkedin_social_link',
					array(
						'selector'         => '.theme-social-linkedin a',
						'render_callback'  => function () {
							return esc_html( get_theme_mod( 'wira_linkedin_social_link', '#' ) );
						},
						'fallback_refresh' => false,
					)
				);

				// Social Link Pinterest
				$wp_customize->selective_refresh->add_partial(
					'wira_pinterest_social_link',
					array(
						'selector'         => '.theme-social-pinterest a',
						'render_callback'  => function () {
							return esc_html( get_theme_mod( 'wira_pinterest_social_link', '#' ) );
						},
						'fallback_refresh' => false,
					)
				);

				// Navbar Button
				$wp_customize->selective_refresh->add_partial(
					'wira_navbar_button_text',
					array(
						'selector'         => '.theme-navbar-btn',
						'render_callback'  => function () {
							return esc_html( get_theme_mod( 'wira_navbar_button_text', 'Get Started' ) );
						},
						'fallback_refresh' => false,
					)
				);

				// Navbar Button
				$wp_customize->selective_refresh->add_partial(
					'wira_footer_credit',
					array(
						'selector'         => '.theme-footer-credit',
						'render_callback'  => function () {
							return esc_html( get_theme_mod( 'wira_footer_credit', '© %s All rights reserved - Wira Theme by Wirastudio' ) );
						},
						'fallback_refresh' => false,
					)
				);

				// Blog Home
				$wp_customize->selective_refresh->add_partial(
					'wira_blog_home_heading',
					array(
						'selector'         => '.theme-blog-home',
						'render_callback'  => function () {
							return esc_html( get_theme_mod( 'wira_blog_home_heading', 'Blog Home' ) );
						},
						'fallback_refresh' => false,
					)
				);
			}
		}

		/**
		 * Sanitize rgba/hex color.
		 *
		 * @param string $value Color value.
		 * @return string|null
		 */
		public function sanitize_rgba_color( $value ) {
			$value = trim( (string) $value );

			if ( '' === $value ) {
				return '';
			}

			if ( 'transparent' === strtolower( $value ) ) {
				return 'transparent';
			}

			// Hex colors.
			$hex = sanitize_hex_color( $value );
			if ( $hex ) {
				return $hex;
			}

			// RGBA or RGB.
			if ( preg_match( '/^rgba?\(\s*(\d{1,3})\s*,\s*(\d{1,3})\s*,\s*(\d{1,3})(\s*,\s*(0|0?\.\d+|1(\.0)?))?\s*\)$/i', $value, $matches ) ) {
				$r = min( 255, max( 0, intval( $matches[1] ) ) );
				$g = min( 255, max( 0, intval( $matches[2] ) ) );
				$b = min( 255, max( 0, intval( $matches[3] ) ) );
				if ( isset( $matches[4] ) && '' !== $matches[4] ) {
					$a = floatval( $matches[5] );
					$a = max( 0, min( 1, $a ) );
					return sprintf( 'rgba(%d,%d,%d,%.2f)', $r, $g, $b, $a );
				}
				return sprintf( 'rgb(%d,%d,%d)', $r, $g, $b );
			}

			return '';
		}

		/**
		 * Add Topbar setting to the Customizer.
		 *
		 * @param WP_Customize_Manager $wp_customize Customizer object.
		 */
		private function add_topbar_toggle( $wp_customize ) {
			$setting_key = 'wira_enable_topbar';

			$wp_customize->add_setting(
				$setting_key,
				array(
					'default'           => true,
					'sanitize_callback' => 'wp_validate_boolean',
				)
			);

			$wp_customize->add_control(
				new Toggle_Control(
					$wp_customize,
					$setting_key,
					array(
						'label'    => __( 'Activated Topbar', 'wira' ),
						'section'  => 'wira_header_settings',
						'settings' => $setting_key,
					)
				)
			);
		}

		/**
		 * Add Navbar Button setting to the Customizer.
		 *
		 * @param WP_Customize_Manager $wp_customize Customizer object.
		 */
		private function add_navbar_btn_toggle( $wp_customize ) {
			$setting_key = 'wira_enable_navbar_btn';

			$wp_customize->add_setting(
				$setting_key,
				array(
					'default'           => true,
					'sanitize_callback' => 'wp_validate_boolean',
				)
			);

			$wp_customize->add_control(
				new Toggle_Control(
					$wp_customize,
					$setting_key,
					array(
						'label'    => __( 'Enable Navbar Button', 'wira' ),
						'section'  => 'wira_header_settings',
						'settings' => $setting_key,
					)
				)
			);
		}

		/**
		 * Add Navbar Overlay setting to the Customizer.
		 *
		 * @param WP_Customize_Manager $wp_customize Customizer object.
		 */
		private function add_navbar_overlay_toggle( $wp_customize ) {
			$setting_key = 'wira_enable_navbar_overlay';

			$wp_customize->add_setting(
				$setting_key,
				array(
					'default'           => false,
					'sanitize_callback' => 'wp_validate_boolean',
				)
			);

			$wp_customize->add_control(
				new Toggle_Control(
					$wp_customize,
					$setting_key,
					array(
						'label'    => __( 'Enable Navbar Overlay', 'wira' ),
						'section'  => 'wira_header_settings',
						'settings' => $setting_key,
					)
				)
			);
		}

		/**
		 * Add Navbar Background Change setting to the Customizer.
		 *
		 * @param WP_Customize_Manager $wp_customize Customizer object.
		 */
		private function add_navbar_bg_change_toggle( $wp_customize ) {
			$setting_key = 'wira_enable_navbar_bg_change';

			$wp_customize->add_setting(
				$setting_key,
				array(
					'default'           => false,
					'sanitize_callback' => 'wp_validate_boolean',
				)
			);

			$wp_customize->add_control(
				new Toggle_Control(
					$wp_customize,
					$setting_key,
					array(
						'label'    => __( 'Enable Navbar Background Change', 'wira' ),
						'section'  => 'wira_header_settings',
						'settings' => $setting_key,
					)
				)
			);
		}

		/**
		 * Add Sticky Header toggle setting to the Customizer.
		 *
		 * @param WP_Customize_Manager $wp_customize Customizer object.
		 */
		private function add_sticky_header_toggle( $wp_customize ) {
			$setting_key = 'wira_enable_sticky_header';

			$wp_customize->add_setting(
				$setting_key,
				array(
					'default'           => true,
					'sanitize_callback' => 'wp_validate_boolean',
				)
			);

			$wp_customize->add_control(
				new Toggle_Control(
					$wp_customize,
					$setting_key,
					array(
						'label'    => __( 'Enable Sticky Header', 'wira' ),
						'section'  => 'wira_header_settings',
						'settings' => $setting_key,
					)
				)
			);
		}

		/**
		 * Social Icons Topbar Toggle Functions
		 *
		 * @param WP_Customize_Manager $wp_customize Customizer object.
		 */
		private function add_social_toggle( $wp_customize, $network ) {
			$label       = ucfirst( $network );
			$setting_key = "wira_enable_social_{$network}";
			$link_key    = "wira_{$network}_social_link";

			$wp_customize->add_setting(
				$setting_key,
				array(
					'default'           => true,
					'sanitize_callback' => 'wp_validate_boolean',
				)
			);

			$wp_customize->add_control(
				new Toggle_Control(
					$wp_customize,
					$setting_key,
					array(
						'label'           => sprintf( __( '%s Link', 'wira' ), $label ),
						'section'         => 'wira_header_settings',
						'settings'        => $setting_key,
						'active_callback' => function () {
							return get_theme_mod( 'wira_enable_topbar', false );
						},
					)
				)
			);

			$wp_customize->add_setting(
				$link_key,
				array(
					'default'           => '#',
					'sanitize_callback' => 'esc_url_raw',
					'transport'         => 'postMessage',
				)
			);

			$wp_customize->add_control(
				$link_key,
				array(
					'label'           => sprintf( __( '%s Link', 'wira' ), $label ),
					'section'         => 'wira_header_settings',
					'type'            => 'url',
					'active_callback' => function () use ( $setting_key ) {
						return get_theme_mod( 'wira_enable_topbar', false ) && get_theme_mod( $setting_key, false );
					},
				)
			);
		}

		/**
		 * Add Scroll Top toggle setting to the Customizer.
		 *
		 * @param WP_Customize_Manager $wp_customize Customizer object.
		 */
		private function add_scroll_top_toggle( $wp_customize ) {
			$setting_key = 'wira_enable_scroll_top';

			$wp_customize->add_setting(
				$setting_key,
				array(
					'default'           => false,
					'sanitize_callback' => 'wp_validate_boolean',
				)
			);

			$wp_customize->add_control(
				new Toggle_Control(
					$wp_customize,
					$setting_key,
					array(
						'label'    => __( 'Enable Scroll To Top', 'wira' ),
						'section'  => 'wira_footer_section',
						'settings' => $setting_key,
					)
				)
			);
		}

		/**
		 * Inline CSS for toggle class Functions
		 */
		public function toggle_css() {
			?>
			<style>
				.customize-control-toggle .switch {
					position: relative;
					display: inline-block;
					width: 50px;
					height: 24px;
				}
				.customize-control-toggle .switch input {
					opacity: 0;
					width: 0;
					height: 0;
				}
				.customize-control-toggle .slider {
					position: absolute;
					cursor: pointer;
					top: 0;
					left: 0;
					right: 0;
					bottom: 0;
					background-color: #ccc;
					transition: .4s;
					border-radius: 24px;
				}
				.customize-control-toggle .slider:before {
					position: absolute;
					content: "";
					height: 18px;
					width: 18px;
					left: 3px;
					bottom: 3px;
					background-color: white;
					transition: .4s;
					border-radius: 50%;
				}
				.customize-control-toggle input:checked + .slider {
					background-color: #2196F3;
				}
				.customize-control-toggle input:checked + .slider:before {
					transform: translateX(26px);
				}
			</style>
			<?php
		}
	}
}
