<?php
/**
 * WooCommerce Product Single 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_product_register' ) ) :
function pawwell_customizer_woocommerce_product_register( $wp_customize ) {

	/**
	 * Section: Product Single (under the WooCommerce panel)
	 */
	$wp_customize->add_section(
		'pawwell_woocommerce_product_single',
		array(
			'title'    => esc_html__( 'Product Single', 'pawwell' ),
			'panel'    => 'woocommerce',
			'priority' => 25,
		)
	);

	/* ── Trust Info Boxes ── */

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

	$wp_customize->add_control(
		new Pawwell_Title_Info_Control( $wp_customize, 'pawwell_pd_trust_label',
		array(
			'label'    => esc_html__( 'Trust Info Boxes', 'pawwell' ),
			'section'  => 'pawwell_woocommerce_product_single',
			'type'     => 'pawwell-title',
			'settings' => 'pawwell_pd_trust_label',
		)
	));

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

	$wp_customize->add_control(
		new Pawwell_Toggle_Control( $wp_customize, 'pawwell_pd_trust_enable',
		array(
			'label'       => esc_html__( 'Show Trust Info Boxes', 'pawwell' ),
			'description' => esc_html__( 'Display the trust / feature info strip below the Add to Cart button.', 'pawwell' ),
			'section'     => 'pawwell_woocommerce_product_single',
			'type'        => 'pawwell-toggle',
			'settings'    => 'pawwell_pd_trust_enable',
		)
	));

	/**
	 * Register 4 trust items via a data-driven loop.
	 */
	$trust_items = array(
		array(
			'key'     => '1',
			'label'   => esc_html__( 'Info Box 1', 'pawwell' ),
			'icon'    => 'truck',
			'title'   => __( 'Free Shipping', 'pawwell' ),
			'desc'    => __( 'On orders over $49', 'pawwell' ),
		),
		array(
			'key'     => '2',
			'label'   => esc_html__( 'Info Box 2', 'pawwell' ),
			'icon'    => 'refresh-cw',
			'title'   => __( 'Easy Returns', 'pawwell' ),
			'desc'    => __( '30-day money back', 'pawwell' ),
		),
		array(
			'key'     => '3',
			'label'   => esc_html__( 'Info Box 3', 'pawwell' ),
			'icon'    => 'stethoscope',
			'title'   => __( 'Vet Consultation', 'pawwell' ),
			'desc'    => __( 'Free first session', 'pawwell' ),
		),
		array(
			'key'     => '4',
			'label'   => esc_html__( 'Info Box 4', 'pawwell' ),
			'icon'    => 'shield-check',
			'title'   => __( 'Secure Payment', 'pawwell' ),
			'desc'    => __( '100% protected', 'pawwell' ),
		),
	);

	$icon_choices = array(
		'truck'         => esc_html__( 'Truck (Shipping)', 'pawwell' ),
		'refresh-cw'    => esc_html__( 'Refresh (Returns)', 'pawwell' ),
		'stethoscope'   => esc_html__( 'Stethoscope (Vet)', 'pawwell' ),
		'shield-check'  => esc_html__( 'Shield (Security)', 'pawwell' ),
		'check-circle'  => esc_html__( 'Check Circle', 'pawwell' ),
		'heart'         => esc_html__( 'Heart', 'pawwell' ),
		'shopping-bag'  => esc_html__( 'Shopping Bag', 'pawwell' ),
		'star'          => esc_html__( 'Star', 'pawwell' ),
	);

	foreach ( $trust_items as $item ) {

		$prefix = 'pawwell_pd_trust_' . $item['key'];

		// Sub-heading
		$wp_customize->add_setting(
			$prefix . '_label',
			array(
				'sanitize_callback' => 'pawwell_sanitize_title',
			)
		);

		$wp_customize->add_control(
			new Pawwell_Title_Info_Control( $wp_customize, $prefix . '_label',
			array(
				'label'    => $item['label'],
				'section'  => 'pawwell_woocommerce_product_single',
				'type'     => 'pawwell-title',
				'settings' => $prefix . '_label',
			)
		));

		// Enable
		$wp_customize->add_setting(
			$prefix . '_enable',
			array(
				'default'           => true,
				'type'              => 'theme_mod',
				'sanitize_callback' => 'pawwell_sanitize_checkbox',
			)
		);

		$wp_customize->add_control(
			new Pawwell_Toggle_Control( $wp_customize, $prefix . '_enable',
			array(
				'label'    => esc_html__( 'Enable', 'pawwell' ),
				'section'  => 'pawwell_woocommerce_product_single',
				'type'     => 'pawwell-toggle',
				'settings' => $prefix . '_enable',
			)
		));

		// Icon
		$wp_customize->add_setting(
			$prefix . '_icon',
			array(
				'default'           => $item['icon'],
				'type'              => 'theme_mod',
				'sanitize_callback' => 'pawwell_sanitize_select',
			)
		);

		$wp_customize->add_control(
			$prefix . '_icon',
			array(
				'settings'  => $prefix . '_icon',
				'section'   => 'pawwell_woocommerce_product_single',
				'type'      => 'select',
				'label'     => esc_html__( 'Icon', 'pawwell' ),
				'choices'   => $icon_choices,
			)
		);

		// Title
		$wp_customize->add_setting(
			$prefix . '_title',
			array(
				'default'           => $item['title'],
				'type'              => 'theme_mod',
				'sanitize_callback' => 'pawwell_sanitize_text_field',
			)
		);

		$wp_customize->add_control(
			$prefix . '_title',
			array(
				'settings'  => $prefix . '_title',
				'section'   => 'pawwell_woocommerce_product_single',
				'type'      => 'text',
				'label'     => esc_html__( 'Title', 'pawwell' ),
			)
		);

		// Description
		$wp_customize->add_setting(
			$prefix . '_desc',
			array(
				'default'           => $item['desc'],
				'type'              => 'theme_mod',
				'sanitize_callback' => 'pawwell_sanitize_text_field',
			)
		);

		$wp_customize->add_control(
			$prefix . '_desc',
			array(
				'settings'  => $prefix . '_desc',
				'section'   => 'pawwell_woocommerce_product_single',
				'type'      => 'text',
				'label'     => esc_html__( 'Description', 'pawwell' ),
			)
		);
	}
}
endif;

add_action( 'customize_register', 'pawwell_customizer_woocommerce_product_register' );
