<?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;
	}

	/**
	 * Product Single Settings Section
	 *
	 */
	$wp_customize->add_section(
		'shop_zen_woocommerce_product_single',
		array(
			'title'    => esc_html__( 'Product Single', 'shop-zen' ),
			'panel'    => 'woocommerce',
			'priority' => 25,
		)
	);

	// Title label - Trust Signals.
	$wp_customize->add_setting(
		'shop_zen_woocommerce_trust_signals_label',
		array(
			'sanitize_callback' => 'shop_zen_sanitize_title',
		)
	);

	$wp_customize->add_control(
		new Shop_Zen_Title_Info_Control( $wp_customize, 'shop_zen_woocommerce_trust_signals_label',
		array(
			'label'    => esc_html__( 'Trust Signals', 'shop-zen' ),
			'section'  => 'shop_zen_woocommerce_product_single',
			'type'     => 'shop-zen-title',
			'settings' => 'shop_zen_woocommerce_trust_signals_label',
		)
	));

	// Enable Trust Signals.
	$wp_customize->add_setting(
		'shop_zen_enable_trust_signals',
		array(
			'default'           => true,
			'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_trust_signals',
		array(
			'label'       => esc_html__( 'Enable Trust Signals', 'shop-zen' ),
			'description' => esc_html__( 'Show the trust badges box (shipping, returns, warranty) on the single product page.', 'shop-zen' ),
			'section'     => 'shop_zen_woocommerce_product_single',
			'type'        => 'shop-zen-toggle',
			'settings'    => 'shop_zen_enable_trust_signals',
		)
	));

	// Trust Signal 1
	$wp_customize->add_setting(
		'shop_zen_trust_signal_1',
		array(
			'default'           => __( 'Free Shipping', 'shop-zen' ),
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shop_zen_sanitize_text_field',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shop_zen_trust_signal_1',
		array(
			'label'   => esc_html__( 'Trust Signal 1', 'shop-zen' ),
			'section' => 'shop_zen_woocommerce_product_single',
			'type'    => 'text',
			'settings' => 'shop_zen_trust_signal_1',
		)
	);

	// Trust Signal 1 - Icon.
	$trust_signal_icons = shop_zen_get_trust_signal_icons();
	$trust_signal_choices = array_merge(
		array( 'none' => esc_html__( 'No Icon', 'shop-zen' ) ),
		wp_list_pluck( $trust_signal_icons, 'label' )
	);

	$wp_customize->add_setting(
		'shop_zen_trust_signal_1_icon',
		array(
			'default'           => 'truck',
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shop_zen_sanitize_select',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shop_zen_trust_signal_1_icon',
		array(
			'label'   => esc_html__( 'Trust Signal 1 Icon', 'shop-zen' ),
			'section' => 'shop_zen_woocommerce_product_single',
			'type'    => 'select',
			'choices' => $trust_signal_choices,
			'settings' => 'shop_zen_trust_signal_1_icon',
		)
	);

	// Trust Signal 2
	$wp_customize->add_setting(
		'shop_zen_trust_signal_2',
		array(
			'default'           => __( '30-Day Returns', 'shop-zen' ),
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shop_zen_sanitize_text_field',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shop_zen_trust_signal_2',
		array(
			'label'   => esc_html__( 'Trust Signal 2', 'shop-zen' ),
			'section' => 'shop_zen_woocommerce_product_single',
			'type'    => 'text',
			'settings' => 'shop_zen_trust_signal_2',
		)
	);

	// Trust Signal 2 - Icon.
	$wp_customize->add_setting(
		'shop_zen_trust_signal_2_icon',
		array(
			'default'           => 'returns',
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shop_zen_sanitize_select',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shop_zen_trust_signal_2_icon',
		array(
			'label'   => esc_html__( 'Trust Signal 2 Icon', 'shop-zen' ),
			'section' => 'shop_zen_woocommerce_product_single',
			'type'    => 'select',
			'choices' => $trust_signal_choices,
			'settings' => 'shop_zen_trust_signal_2_icon',
		)
	);

	// Trust Signal 3
	$wp_customize->add_setting(
		'shop_zen_trust_signal_3',
		array(
			'default'           => __( '2-Year Warranty', 'shop-zen' ),
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shop_zen_sanitize_text_field',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shop_zen_trust_signal_3',
		array(
			'label'   => esc_html__( 'Trust Signal 3', 'shop-zen' ),
			'section' => 'shop_zen_woocommerce_product_single',
			'type'    => 'text',
			'settings' => 'shop_zen_trust_signal_3',
		)
	);

	// Trust Signal 3 - Icon.
	$wp_customize->add_setting(
		'shop_zen_trust_signal_3_icon',
		array(
			'default'           => 'shield',
			'type'              => 'theme_mod',
			'sanitize_callback' => 'shop_zen_sanitize_select',
			'transport'         => 'refresh',
		)
	);

	$wp_customize->add_control(
		'shop_zen_trust_signal_3_icon',
		array(
			'label'   => esc_html__( 'Trust Signal 3 Icon', 'shop-zen' ),
			'section' => 'shop_zen_woocommerce_product_single',
			'type'    => 'select',
			'choices' => $trust_signal_choices,
			'settings' => 'shop_zen_trust_signal_3_icon',
		)
	);

	/**
	 * 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',
		)
	));

	// Title label - Default Payment Section.
	$wp_customize->add_setting(
		'shop_zen_woocommerce_checkout_payment_label',
		array(
			'sanitize_callback' => 'shop_zen_sanitize_title',
		)
	);

	$wp_customize->add_control(
		new Shop_Zen_Title_Info_Control( $wp_customize, 'shop_zen_woocommerce_checkout_payment_label',
		array(
			'label'    => esc_html__( 'Payment Section', 'shop-zen' ),
			'section'  => 'shop_zen_woocommerce_checkout',
			'type'     => 'shop-zen-title',
			'settings' => 'shop_zen_woocommerce_checkout_payment_label',
		)
	));

	// Default Payment Section.
	$wp_customize->add_setting(
		'shop_zen_default_checkout_payment',
		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_default_checkout_payment',
		array(
			'label'       => esc_html__( 'Default Payment Section', 'shop-zen' ),
			'description' => esc_html__( 'Use WooCommerce default payment section with full gateway fields (e.g. credit card inputs). When disabled, the theme card-style payment selector is shown.', 'shop-zen' ),
			'section'     => 'shop_zen_woocommerce_checkout',
			'type'        => 'shop-zen-toggle',
			'settings'    => 'shop_zen_default_checkout_payment',
		)
	));

	/**
	 * 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' );
