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

defined( 'ABSPATH' ) || exit;


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

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

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

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

	$wp_customize->add_control(
		new Shop_Zen_Title_Info_Control( $wp_customize, 'shop_zen_woocommerce_checkout_label',
		array(
			'label'    => esc_html__( 'Block Checkout', 'shop-zen' ),
			'section'  => 'shop_zen_woocommerce_checkout',
			'type'     => 'shop-zen-title',
			'settings' => 'shop_zen_woocommerce_checkout_label',
		)
	));

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

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

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

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

	$wp_customize->add_control(
		new Shop_Zen_Title_Info_Control( $wp_customize, 'shop_zen_woocommerce_cart_label',
		array(
			'label'    => esc_html__( 'Block Cart', 'shop-zen' ),
			'section'  => 'shop_zen_woocommerce_cart',
			'type'     => 'shop-zen-title',
			'settings' => 'shop_zen_woocommerce_cart_label',
		)
	));

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

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

add_action( 'customize_register', 'shop_zen_customizer_woocommerce_register' );
