<?php
/**
 * Theme Customizer Controls - WooCommerce
 *
 * @package shopbar
 */

defined( 'ABSPATH' ) || exit;


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

	if ( ! class_exists( 'WooCommerce' ) ) {
		return;
	}

	/**
	 * Product Archive Page Settings Section
	 */
	$wp_customize->add_section(
		'shopbar_woocommerce_product_archive',
		array(
			'title'    => esc_html__( 'Product Archive Page', 'shopbar' ),
			'panel'    => 'woocommerce',
			'priority' => 10,
		)
	);

	// Title label.
	$wp_customize->add_setting(
		'shopbar_woocommerce_archive_label',
		array(
			'sanitize_callback' => 'shopbar_sanitize_title',
		)
	);

	$wp_customize->add_control(
		new Shopbar_Title_Info_Control( $wp_customize, 'shopbar_woocommerce_archive_label',
		array(
			'label'    => esc_html__( 'Archive Header', 'shopbar' ),
			'section'  => 'shopbar_woocommerce_product_archive',
			'type'     => 'shopbar-title',
			'settings' => 'shopbar_woocommerce_archive_label',
		)
	));

	// Archive Title.
	$wp_customize->add_setting(
		'shopbar_archive_page_title',
		array(
			'default'           => '',
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shopbar_sanitize_text_field',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shopbar_archive_page_title',
		array(
			'label'       => esc_html__( 'Title', 'shopbar' ),
			'description' => esc_html__( 'Displayed as the main heading on the product archive page. Leave empty to use the default title.', 'shopbar' ),
			'section'     => 'shopbar_woocommerce_product_archive',
			'type'        => 'text',
		)
	);

	// Archive Subtitle.
	$wp_customize->add_setting(
		'shopbar_archive_page_subtitle',
		array(
			'default'           => '',
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shopbar_sanitize_textarea_field',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shopbar_archive_page_subtitle',
		array(
			'label'       => esc_html__( 'Subtitle', 'shopbar' ),
			'description' => esc_html__( 'Short description shown beneath the title. Leave empty to use the default text.', 'shopbar' ),
			'section'     => 'shopbar_woocommerce_product_archive',
			'type'        => 'textarea',
		)
	);

	/**
	 * Promo Banner sub-group.
	 *
	 */

	// Title label - Promo Banner.
	$wp_customize->add_setting(
		'shopbar_woocommerce_promo_label',
		array(
			'sanitize_callback' => 'shopbar_sanitize_title',
		)
	);

	$wp_customize->add_control(
		new Shopbar_Title_Info_Control( $wp_customize, 'shopbar_woocommerce_promo_label',
		array(
			'label'    => esc_html__( 'Promo Banner', 'shopbar' ),
			'section'  => 'shopbar_woocommerce_product_archive',
			'type'     => 'shopbar-title',
			'settings' => 'shopbar_woocommerce_promo_label',
		)
	));

	// Enable / disable the promo banner.
	$wp_customize->add_setting(
		'shopbar_archive_promo_enable',
		array(
			'default'           => true,
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shopbar_sanitize_checkbox',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		new Shopbar_Toggle_Control( $wp_customize, 'shopbar_archive_promo_enable',
		array(
			'label'       => esc_html__( 'Show Promo Banner', 'shopbar' ),
			'description' => esc_html__( 'Display the promotional banner next to the archive header. When disabled, the title block is centered.', 'shopbar' ),
			'section'     => 'shopbar_woocommerce_product_archive',
			'type'        => 'shopbar-toggle',
			'settings'    => 'shopbar_archive_promo_enable',
		)
	));

	// Promo Eyebrow.
	$wp_customize->add_setting(
		'shopbar_archive_promo_eyebrow',
		array(
			'default'           => '',
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shopbar_sanitize_text_field',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shopbar_archive_promo_eyebrow',
		array(
			'label'       => esc_html__( 'Promo Eyebrow', 'shopbar' ),
			'description' => esc_html__( 'Small label above the promo headline. Leave empty for the default.', 'shopbar' ),
			'section'     => 'shopbar_woocommerce_product_archive',
			'type'        => 'text',
		)
	);

	// Promo Headline.
	$wp_customize->add_setting(
		'shopbar_archive_promo_headline',
		array(
			'default'           => '',
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shopbar_sanitize_text_field',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shopbar_archive_promo_headline',
		array(
			'label'       => esc_html__( 'Promo Headline', 'shopbar' ),
			'description' => esc_html__( 'Main heading of the promo banner. Leave empty for the default.', 'shopbar' ),
			'section'     => 'shopbar_woocommerce_product_archive',
			'type'        => 'text',
		)
	);

	// Promo Subtext.
	$wp_customize->add_setting(
		'shopbar_archive_promo_subtitle',
		array(
			'default'           => '',
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shopbar_sanitize_textarea_field',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shopbar_archive_promo_subtitle',
		array(
			'label'       => esc_html__( 'Promo Subtext', 'shopbar' ),
			'description' => esc_html__( 'Supporting line beneath the promo headline. Leave empty for the default.', 'shopbar' ),
			'section'     => 'shopbar_woocommerce_product_archive',
			'type'        => 'textarea',
		)
	);

	// Promo CTA Text.
	$wp_customize->add_setting(
		'shopbar_archive_promo_cta_text',
		array(
			'default'           => '',
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shopbar_sanitize_text_field',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shopbar_archive_promo_cta_text',
		array(
			'label'       => esc_html__( 'Promo CTA Text', 'shopbar' ),
			'description' => esc_html__( 'Text for the promo button. Leave empty for the default.', 'shopbar' ),
			'section'     => 'shopbar_woocommerce_product_archive',
			'type'        => 'text',
		)
	);

	// Promo CTA URL.
	$wp_customize->add_setting(
		'shopbar_archive_promo_cta_url',
		array(
			'default'           => '',
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shopbar_sanitize_url',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shopbar_archive_promo_cta_url',
		array(
			'label'       => esc_html__( 'Promo CTA Link', 'shopbar' ),
			'description' => esc_html__( 'Destination URL for the promo button. Leave empty to link to the on-sale products.', 'shopbar' ),
			'section'     => 'shopbar_woocommerce_product_archive',
			'type'        => 'url',
		)
	);

	/**
	 * Checkout Settings Section
	 *
	 */
	$wp_customize->add_section(
		'shopbar_woocommerce_checkout',
		array(
			'title'    => esc_html__( 'Checkout', 'shopbar' ),
			'panel'    => 'woocommerce',
			'priority' => 30,
		)
	);

	// Title label - Block Checkout.
	$wp_customize->add_setting(
		'shopbar_woocommerce_checkout_label',
		array(
			'sanitize_callback' => 'shopbar_sanitize_title',
		)
	);

	$wp_customize->add_control(
		new Shopbar_Title_Info_Control( $wp_customize, 'shopbar_woocommerce_checkout_label',
		array(
			'label'    => esc_html__( 'Block Checkout', 'shopbar' ),
			'section'  => 'shopbar_woocommerce_checkout',
			'type'     => 'shopbar-title',
			'settings' => 'shopbar_woocommerce_checkout_label',
		)
	));

	// Enable Block Checkout.
	$wp_customize->add_setting(
		'shopbar_enable_block_checkout',
		array(
			'default'           => false,
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shopbar_sanitize_checkbox',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		new Shopbar_Toggle_Control( $wp_customize, 'shopbar_enable_block_checkout',
		array(
			'label'       => esc_html__( 'Enable Block Checkout', 'shopbar' ),
			'description' => esc_html__( 'Use the default WooCommerce Block checkout. When enabled, the theme classic checkout template overrides are disabled.', 'shopbar' ),
			'section'     => 'shopbar_woocommerce_checkout',
			'type'        => 'shopbar-toggle',
			'settings'    => 'shopbar_enable_block_checkout',
		)
	));

	/**
	 * Cart Settings Section
	 *
	 */
	$wp_customize->add_section(
		'shopbar_woocommerce_cart',
		array(
			'title'    => esc_html__( 'Cart', 'shopbar' ),
			'panel'    => 'woocommerce',
			'priority' => 40,
		)
	);

	// Title label - Block Cart.
	$wp_customize->add_setting(
		'shopbar_woocommerce_cart_label',
		array(
			'sanitize_callback' => 'shopbar_sanitize_title',
		)
	);

	$wp_customize->add_control(
		new Shopbar_Title_Info_Control( $wp_customize, 'shopbar_woocommerce_cart_label',
		array(
			'label'    => esc_html__( 'Block Cart', 'shopbar' ),
			'section'  => 'shopbar_woocommerce_cart',
			'type'     => 'shopbar-title',
			'settings' => 'shopbar_woocommerce_cart_label',
		)
	));

	// Enable Block Cart.
	$wp_customize->add_setting(
		'shopbar_enable_block_cart',
		array(
			'default'           => false,
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shopbar_sanitize_checkbox',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		new Shopbar_Toggle_Control( $wp_customize, 'shopbar_enable_block_cart',
		array(
			'label'       => esc_html__( 'Enable Block Cart', 'shopbar' ),
			'description' => esc_html__( 'Use the default WooCommerce Block cart. When enabled, the theme classic cart template overrides are disabled.', 'shopbar' ),
			'section'     => 'shopbar_woocommerce_cart',
			'type'        => 'shopbar-toggle',
			'settings'    => 'shopbar_enable_block_cart',
		)
	));
}
endif;

add_action( 'customize_register', 'shopbar_customizer_woocommerce_register' );
