<?php
/**
 * WooCommerce Cart Customizer Controls
 *
 * @package pawwell
 */

defined( 'ABSPATH' ) || exit;

if ( ! function_exists( 'pawwell_is_active_woocommerce' ) || ! pawwell_is_active_woocommerce() ) {
	return;
}

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

	/**
	 * Section: Cart
	 */
	$wp_customize->add_section(
		'pawwell_woocommerce_cart',
		array(
			'title'    => esc_html__( 'Cart', 'pawwell' ),
			'panel'    => 'woocommerce',
			'priority' => 40,
		)
	);

	/* ── Block Cart ── */

	$wp_customize->add_setting(
		'pawwell_woocommerce_cart_label',
		array(
			'sanitize_callback' => 'pawwell_sanitize_title',
		)
	);

	$wp_customize->add_control(
		new Pawwell_Title_Info_Control( $wp_customize, 'pawwell_woocommerce_cart_label',
		array(
			'label'    => esc_html__( 'Block Cart', 'pawwell' ),
			'section'  => 'pawwell_woocommerce_cart',
			'type'     => 'pawwell-title',
			'settings' => 'pawwell_woocommerce_cart_label',
		)
	));

	$wp_customize->add_setting(
		'pawwell_enable_block_cart',
		array(
			'default'           => false,
			'type'              => 'theme_mod',
			'sanitize_callback' => 'pawwell_sanitize_checkbox',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		new Pawwell_Toggle_Control( $wp_customize, 'pawwell_enable_block_cart',
		array(
			'label'       => esc_html__( 'Enable Block Cart', 'pawwell' ),
			'description' => esc_html__( 'Use the default WooCommerce Block cart. When enabled, the theme classic cart template overrides are disabled.', 'pawwell' ),
			'section'     => 'pawwell_woocommerce_cart',
			'type'        => 'pawwell-toggle',
			'settings'    => 'pawwell_enable_block_cart',
		)
	));

	/* ── Hero Section ── */

	// Title separator
	$wp_customize->add_setting(
		'pawwell_cart_hero_label',
		array(
			'sanitize_callback' => 'pawwell_sanitize_title',
		)
	);

	$wp_customize->add_control(
		new Pawwell_Title_Info_Control( $wp_customize, 'pawwell_cart_hero_label',
		array(
			'label'    => esc_html__( 'Cart Hero / Title', 'pawwell' ),
			'section'  => 'pawwell_woocommerce_cart',
			'type'     => 'pawwell-title',
			'settings' => 'pawwell_cart_hero_label',
		)
	));

	// Master enable toggle
	$wp_customize->add_setting(
		'pawwell_cart_hero_enable',
		array(
			'default'           => true,
			'type'              => 'theme_mod',
			'sanitize_callback' => 'pawwell_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		new Pawwell_Toggle_Control( $wp_customize, 'pawwell_cart_hero_enable',
		array(
			'label'       => esc_html__( 'Show Hero Section', 'pawwell' ),
			'description' => esc_html__( 'Display the hero title block at the top of the cart page.', 'pawwell' ),
			'section'     => 'pawwell_woocommerce_cart',
			'type'        => 'pawwell-toggle',
			'settings'    => 'pawwell_cart_hero_enable',
		)
	));

	// Eyebrow text
	$wp_customize->add_setting(
		'pawwell_cart_hero_eyebrow',
		array(
			'default'           => __( 'Almost Yours', 'pawwell' ),
			'type'              => 'theme_mod',
			'sanitize_callback' => 'pawwell_sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'pawwell_cart_hero_eyebrow',
		array(
			'settings'  => 'pawwell_cart_hero_eyebrow',
			'section'   => 'pawwell_woocommerce_cart',
			'type'      => 'text',
			'label'     => esc_html__( 'Eyebrow Text', 'pawwell' ),
		)
	);

	// Title (main)
	$wp_customize->add_setting(
		'pawwell_cart_hero_title',
		array(
			'default'           => __( 'Your', 'pawwell' ),
			'type'              => 'theme_mod',
			'sanitize_callback' => 'pawwell_sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'pawwell_cart_hero_title',
		array(
			'settings'  => 'pawwell_cart_hero_title',
			'section'   => 'pawwell_woocommerce_cart',
			'type'      => 'text',
			'label'     => esc_html__( 'Title', 'pawwell' ),
		)
	);

	// Title (accent)
	$wp_customize->add_setting(
		'pawwell_cart_hero_title_accent',
		array(
			'default'           => __( 'Shopping Cart', 'pawwell' ),
			'type'              => 'theme_mod',
			'sanitize_callback' => 'pawwell_sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'pawwell_cart_hero_title_accent',
		array(
			'settings'  => 'pawwell_cart_hero_title_accent',
			'section'   => 'pawwell_woocommerce_cart',
			'type'      => 'text',
			'label'     => esc_html__( 'Title Accent (highlighted)', 'pawwell' ),
		)
	);

	// Subtitle
	$wp_customize->add_setting(
		'pawwell_cart_hero_subtitle',
		array(
			'default'           => __( 'Review your selected essentials, adjust quantities and apply any promo codes before a quick, secure checkout.', 'pawwell' ),
			'type'              => 'theme_mod',
			'sanitize_callback' => 'pawwell_sanitize_textarea_field',
		)
	);

	$wp_customize->add_control(
		'pawwell_cart_hero_subtitle',
		array(
			'settings'  => 'pawwell_cart_hero_subtitle',
			'section'   => 'pawwell_woocommerce_cart',
			'type'      => 'textarea',
			'label'     => esc_html__( 'Subtitle', 'pawwell' ),
		)
	);

	/* ── Hero Stat Box ── */

	// Title separator
	$wp_customize->add_setting(
		'pawwell_cart_hero_stat_label',
		array(
			'sanitize_callback' => 'pawwell_sanitize_title',
		)
	);

	$wp_customize->add_control(
		new Pawwell_Title_Info_Control( $wp_customize, 'pawwell_cart_hero_stat_label',
		array(
			'label'    => esc_html__( 'Hero Stat Box', 'pawwell' ),
			'section'  => 'pawwell_woocommerce_cart',
			'type'     => 'pawwell-title',
			'settings' => 'pawwell_cart_hero_stat_label',
		)
	));

	// Show stat box toggle
	$wp_customize->add_setting(
		'pawwell_cart_hero_stat_enable',
		array(
			'default'           => true,
			'type'              => 'theme_mod',
			'sanitize_callback' => 'pawwell_sanitize_checkbox',
		)
	);

	$wp_customize->add_control(
		new Pawwell_Toggle_Control( $wp_customize, 'pawwell_cart_hero_stat_enable',
		array(
			'label'    => esc_html__( 'Show Item Count Stat', 'pawwell' ),
			'section'  => 'pawwell_woocommerce_cart',
			'type'     => 'pawwell-toggle',
			'settings' => 'pawwell_cart_hero_stat_enable',
		)
	));

	// Stat label
	$wp_customize->add_setting(
		'pawwell_cart_hero_stat_text',
		array(
			'default'           => __( 'ready to checkout', 'pawwell' ),
			'type'              => 'theme_mod',
			'sanitize_callback' => 'pawwell_sanitize_text_field',
		)
	);

	$wp_customize->add_control(
		'pawwell_cart_hero_stat_text',
		array(
			'settings'  => 'pawwell_cart_hero_stat_text',
			'section'   => 'pawwell_woocommerce_cart',
			'type'      => 'text',
			'label'     => esc_html__( 'Stat Caption', 'pawwell' ),
			'description' => esc_html__( 'Text shown under the item count, e.g. "ready to checkout".', 'pawwell' ),
		)
	);
}
endif;

add_action( 'customize_register', 'pawwell_customizer_woocommerce_cart_register' );
