<?php
if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * Customizer settings for the "Why Choose Pawfect" section
 */

if ( ! class_exists( 'Pawfect_Customize_Why_Choose_Option' ) ) :

class Pawfect_Customize_Why_Choose_Option extends pawfect_Customize_Base_Option {

    public function elements() {
        return [

            'pawfect_why_choose_heading' => [
                'setting' => [
                    'default' => 'Why Choose Options',
                    'sanitize_callback' => 'sanitize_text_field',
                ],
                'control' => [
                    'type'    => 'heading',
                    'label'   => esc_html__( 'Why Choose Options', 'pawfect' ),
                    'section' => 'pawfect_theme_service',
                    'priority' => 45,
                ],
            ],

            'pawfect_service_area_enabled' => [
             
                 'setting' => array( 
                        'default'           => true,
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_checkbox' ),
                    ),
                'control' => [
                    'type'    => 'toggle',
                    'label'   => esc_html__( 'Enable Why Choose Section', 'pawfect' ),
                    'section' => 'pawfect_theme_service',
                    'priority' => 46,
                ],
            ],

            'pawfect_service_area_title' => [
                'setting' => [
                    'default' => 'Why Choose Pawfect?',
                    'sanitize_callback' => 'sanitize_text_field',
                ],
                'control' => [
                    'type'    => 'text',
                    'label'   => esc_html__( 'Section Title', 'pawfect' ),
                    'section' => 'pawfect_theme_service',
                    'priority' => 47,
                   'active_callback' => 'pawfect_service_area_disabled',
                ],
            ],

            'pawfect_service_area_des' => [
                'setting' => [
                    'default' => 'We create thoughtful, high-quality essentials that keep tails wagging â€” and hearts full.',
                    'sanitize_callback' => 'sanitize_textarea_field',
                ],
                'control' => [
                    'type'    => 'textarea',
                    'label'   => esc_html__( 'Section Description', 'pawfect' ),
                    'section' => 'pawfect_theme_service',
                    'priority' => 48,
                   'active_callback' => 'pawfect_service_area_disabled',
                ],
            ],

            'pawfect_service_column_layout' => [
                'setting' => [
                    'default' => 'col-md-4',
                    'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_radio'),
                ],
                'control' => [
                    'type'    => 'simple-radio-image',
                    'label'   => esc_html__( 'Column Layout', 'pawfect' ),
                    'section' => 'pawfect_theme_service',
                    'priority' => 49,
                    'choices' => [
                        'col-md-6' => PAWFECT_THEME_URL . '/assets/images/icons/column-2.png',
                        'col-md-4' => PAWFECT_THEME_URL . '/assets/images/icons/column-3.png',
                        'col-md-3' => PAWFECT_THEME_URL . '/assets/images/icons/column-4.png',
                    ],
                   'active_callback' => 'pawfect_service_area_disabled',
                ],
            ],

            'pawfect_service_count' => [
                'setting' => [
                    'default' => array('slider' => 4),
                    'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_slider'),
                ],
                'control' => [
                    'type'    => 'pawfect-slider',
                    'label'   => esc_html__( 'Number of Items to Show', 'pawfect' ),
                    'section' => 'pawfect_theme_service',
                    'priority' => 50,
                    'input_attrs' => [
                        'min'  => 2,
                        'max'  => 12,
                        'step' => 1,
                    ],
                   'active_callback' => 'pawfect_service_area_disabled',
                ],
            ],

            'pawfect_service_content' => [
                'setting' => [
                    'default' => json_encode(array(
                        array(
                            'title' => esc_html__('Premium Quality', 'pawfect'),
                            'text' => esc_html__('Only the finest materials and craftsmanship for your beloved pets.', 'pawfect'),
                            'image_url' => get_template_directory_uri() . '/assets/images/hero-up.webp',
                            'icon_value' => 'fa-star',
                            'id' => 'customizer_repeater_why_001',
                        ),
                        array(
                            'title' => esc_html__('Expert Care', 'pawfect'),
                            'text' => esc_html__('Designed by veterinarians and pet care specialists.', 'pawfect'),
                            'image_url' => get_template_directory_uri() . '/assets/images/hero-up.webp',
                            'icon_value' => 'fa-heart',
                            'id' => 'customizer_repeater_why_002',
                        ),
                        array(
                            'title' => esc_html__('Trusted Brand', 'pawfect'),
                            'text' => esc_html__('Thousands of happy pet parents trust our products worldwide.', 'pawfect'),
                            'image_url' => get_template_directory_uri() . '/assets/images/hero-up.webp',
                            'icon_value' => 'fa-shield',
                            'id' => 'customizer_repeater_why_003',
                        ),
                    )),
                    'sanitize_callback' => 'wp_kses_post',
                    'transport' => 'postMessage', // Enable selective refresh
                ],
                'control' => [
                    'type'    => 'repeater',
                    'label'   => esc_html__( 'Why Choose Items', 'pawfect' ),
                    'section' => 'pawfect_theme_service',
                    'priority' => 51,
                    'add_field_label' => esc_html__('Add new item', 'pawfect'),
                    'item_name' => esc_html__('Why Choose Item', 'pawfect'),
                    'customizer_repeater_title_control' => true,
                    'customizer_repeater_text_control' => true,
                    'customizer_repeater_image_control' => true,
                    'customizer_repeater_icon_control' => true,
                    'customizer_repeater_svg_control' => true,
                    'active_callback' => 'pawfect_service_area_disabled',
                ],
            ],

            // Upgrade control for why choose limitation
            'pawfect_service_content_upsale' => array(
                'setting' => array(
                    'sanitize_callback' => 'sanitize_text_field',
                ),
                'control' => array(
                    'type' => 'pawfect-upgrade',
                    'priority' => 52,
                    'label' => esc_html__('Why Choose Features', 'pawfect'),
                    'section' => 'pawfect_theme_service',
                    'active_callback' => 'pawfect_service_area_disabled',
                ),
            ),

        ];
    }

  
}

new Pawfect_Customize_Why_Choose_Option();

endif;



function pawfect_service_area_disabled($control)
{
    // Following main slider pattern - return true when section is enabled
    // This makes other settings visible when the main toggle is ON
    return true === ( $control->manager->get_setting( 'pawfect_service_area_enabled' )->value() == true );
}



