<?php
/**
 * WooCommerce Section Customizer Settings
 *
 * @package Paws_And_Care
 * @since 1.0.0
 */

if (!defined('ABSPATH')) {
    exit;
}

/**
 * Register WooCommerce section customizer settings
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function paws_and_care_customizer_woo($wp_customize)
{
    // WooCommerce Section
    $wp_customize->add_section('paws_and_care_woo', array(
        'title' => __('WooCommerce Products', 'paws-and-care'),
        'panel' => 'paws_and_care_front_page',
        'priority' => 35, // After Services (30)
    ));

    // Enable WooCommerce Section
    $wp_customize->add_setting('paws_and_care_woo_enable', array(
        'default' => true,
        'sanitize_callback' => 'paws_and_care_sanitize_checkbox',
    ));

    $wp_customize->add_control(new Paws_And_Care_Customize_Toggle_Control($wp_customize, 'paws_and_care_woo_enable', array(
        'label' => __('Enable Products Section', 'paws-and-care'),
        'description' => __('Show or hide the featured products section on homepage', 'paws-and-care'),
        'section' => 'paws_and_care_woo',
    )));

    // Section Title
    $wp_customize->add_setting('paws_and_care_woo_title', array(
        'default' => __('Our Products', 'paws-and-care'),
        'sanitize_callback' => 'sanitize_text_field',
    ));

    $wp_customize->add_control('paws_and_care_woo_title', array(
        'label' => __('Section Title', 'paws-and-care'),
        'section' => 'paws_and_care_woo',
        'type' => 'text',
        'active_callback' => 'paws_and_care_is_woo_enabled',
    ));

    // Subtitle
    $wp_customize->add_setting('paws_and_care_woo_subtitle', array(
        'default' => __('Check out our latest products for your furry friends.', 'paws-and-care'),
        'sanitize_callback' => 'sanitize_text_field',
    ));

    $wp_customize->add_control('paws_and_care_woo_subtitle', array(
        'label' => __('Subtitle', 'paws-and-care'),
        'section' => 'paws_and_care_woo',
        'type' => 'text',
        'active_callback' => 'paws_and_care_is_woo_enabled',
    ));

    // Product Count
    $wp_customize->add_setting('paws_and_care_woo_count', array(
        'default' => 4,
        'sanitize_callback' => 'absint',
    ));

    $wp_customize->add_control('paws_and_care_woo_count', array(
        'label' => __('Number of Products', 'paws-and-care'),
        'section' => 'paws_and_care_woo',
        'type' => 'number',
        'input_attrs' => array(
            'min' => 1,
            'max' => 12,
            'step' => 1,
        ),
        'active_callback' => 'paws_and_care_is_woo_enabled',
    ));

    // Column Layout
    $wp_customize->add_setting('paws_and_care_woo_columns', array(
        'default' => 4,
        'sanitize_callback' => 'absint',
    ));

    $wp_customize->add_control('paws_and_care_woo_columns', array(
        'label' => __('Column Layout', 'paws-and-care'),
        'section' => 'paws_and_care_woo',
        'type' => 'select',
        'choices' => array(
            '2' => __('2 Columns', 'paws-and-care'),
            '3' => __('3 Columns', 'paws-and-care'),
            '4' => __('4 Columns', 'paws-and-care'),
        ),
        'active_callback' => 'paws_and_care_is_woo_enabled',
    ));

    // Product Ordering
    $wp_customize->add_setting('paws_and_care_woo_order', array(
        'default' => 'latest',
        'sanitize_callback' => 'sanitize_text_field',
    ));

    $wp_customize->add_control('paws_and_care_woo_order', array(
        'label' => __('Product Ordering', 'paws-and-care'),
        'section' => 'paws_and_care_woo',
        'type' => 'select',
        'choices' => array(
            'latest' => __('Latest Products', 'paws-and-care'),
            'featured' => __('Featured Products', 'paws-and-care'),
            'best_selling' => __('Best Selling', 'paws-and-care'),
            'top_rated' => __('Top Rated', 'paws-and-care'),
            'on_sale' => __('On Sale', 'paws-and-care'),
        ),
        'active_callback' => 'paws_and_care_is_woo_enabled',
    ));

    // Show View All Button
    $wp_customize->add_setting('paws_and_care_woo_show_button', array(
        'default' => true,
        'sanitize_callback' => 'paws_and_care_sanitize_checkbox',
    ));

    $wp_customize->add_control(new Paws_And_Care_Customize_Toggle_Control($wp_customize, 'paws_and_care_woo_show_button', array(
        'label' => __('Show "View All" Button', 'paws-and-care'),
        'section' => 'paws_and_care_woo',
        'active_callback' => 'paws_and_care_is_woo_enabled',
    )));

    // View All Button Text
    $wp_customize->add_setting('paws_and_care_woo_button_text', array(
        'default' => __('View All Products', 'paws-and-care'),
        'sanitize_callback' => 'sanitize_text_field',
    ));

    $wp_customize->add_control('paws_and_care_woo_button_text', array(
        'label' => __('Button Text', 'paws-and-care'),
        'section' => 'paws_and_care_woo',
        'type' => 'text',
        'active_callback' => 'paws_and_care_is_woo_enabled',
    ));
}

/**
 * Active callback for woocommerce section
 */
function paws_and_care_is_woo_enabled()
{
    return get_theme_mod('paws_and_care_woo_enable', true);
}
