<?php
/**
 * storecraft: Customizer
 *
 * @subpackage storecraft
 * @since 1.0
 */

/**
 * Register a color control.
 *
 * @param WP_Customize_Manager $wp_customize Customizer object.
 * @param string               $id           Setting ID.
 * @param string               $label        Control label.
 * @param string               $section      Section ID.
 */
function storecraft_customize_color( $wp_customize, $id, $label, $section ) {
	$wp_customize->add_setting(
		$id,
		array(
			'default'           => '',
			'sanitize_callback' => 'sanitize_hex_color',
		)
	);
	$wp_customize->add_control(
		new WP_Customize_Color_Control(
			$wp_customize,
			$id,
			array(
				'label'   => $label,
				'section' => $section,
			)
		)
	);
}

function storecraft_customize_register( $wp_customize ) {

	if ( ! class_exists( 'storecraft_Pro_Section' ) ) {

		/**
		 * Customizer section with an external Go Pro link.
		 */
		class storecraft_Pro_Section extends WP_Customize_Section {

			public $type = 'huda-pro-button';

			public $button_text = '';

			public $button_url = '';

			public function json() {
				$json                = parent::json();
				$json['button_text'] = $this->button_text;
				$json['button_url']  = esc_url( $this->button_url );

				return $json;
			}

			protected function render_template() {
				?>
				<li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }} cannot-expand">
					<h3 class="accordion-section-title">
						{{ data.title }}
						<# if ( data.button_text && data.button_url ) { #>
							<a href="{{ data.button_url }}" class="button button-secondary alignright" target="_blank" rel="noopener noreferrer">{{ data.button_text }}</a>
						<# } #>
					</h3>
				</li>
				<?php
			}
		}
	}

	$wp_customize->register_section_type( 'storecraft_Pro_Section' );

	$wp_customize->add_section(
		new storecraft_Pro_Section(
			$wp_customize,
			'storecraft_pro',
			array(
				'title'       => __( 'Storecraft Pro', 'storecraft' ),
				'priority'    => 0,
				'button_text' => __( 'Go Pro', 'storecraft' ),
				'button_url'  => 'https://hudawp.com/product/storecraft-multipurpose-woocommerce-wordpress-theme/',
			)
		)
	);

	$wp_customize->add_setting('storecraft_logo_size',array(
		'sanitize_callback'	=> 'storecraft_sanitize_float'
	));
	$wp_customize->add_control('storecraft_logo_size',array(
		'type' => 'range',
		'label' => __('Logo Size','storecraft'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting('storecraft_logo_padding',array(
		'sanitize_callback'	=> 'esc_html'
	));
	$wp_customize->add_control('storecraft_logo_padding',array(
		'label' => __('Logo Margin','storecraft'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting('storecraft_logo_top_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'storecraft_sanitize_float'
	));
	$wp_customize->add_control('storecraft_logo_top_padding',array(
		'type' => 'number',
		'description' => __('Top','storecraft'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('storecraft_logo_bottom_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'storecraft_sanitize_float'
	));
	$wp_customize->add_control('storecraft_logo_bottom_padding',array(
		'type' => 'number',
		'description' => __('Bottom','storecraft'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('storecraft_logo_left_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'storecraft_sanitize_float'
	));
	$wp_customize->add_control('storecraft_logo_left_padding',array(
		'type' => 'number',
		'description' => __('Left','storecraft'),
		'section' => 'title_tagline',
	));

	$wp_customize->add_setting('storecraft_logo_right_padding',array(
		'default' => '',
		'sanitize_callback'	=> 'storecraft_sanitize_float'
 	));
 	$wp_customize->add_control('storecraft_logo_right_padding',array(
		'type' => 'number',
		'description' => __('Right','storecraft'),
		'section' => 'title_tagline',
    ));

	$wp_customize->add_setting('storecraft_show_site_title',array(
		'default' => true,
		'sanitize_callback'	=> 'storecraft_sanitize_checkbox'
	));
	$wp_customize->add_control('storecraft_show_site_title',array(
		'type' => 'checkbox',
		'label' => __('Show / Hide Site Title','storecraft'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting( 'storecraft_site_title_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'storecraft_site_title_color', array(
		'label' => 'Title Color',
		'section' => 'title_tagline',
	)));

	$wp_customize->add_setting('storecraft_show_tagline',array(
		'default' => true,
		'sanitize_callback'	=> 'storecraft_sanitize_checkbox'
	));
	$wp_customize->add_control('storecraft_show_tagline',array(
		'type' => 'checkbox',
		'label' => __('Show / Hide Site Tagline','storecraft'),
		'section' => 'title_tagline'
	));

	$wp_customize->add_setting( 'storecraft_site_tagline_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'storecraft_site_tagline_color', array(
		'label' => 'Tagline Color',
		'section' => 'title_tagline',
	)));

	$wp_customize->add_panel( 'storecraft_panel_id', array(
		'priority' => 10,
		'capability' => 'edit_theme_options',
		'theme_supports' => '',
		'title' => __( 'Theme Settings', 'storecraft' ),
		'description' => __( 'Description of what this panel does.', 'storecraft' ),
	) );

	$wp_customize->add_section( 'storecraft_theme_options_section', array(
    	'title'      => __( 'General Settings', 'storecraft' ),
		'priority'   => 30,
		'panel' => 'storecraft_panel_id'
	) );

	$wp_customize->add_setting('storecraft_theme_options',array(
		'default' => 'One Column',
		'sanitize_callback' => 'storecraft_sanitize_choices'
	));
	$wp_customize->add_control('storecraft_theme_options',array(
		'type' => 'select',
		'label' => __('Blog Page Sidebar Layout','storecraft'),
		'section' => 'storecraft_theme_options_section',
		'choices' => array(
		   'Left Sidebar' => __('Left Sidebar','storecraft'),
		   'Right Sidebar' => __('Right Sidebar','storecraft'),
		   'One Column' => __('One Column','storecraft'),
		   'Grid Layout' => __('Grid Layout','storecraft')
		),
	));

	$wp_customize->add_setting('storecraft_single_post_sidebar',array(
		'default' => 'Right Sidebar',
		'sanitize_callback' => 'storecraft_sanitize_choices'
	));
	$wp_customize->add_control('storecraft_single_post_sidebar',array(
        'type' => 'select',
        'label' => __('Single Post Sidebar Layout','storecraft'),
        'section' => 'storecraft_theme_options_section',
        'choices' => array(
            'Left Sidebar' => __('Left Sidebar','storecraft'),
            'Right Sidebar' => __('Right Sidebar','storecraft'),
            'One Column' => __('One Column','storecraft')
        ),
	));

	$wp_customize->add_setting('storecraft_page_sidebar',array(
		'default' => 'One Column',
		'sanitize_callback' => 'storecraft_sanitize_choices'
	));
	$wp_customize->add_control('storecraft_page_sidebar',array(
        'type' => 'select',
        'label' => __('Page Sidebar Layout','storecraft'),
        'section' => 'storecraft_theme_options_section',
        'choices' => array(
            'Left Sidebar' => __('Left Sidebar','storecraft'),
            'Right Sidebar' => __('Right Sidebar','storecraft'),
            'One Column' => __('One Column','storecraft')
        ),
	));

	$wp_customize->add_setting('storecraft_archive_page_sidebar',array(
		'default' => 'One Column',
		'sanitize_callback' => 'storecraft_sanitize_choices'
	));
	$wp_customize->add_control('storecraft_archive_page_sidebar',array(
        'type' => 'select',
        'label' => __('Archive & Search Page Sidebar Layout','storecraft'),
        'section' => 'storecraft_theme_options_section',
        'choices' => array(
            'Left Sidebar' => __('Left Sidebar','storecraft'),
            'Right Sidebar' => __('Right Sidebar','storecraft'),
            'One Column' => __('One Column','storecraft'),
            'Grid Layout' => __('Grid Layout','storecraft')
        ),
	));
 
	/* ---------- Header Settings (new Storecraft header) ---------- */
	$wp_customize->add_section(
		'storecraft_header',
		array(
			'title'       => __( 'Header Settings', 'storecraft' ),
			'description' => __( 'Top bar, header actions, menu colors, and mobile menu. Assign the Primary Menu under Appearance → Menus.', 'storecraft' ),
			'priority'    => null,
			'panel'       => 'storecraft_panel_id',
		)
	);

	/* Top bar */
	$wp_customize->add_setting(
		'storecraft_show_topbar',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_show_topbar',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Show Top Bar', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_topbar_text',
		array(
			'default'           => __( 'Free Shipping on Orders Over $59', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_topbar_text',
		array(
			'type'    => 'text',
			'label'   => __( 'Top Bar Text', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	storecraft_customize_color( $wp_customize, 'storecraft_topbar_bg_color', __( 'Top Bar Background Color', 'storecraft' ), 'storecraft_header' );
	storecraft_customize_color( $wp_customize, 'storecraft_topbar_text_color', __( 'Top Bar Text Color', 'storecraft' ), 'storecraft_header' );

	/* Header actions */
	$wp_customize->add_setting(
		'storecraft_show_currency',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_show_currency',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Show Currency Label', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_header_language_text',
		array(
			'default'           => 'USD',
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_header_language_text',
		array(
			'type'    => 'text',
			'label'   => __( 'Currency Label Text', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_show_search',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_show_search',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Show Search Icon', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_show_account',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_show_account',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Show Account Icon', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_show_wishlist',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_show_wishlist',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Show Wishlist Icon', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_wishlist_url',
		array(
			'default'           => '',
			'sanitize_callback' => 'storecraft_sanitize_url',
		)
	);
	$wp_customize->add_control(
		'storecraft_wishlist_url',
		array(
			'type'        => 'url',
			'label'       => __( 'Wishlist Link', 'storecraft' ),
			'description' => __( 'Leave empty to use the My Account page.', 'storecraft' ),
			'section'     => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_show_cart',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_show_cart',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Show Cart Icon', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	/* Header / menu colors */
	storecraft_customize_color( $wp_customize, 'storecraft_header_bg_color', __( 'Header Background Color', 'storecraft' ), 'storecraft_header' );
	storecraft_customize_color( $wp_customize, 'storecraft_header_title_color', __( 'Site Title Color', 'storecraft' ), 'storecraft_header' );
	storecraft_customize_color( $wp_customize, 'storecraft_header_menu_color', __( 'Menu Link Color', 'storecraft' ), 'storecraft_header' );
	storecraft_customize_color( $wp_customize, 'storecraft_header_menu_hover_color', __( 'Menu Hover / Active Color', 'storecraft' ), 'storecraft_header' );
	storecraft_customize_color( $wp_customize, 'storecraft_headeraccicon_col', __( 'Header Icons Color', 'storecraft' ), 'storecraft_header' );
	storecraft_customize_color( $wp_customize, 'storecraft_headercartnumbg_col', __( 'Cart Badge Background', 'storecraft' ), 'storecraft_header' );
	storecraft_customize_color( $wp_customize, 'storecraft_headercartnum_col', __( 'Cart Badge Text Color', 'storecraft' ), 'storecraft_header' );

	/* Mobile menu */
	$wp_customize->add_setting(
		'storecraft_sidebar_show_account',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_sidebar_show_account',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Mobile Menu: Show Account Links', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_sidebar_show_currency',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_sidebar_show_currency',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Mobile Menu: Show Currency', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_sidebar_email',
		array(
			'default'           => get_option( 'admin_email' ),
			'sanitize_callback' => 'sanitize_email',
		)
	);
	$wp_customize->add_control(
		'storecraft_sidebar_email',
		array(
			'type'    => 'email',
			'label'   => __( 'Mobile Menu Contact Email', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_sidebar_social_instagram',
		array(
			'default'           => '',
			'sanitize_callback' => 'storecraft_sanitize_url',
		)
	);
	$wp_customize->add_control(
		'storecraft_sidebar_social_instagram',
		array(
			'type'    => 'url',
			'label'   => __( 'Mobile Menu Instagram URL', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_sidebar_social_facebook',
		array(
			'default'           => '',
			'sanitize_callback' => 'storecraft_sanitize_url',
		)
	);
	$wp_customize->add_control(
		'storecraft_sidebar_social_facebook',
		array(
			'type'    => 'url',
			'label'   => __( 'Mobile Menu Facebook URL', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	$wp_customize->add_setting(
		'storecraft_sidebar_social_pinterest',
		array(
			'default'           => '',
			'sanitize_callback' => 'storecraft_sanitize_url',
		)
	);
	$wp_customize->add_control(
		'storecraft_sidebar_social_pinterest',
		array(
			'type'    => 'url',
			'label'   => __( 'Mobile Menu Pinterest URL', 'storecraft' ),
			'section' => 'storecraft_header',
		)
	);

	storecraft_customize_color( $wp_customize, 'storecraft_sidebar_bg_color', __( 'Mobile Menu Background', 'storecraft' ), 'storecraft_header' );
	storecraft_customize_color( $wp_customize, 'storecraft_sidebar_menu_color', __( 'Mobile Menu Text Color', 'storecraft' ), 'storecraft_header' );
	storecraft_customize_color( $wp_customize, 'storecraft_sidebar_menu_active_bg_color', __( 'Mobile Menu Active Background', 'storecraft' ), 'storecraft_header' );
	storecraft_customize_color( $wp_customize, 'storecraft_sidebar_social_color', __( 'Mobile Menu Social Icon Color', 'storecraft' ), 'storecraft_header' );

	/* ---------- Slider Settings ---------- */
	$wp_customize->add_section(
		'storecraft_slider_section',
		array(
			'title'       => __( 'Slider Settings', 'storecraft' ),
			'description' => __( 'Select pages for slider slides. Use page title, excerpt, and featured image.', 'storecraft' ),
			'panel'       => 'storecraft_panel_id',
		)
	);

	$wp_customize->add_setting(
		'storecraft_slider_show',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_slider_show',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Show / Hide Slider', 'storecraft' ),
			'section' => 'storecraft_slider_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_slider_subheading',
		array(
			'default'           => __( 'New Arrivals', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_slider_subheading',
		array(
			'type'    => 'text',
			'label'   => __( 'Slider Subheading', 'storecraft' ),
			'section' => 'storecraft_slider_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_slider_btn_text',
		array(
			'default'           => __( 'SHOP NOW', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_slider_btn_text',
		array(
			'type'    => 'text',
			'label'   => __( 'Slider Button Text', 'storecraft' ),
			'section' => 'storecraft_slider_section',
		)
	);

	for ( $storecraft_i = 1; $storecraft_i <= 3; $storecraft_i++ ) {
		$wp_customize->add_setting(
			'storecraft_slider_page' . $storecraft_i,
			array(
				'default'           => 0,
				'sanitize_callback' => 'storecraft_sanitize_dropdown_pages',
			)
		);
		$wp_customize->add_control(
			'storecraft_slider_page' . $storecraft_i,
			array(
				'type'    => 'dropdown-pages',
				'label'   => sprintf(
					/* translators: %d: slide number */
					__( 'Select Slide Page %d', 'storecraft' ),
					$storecraft_i
				),
				'section' => 'storecraft_slider_section',
			)
		);
	}

	storecraft_customize_color( $wp_customize, 'storecraft_slider_title_color', __( 'Slider Title Color', 'storecraft' ), 'storecraft_slider_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_slider_subheading_color', __( 'Slider Subheading Color', 'storecraft' ), 'storecraft_slider_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_slider_text_color', __( 'Slider Description Color', 'storecraft' ), 'storecraft_slider_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_slider_btn_color', __( 'Slider Button Text Color', 'storecraft' ), 'storecraft_slider_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_slider_btn_border_color', __( 'Slider Button Border Color', 'storecraft' ), 'storecraft_slider_section' );

	/* ---------- Product Category Settings ---------- */
	$wp_customize->add_section(
		'storecraft_category_section',
		array(
			'title'       => __( 'Product Category Settings', 'storecraft' ),
			'description' => __( 'Requires WooCommerce. Displays product categories on the homepage.', 'storecraft' ),
			'panel'       => 'storecraft_panel_id',
		)
	);

	$wp_customize->add_setting(
		'storecraft_category_show',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_category_show',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Show / Hide Product Categories', 'storecraft' ),
			'section' => 'storecraft_category_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_category_title',
		array(
			'default'           => __( 'Shop by category', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_category_title',
		array(
			'type'    => 'text',
			'label'   => __( 'Section Title', 'storecraft' ),
			'section' => 'storecraft_category_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_category_count',
		array(
			'default'           => 6,
			'sanitize_callback' => 'absint',
		)
	);
	$wp_customize->add_control(
		'storecraft_category_count',
		array(
			'type'        => 'number',
			'label'       => __( 'Number of Categories', 'storecraft' ),
			'section'     => 'storecraft_category_section',
			'input_attrs' => array(
				'min' => 1,
				'max' => 12,
			),
		)
	);

	$wp_customize->add_setting(
		'storecraft_category_btn_text',
		array(
			'default'           => __( 'View All Categories', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_category_btn_text',
		array(
			'type'    => 'text',
			'label'   => __( 'Button Text', 'storecraft' ),
			'section' => 'storecraft_category_section',
		)
	);

	storecraft_customize_color( $wp_customize, 'storecraft_category_bg_color', __( 'Section Background Color', 'storecraft' ), 'storecraft_category_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_category_title_color', __( 'Section Title Color', 'storecraft' ), 'storecraft_category_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_category_name_color', __( 'Category Name Color', 'storecraft' ), 'storecraft_category_section' );

	/* ---------- Products Settings ---------- */
	$wp_customize->add_section(
		'storecraft_products_section',
		array(
			'title'       => __( 'Products Settings', 'storecraft' ),
			'description' => __( 'Requires WooCommerce. Displays all published products on the homepage.', 'storecraft' ),
			'panel'       => 'storecraft_panel_id',
		)
	);

	$wp_customize->add_setting(
		'storecraft_products_show',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_products_show',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Show / Hide Products', 'storecraft' ),
			'section' => 'storecraft_products_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_products_title',
		array(
			'default'           => __( 'Featured Products', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_products_title',
		array(
			'type'    => 'text',
			'label'   => __( 'Section Title', 'storecraft' ),
			'section' => 'storecraft_products_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_products_btn_text',
		array(
			'default'           => __( 'View all', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_products_btn_text',
		array(
			'type'    => 'text',
			'label'   => __( 'Button Text', 'storecraft' ),
			'section' => 'storecraft_products_section',
		)
	);

	storecraft_customize_color( $wp_customize, 'storecraft_products_bg_color', __( 'Section Background Color', 'storecraft' ), 'storecraft_products_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_products_title_color', __( 'Section Title Color', 'storecraft' ), 'storecraft_products_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_products_link_color', __( 'View All Link Color', 'storecraft' ), 'storecraft_products_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_products_item_title_color', __( 'Product Title Color', 'storecraft' ), 'storecraft_products_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_products_price_color', __( 'Product Price Color', 'storecraft' ), 'storecraft_products_section' );

	/* ---------- Banner Settings ---------- */
	$wp_customize->add_section(
		'storecraft_banner_section',
		array(
			'title' => __( 'Banner Settings', 'storecraft' ),
			'panel' => 'storecraft_panel_id',
		)
	);

	$wp_customize->add_setting(
		'storecraft_banner_show',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_banner_show',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Show / Hide Banner', 'storecraft' ),
			'section' => 'storecraft_banner_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_banner_kicker',
		array(
			'default'           => __( 'FLASH SALE', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_banner_kicker',
		array(
			'type'    => 'text',
			'label'   => __( 'Banner Kicker', 'storecraft' ),
			'section' => 'storecraft_banner_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_banner_title',
		array(
			'default'           => __( 'Limited Time Special Offer', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_banner_title',
		array(
			'type'    => 'text',
			'label'   => __( 'Banner Title', 'storecraft' ),
			'section' => 'storecraft_banner_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_banner_text',
		array(
			'default'           => __( 'Discover exclusive savings on curated pieces. This offer won\'t last — shop before it\'s gone.', 'storecraft' ),
			'sanitize_callback' => 'sanitize_textarea_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_banner_text',
		array(
			'type'    => 'textarea',
			'label'   => __( 'Banner Text', 'storecraft' ),
			'section' => 'storecraft_banner_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_banner_btn_text',
		array(
			'default'           => __( 'SHOP NOW', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_banner_btn_text',
		array(
			'type'    => 'text',
			'label'   => __( 'Primary Button Text', 'storecraft' ),
			'section' => 'storecraft_banner_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_banner_btn2_text',
		array(
			'default'           => __( 'VIEW ALL DEALS', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_banner_btn2_text',
		array(
			'type'    => 'text',
			'label'   => __( 'Secondary Button Text', 'storecraft' ),
			'section' => 'storecraft_banner_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_banner_btn_url',
		array(
			'default'           => '',
			'sanitize_callback' => 'storecraft_sanitize_url',
		)
	);
	$wp_customize->add_control(
		'storecraft_banner_btn_url',
		array(
			'type'        => 'url',
			'label'       => __( 'Button URL', 'storecraft' ),
			'description' => __( 'Leave empty to use the shop page.', 'storecraft' ),
			'section'     => 'storecraft_banner_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_banner_image',
		array(
			'default'           => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control(
		new WP_Customize_Image_Control(
			$wp_customize,
			'storecraft_banner_image',
			array(
				'label'   => __( 'Banner Image', 'storecraft' ),
				'section' => 'storecraft_banner_section',
			)
		)
	);

	storecraft_customize_color( $wp_customize, 'storecraft_banner_bg_color', __( 'Section Background Color', 'storecraft' ), 'storecraft_banner_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_banner_kicker_color', __( 'Kicker Color', 'storecraft' ), 'storecraft_banner_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_banner_title_color', __( 'Title Color', 'storecraft' ), 'storecraft_banner_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_banner_text_color', __( 'Text Color', 'storecraft' ), 'storecraft_banner_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_banner_btn_bg_color', __( 'Primary Button Background', 'storecraft' ), 'storecraft_banner_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_banner_btn_text_color', __( 'Primary Button Text Color', 'storecraft' ), 'storecraft_banner_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_banner_btn2_color', __( 'Secondary Button Color', 'storecraft' ), 'storecraft_banner_section' );

	/* ---------- Blog Settings ---------- */
	$wp_customize->add_section(
		'storecraft_blog_section',
		array(
			'title' => __( 'Blog Settings', 'storecraft' ),
			'panel' => 'storecraft_panel_id',
		)
	);

	$wp_customize->add_setting(
		'storecraft_blog_show',
		array(
			'default'           => true,
			'sanitize_callback' => 'storecraft_sanitize_checkbox',
		)
	);
	$wp_customize->add_control(
		'storecraft_blog_show',
		array(
			'type'    => 'checkbox',
			'label'   => __( 'Show / Hide Blog', 'storecraft' ),
			'section' => 'storecraft_blog_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_blog_title',
		array(
			'default'           => __( 'News', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_blog_title',
		array(
			'type'    => 'text',
			'label'   => __( 'Section Title', 'storecraft' ),
			'section' => 'storecraft_blog_section',
		)
	);

	$wp_customize->add_setting(
		'storecraft_blog_count',
		array(
			'default'           => 3,
			'sanitize_callback' => 'absint',
		)
	);
	$wp_customize->add_control(
		'storecraft_blog_count',
		array(
			'type'        => 'number',
			'label'       => __( 'Number of Posts', 'storecraft' ),
			'section'     => 'storecraft_blog_section',
			'input_attrs' => array(
				'min' => 1,
				'max' => 9,
			),
		)
	);

	$wp_customize->add_setting(
		'storecraft_blog_btn_text',
		array(
			'default'           => __( 'Visit Blog', 'storecraft' ),
			'sanitize_callback' => 'sanitize_text_field',
		)
	);
	$wp_customize->add_control(
		'storecraft_blog_btn_text',
		array(
			'type'    => 'text',
			'label'   => __( 'Button Text', 'storecraft' ),
			'section' => 'storecraft_blog_section',
		)
	);

	storecraft_customize_color( $wp_customize, 'storecraft_blog_bg_color', __( 'Section Background Color', 'storecraft' ), 'storecraft_blog_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_blog_title_color', __( 'Section Title Color', 'storecraft' ), 'storecraft_blog_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_blog_link_color', __( 'Visit Blog Link Color', 'storecraft' ), 'storecraft_blog_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_blog_post_title_color', __( 'Post Title Color', 'storecraft' ), 'storecraft_blog_section' );
	storecraft_customize_color( $wp_customize, 'storecraft_blog_excerpt_color', __( 'Post Excerpt Color', 'storecraft' ), 'storecraft_blog_section' );

	//Footer
    $wp_customize->add_section( 'storecraft_footer', array(
    	'title'  => __( 'Footer Settings', 'storecraft' ),
		'description' => __( 'Assign menus under Appearance → Menus to Footer Shop, Footer Customer Service, and Footer About locations.', 'storecraft' ),
		'priority' => null,
		'panel' => 'storecraft_panel_id'
	) );

	$wp_customize->add_setting('storecraft_show_back_totop',array(
       'default' => true,
       'sanitize_callback'	=> 'storecraft_sanitize_checkbox'
    ));
    $wp_customize->add_control('storecraft_show_back_totop',array(
       'type' => 'checkbox',
       'label' => __('Show / Hide Back to Top','storecraft'),
       'section' => 'storecraft_footer'
    ));

    $wp_customize->add_setting('storecraft_footer_copy',array(
		'default' => '',
		'sanitize_callback'	=> 'sanitize_text_field'
	));	
    $wp_customize->add_control('storecraft_footer_copy',array(
		'label'	=> __('Copyright Text','storecraft'),
		'description' => __( 'Leave empty to use the default copyright. On the homepage it appears as uppercase text in the minimal black footer bar.', 'storecraft' ),
		'section' => 'storecraft_footer',
		'setting' => 'storecraft_footer_copy',
		'type' => 'text'
	));

	$wp_customize->add_setting('storecraft_footer_about_text',array(
		'default' => 'Your one-stop destination for premium beauty products. Enhance your natural glow with trusted skincare, makeup, and more.',
		'sanitize_callback' => 'sanitize_textarea_field'
	));
	$wp_customize->add_control('storecraft_footer_about_text',array(
		'label' => __('Brand Description','storecraft'),
		'section' => 'storecraft_footer',
		'type' => 'textarea'
	));

	$wp_customize->add_setting('storecraft_footer_logo_tag',array(
		'default' => 'Beauty',
		'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('storecraft_footer_logo_tag',array(
		'label' => __('Logo Tagline','storecraft'),
		'description' => __('Shown below site title when no custom logo is set.','storecraft'),
		'section' => 'storecraft_footer',
		'type' => 'text'
	));

	$wp_customize->add_setting('storecraft_footer_shop_heading',array(
		'default' => __( 'Quick Links', 'storecraft' ),
		'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('storecraft_footer_shop_heading',array(
		'label' => __('Quick Links Column Heading','storecraft'),
		'section' => 'storecraft_footer',
		'type' => 'text'
	));

	$wp_customize->add_setting('storecraft_footer_service_heading',array(
		'default' => __( 'Store Links', 'storecraft' ),
		'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('storecraft_footer_service_heading',array(
		'label' => __('Store Links Column Heading','storecraft'),
		'section' => 'storecraft_footer',
		'type' => 'text'
	));

	$wp_customize->add_setting('storecraft_footer_about_heading',array(
		'default' => __( 'About Us', 'storecraft' ),
		'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('storecraft_footer_about_heading',array(
		'label' => __('About Column Heading','storecraft'),
		'section' => 'storecraft_footer',
		'type' => 'text'
	));

	$wp_customize->add_setting('storecraft_footer_social_heading',array(
		'default' => __( 'Social Platform', 'storecraft' ),
		'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('storecraft_footer_social_heading',array(
		'label' => __('Social Column Heading','storecraft'),
		'section' => 'storecraft_footer',
		'type' => 'text'
	));

	$wp_customize->add_setting('storecraft_footer_newsletter_heading',array(
		'default' => __( 'Subscribe to our newsletter', 'storecraft' ),
		'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('storecraft_footer_newsletter_heading',array(
		'label' => __('Newsletter Heading','storecraft'),
		'section' => 'storecraft_footer',
		'type' => 'text'
	));

	$wp_customize->add_setting('storecraft_footer_newsletter_placeholder',array(
		'default' => __( 'Enter your email address', 'storecraft' ),
		'sanitize_callback' => 'sanitize_text_field'
	));
	$wp_customize->add_control('storecraft_footer_newsletter_placeholder',array(
		'label' => __('Newsletter Placeholder','storecraft'),
		'section' => 'storecraft_footer',
		'type' => 'text'
	));

	$social_networks = array(
		'instagram' => 'Instagram URL',
		'facebook'  => 'Facebook URL',
		'twitter'   => 'Twitter / X URL',
		'pinterest' => 'Pinterest URL',
		'youtube'   => 'YouTube URL',
	);
	foreach ( $social_networks as $social_key => $social_label ) {
		$wp_customize->add_setting(
			'storecraft_footer_social_' . $social_key,
			array(
				'default'           => '',
				'sanitize_callback' => 'esc_url_raw',
			)
		);
		$wp_customize->add_control(
			'storecraft_footer_social_' . $social_key,
			array(
				'label'   => $social_label,
				'section' => 'storecraft_footer',
				'type'    => 'url',
			)
		);
	}

	$wp_customize->add_setting('storecraft_footer_show_payments',array(
		'default' => true,
		'sanitize_callback' => 'storecraft_sanitize_checkbox'
	));
	$wp_customize->add_control('storecraft_footer_show_payments',array(
		'type' => 'checkbox',
		'label' => __('Show Payment Icons','storecraft'),
		'section' => 'storecraft_footer'
	));

	$wp_customize->add_setting(
		'storecraft_footer_payment_image',
		array(
			'default'           => '',
			'sanitize_callback' => 'esc_url_raw',
		)
	);
	$wp_customize->add_control(
		new WP_Customize_Image_Control(
			$wp_customize,
			'storecraft_footer_payment_image',
			array(
				'label'       => __( 'Payment Icons Image', 'storecraft' ),
				'description' => __( 'Upload one image for payment methods. When set, default payment badges are hidden.', 'storecraft' ),
				'section'     => 'storecraft_footer',
			)
		)
	);

	$wp_customize->add_setting( 'storecraft_footertext_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'storecraft_footertext_color', array(
		'label' => __( 'Text Color', 'storecraft' ),
		'section' => 'storecraft_footer',
	)));

	$wp_customize->add_setting( 'storecraft_footerbg_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'storecraft_footerbg_color', array(
		'label' => __( 'Background Color', 'storecraft' ),
		'section' => 'storecraft_footer',
	)));

	$wp_customize->add_setting( 'storecraft_footercopyright_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'storecraft_footercopyright_color', array(
		'label' => __( 'Copyright Color', 'storecraft' ),
		'section' => 'storecraft_footer',
	)));

	$wp_customize->add_setting( 'storecraft_footercopyrightbg_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'storecraft_footercopyrightbg_color', array(
		'label' => __( 'Copyright Background Color', 'storecraft' ),
		'section' => 'storecraft_footer',
	)));

	$wp_customize->add_setting( 'storecraft_footerscrolltotoptext_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'storecraft_footerscrolltotoptext_color', array(
		'label' => __( 'Scroll To Top Text Color', 'storecraft' ),
		'section' => 'storecraft_footer',
	)));

	$wp_customize->add_setting( 'storecraft_footerscrolltotopbg_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'storecraft_footerscrolltotopbg_color', array(
		'label' => __( 'Scroll To Top Background Color', 'storecraft' ),
		'section' => 'storecraft_footer',
	)));

	$wp_customize->add_setting( 'storecraft_footerscrolltotoptexthover_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'storecraft_footerscrolltotoptexthover_color', array(
		'label' => __( 'Scroll To Top Text Hover Color', 'storecraft' ),
		'section' => 'storecraft_footer',
	)));

	$wp_customize->add_setting( 'storecraft_footerscrolltotophover_color', array(
		'default' => '',
		'sanitize_callback' => 'sanitize_hex_color'
	));
	$wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'storecraft_footerscrolltotophover_color', array(
		'label' => __( 'Scroll To Top Hover Background', 'storecraft' ),
		'section' => 'storecraft_footer',
	)));




	

	$wp_customize->get_setting( 'blogname' )->transport          = 'postMessage';
	$wp_customize->get_setting( 'blogdescription' )->transport   = 'postMessage';
	$wp_customize->get_setting( 'header_textcolor' )->transport  = 'postMessage';

	$wp_customize->selective_refresh->add_partial( 'blogname', array(
		'selector' => '.site-title a',
		'render_callback' => 'storecraft_customize_partial_blogname',
	) );
	$wp_customize->selective_refresh->add_partial( 'blogdescription', array(
		'selector' => '.site-description',
		'render_callback' => 'storecraft_customize_partial_blogdescription',
	) );
}
add_action( 'customize_register', 'storecraft_customize_register' );

function storecraft_customize_partial_blogname() {
	bloginfo( 'name' );
}

function storecraft_customize_partial_blogdescription() {
	bloginfo( 'description' );
}

if (class_exists('WP_Customize_Control')) {

   	class storecraft_Fontawesome_Icon_Chooser extends WP_Customize_Control {

      	public $type = 'icon';

      	public function render_content() { ?>
	     	<label>
	            <span class="customize-control-title">
	               <?php echo esc_html($this->label); ?>
	            </span>

	            <?php if ($this->description) { ?>
	                <span class="description customize-control-description">
	                   <?php echo wp_kses_post($this->description); ?>
	                </span>
	            <?php } ?>

	            <div class="storecraft-selected-icon">
	                <i class="fa <?php echo esc_attr($this->value()); ?>"></i>
	                <span><i class="fa fa-angle-down"></i></span>
	            </div>

	            <ul class="storecraft-icon-list clearfix">
	                <?php
	                $storecraft_font_awesome_icon_array = storecraft_font_awesome_icon_array();
	                foreach ($storecraft_font_awesome_icon_array as $storecraft_font_awesome_icon) {
	                   $storecraft_icon_class = $this->value() == $storecraft_font_awesome_icon ? 'icon-active' : '';
	                   echo '<li class="' . esc_attr( $storecraft_icon_class ) . '"><i class="' . esc_attr( $storecraft_font_awesome_icon ) . '"></i></li>';
	                }
	                ?>
	            </ul>
	            <input type="hidden" value="<?php echo esc_attr( $this->value() ); ?>" <?php $this->link(); ?> />
	        </label>
	        <?php
      	}
  	}
}
function storecraft_customizer_script() {
	$version = wp_get_theme()->get( 'Version' );

	wp_enqueue_style( 'storecraft-fontawesome', esc_url( get_template_directory_uri() ) . '/assets/css/fontawesome-all.css' );
	wp_enqueue_style(
		'storecraft-customize-controls',
		get_theme_file_uri( 'assets/css/customize-controls.css' ),
		array( 'customize-controls' ),
		$version
	);
	wp_enqueue_script(
		'storecraft-customize-pro-section',
		get_theme_file_uri( 'assets/js/customize-pro-section.js' ),
		array( 'customize-controls' ),
		$version,
		true
	);
}
add_action( 'customize_controls_enqueue_scripts', 'storecraft_customizer_script' );