<?php
if (!defined('ABSPATH'))
    exit; // Exit if accessed directly

/**
 * Frontpage Testimonial Options.
 *
 * @package pawfect
 */

if (!class_exists('Pawfect_Options_Testimonial')):

    class Pawfect_Options_Testimonial extends pawfect_Customize_Base_Option
    {

        /**
         * Arguments for options.
         *
         * @return array
         */
        public function elements()
        {

            return array(

                'pawfect_main_testimonial_heading' => array(
                    'setting' => array(),
                    'control' => array(
                        'type' => 'heading',
                        'priority' => 1,
                        'label' => esc_html__('Testimonial Options', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                    ),
                ),

                'pawfect_testimonial_enabled' => array(
                    'setting' => array(
                        'default' => true,
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_checkbox'),
                    ),
                    'control' => array(
                        'type' => 'toggle',
                        'priority' => 3,
                        'label' => esc_html__('Enable Testimonial Section', 'pawfect'),
                        'description' => esc_html__('Toggle ON to show this section', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                    ),
                ),

                'pawfect_testimonial_autoplay' => array(
                    'setting' => array(
                        'default' => true,
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_checkbox'),
                    ),
                    'control' => array(
                        'type' => 'toggle',
                        'priority' => 15,
                        'label' => esc_html__('Testimonial Autoplay', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_animation_speed' => array( 
                    'setting' => array(
                        'default' => '4000',
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_radio'),
                    ),
                    'control' => array(
                        'type' => 'select',
                        'priority' => 20,
                        'is_default_type' => true, 
                        'label' => esc_html__('Testimonial Animation Speed', 'pawfect'),
                        'description' => esc_html__('Note: Turn on Autoplay', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'choices' => array(
                            '2000' => esc_html__('2.0', 'pawfect'),
                            '3000' => esc_html__('3.0', 'pawfect'),
                            '4000' => esc_html__('4.0', 'pawfect'),
                            '5000' => esc_html__('5.0', 'pawfect'),
                            '6000' => esc_html__('6.0', 'pawfect'),
                        ),
                        'active_callback' => 'pawfect_testimonial_autoplay_is_enabled',
                    ),
                ),

                'pawfect_testimonial_container_size' => array(
                    'setting' => array(
                        'default' => 'container',
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_radio'),
                    ),
                    'control' => array(
                        'type' => 'radio-switch',
                        'priority' => 25,
                        'label' => esc_html__('Testimonial Width', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'choices' => array(
                            'container' => esc_html__('Container', 'pawfect'),
                            'container-full' => esc_html__('Container Full', 'pawfect'),
                        ),
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),





                'pawfect_testimonial_column_layout' => array(
                    'setting' => array(
                        'default' => 2,
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_radio'),
                    ),
                    'control' => array(
                        'type' => 'simple-radio-image',
                        'priority' => 30,
                        'label' => esc_html__('Desktop Column Layout', 'pawfect'),
                        'description' => esc_html__('Number of columns on medium and large devices (768px+)', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'choices' => array(
                            '2' => PAWFECT_THEME_URL . '/assets/images/icons/column-2.png',
                            '3' => PAWFECT_THEME_URL . '/assets/images/icons/column-3.png',
                            '4' => PAWFECT_THEME_URL . '/assets/images/icons/column-4.png',
                        ),
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),
                'pawfect_testimonial_content' => array(
                    'setting' => array(
                        'sanitize_callback' => 'pawfect_repeater_sanitize',
                        'default' => json_encode(array(
                            array(
                                'title' => esc_html__('Sarah Johnson', 'pawfect'),
                                'subtitle' => esc_html__('Dog Owner', 'pawfect'),
                                'text' => esc_html__('The quality of Pawfect products is outstanding! My golden retriever loves his new collar and bed. Highly recommended for any pet parent who wants the best.', 'pawfect'),
                                'image_url' => get_template_directory_uri() . '/assets/images/testimonial/client-1.webp',
                                'designation' => esc_html__('Pet Parent', 'pawfect'),
                                'id' => 'customizer_repeater_testimonial_001',
                            ),
                            array(
                                'title' => esc_html__('Michael Chen', 'pawfect'),
                                'subtitle' => esc_html__('Cat Owner', 'pawfect'),
                                'text' => esc_html__('Amazing customer service and premium products. My cats are pampered with their new accessories from Pawfect. Worth every penny!', 'pawfect'),
                                'image_url' => get_template_directory_uri() . '/assets/images/testimonial/client-2.webp',
                                'designation' => esc_html__('Happy Customer', 'pawfect'),
                                'id' => 'customizer_repeater_testimonial_002',
                            ),
                        )),
                    ),
                    'control' => array(
                        'type' => 'repeater',
                        'label' => esc_html__('Testimonial Items Content', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'priority' => 20,
                        'add_field_label' => esc_html__('Add new testimonial item', 'pawfect'),
                        'item_name' => esc_html__('Testimonial Item', 'pawfect'),
                        'customizer_repeater_title_control' => true,
                        'customizer_repeater_subtitle_control' => true,
                        'customizer_repeater_text_control' => true,
                        'customizer_repeater_image_control' => true,
                        'customizer_repeater_designation_control' => true,
                        'customizer_repeater_product_select_control' => true,
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                // Upgrade control for testimonial limitation
                'pawfect_testimonial_content_upsale' => array(
                    'setting' => array(
                        'sanitize_callback' => 'sanitize_text_field',
                    ),
                    'control' => array(
                        'type' => 'pawfect-upgrade',
                        'priority' => 21,
                        'label' => esc_html__('Testimonial Features', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),
                'pawfect_testimonial_area_title' => array(
                    'setting' => array(
                        'default' => esc_html__('CUSTOMER FEEDBACKS ABOUT US', 'pawfect'),
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'text',
                        'priority' => 4,
                        'label' => esc_html__('Section Title', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_area_subtitle' => array(
                    'setting' => array(
                        'default' => '',
                        'sanitize_callback' => 'sanitize_text_field',
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'text',
                        'priority' => 4, // 4.5
                        'label' => esc_html__('Section Subtitle', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_area_des' => array(
                    'setting' => array(
                        'default' => esc_html__('Happy Customers!', 'pawfect'),
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'textarea',
                        'priority' => 5,
                        'label' => esc_html__('Section Description', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_background' => array(
                    'setting' => array(
                        'default' => '',
                        'sanitize_callback' => 'esc_url_raw',
                    ),
                    'control' => array(
                        'type' => 'image',
                        'priority' => 6,
                        'label' => esc_html__('Background Image', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_background_color' => array(
                    'setting' => array(
                        'default' => '#f9fafb',
                        'sanitize_callback' => 'sanitize_hex_color',
                    ),
                    'control' => array(
                        'type' => 'color',
                        'priority' => 7,
                        'label' => esc_html__('Background Color', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                // Enhanced Styling Options
                'pawfect_testimonial_card_style' => array(
                    'setting' => array(
                        'default' => 'classic',
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_radio'),
                    ),
                    'control' => array(
                        'type' => 'radio-switch',
                        'priority' => 8,
                        'label' => esc_html__('Card Style', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'choices' => array(
                            'modern' => esc_html__('Modern', 'pawfect'),
                            'classic' => esc_html__('Classic', 'pawfect'),
                            'minimal' => esc_html__('Minimal', 'pawfect'),
                        ),
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_show_ratings' => array(
                    'setting' => array(
                        'default' => true,
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_checkbox'),
                    ),
                    'control' => array(
                        'type' => 'toggle',
                        'priority' => 9,
                        'label' => esc_html__('Show Star Ratings', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_show_products' => array(
                    'setting' => array(
                        'default' => true,
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_checkbox'),
                    ),
                    'control' => array(
                        'type' => 'toggle',
                        'priority' => 10,
                        'label' => esc_html__('Show Related Products', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_text_color' => array(
                    'setting' => array(
                        'default' => '#1f2937',
                        'sanitize_callback' => 'sanitize_hex_color',
                    ),
                    'control' => array(
                        'type' => 'color',
                        'priority' => 11,
                        'label' => esc_html__('Text Color', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_accent_color' => array(
                    'setting' => array(
                        'default' => '#f59e0b',
                        'sanitize_callback' => 'sanitize_hex_color',
                    ),
                    'control' => array(
                        'type' => 'color',
                        'priority' => 12,
                        'label' => esc_html__('Accent Color (Stars, Borders)', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_heading_color' => array(
                    'setting' => array(
                        'default' => '#1f2937',
                        'sanitize_callback' => 'sanitize_hex_color',
                    ),
                    'control' => array(
                        'type' => 'color',
                        'priority' => 13,
                        'label' => esc_html__('Heading Color', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_description_color' => array(
                    'setting' => array(
                        'default' => '#6b7280',
                        'sanitize_callback' => 'sanitize_hex_color',
                    ),
                    'control' => array(
                        'type' => 'color',
                        'priority' => 14,
                        'label' => esc_html__('Description Color', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),

                'pawfect_testimonial_slide_gap' => array(
                    'setting' => array(
                        'default' => 30,
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_number_range'),
                    ),
                    'control' => array(
                        'type' => 'pawfect-slider',
                        'priority' => 15,
                        'label' => esc_html__('Gap Between Slides (px)', 'pawfect'),
                        'section' => 'pawfect_theme_testimonial',
                        'input_attrs' => array(
                            'min' => 0,
                            'max' => 100,
                            'step' => 5,
                        ),
                        'active_callback' => 'pawfect_testimonial_enabled',
                    ),
                ),
            );
        }
    }

    new Pawfect_Options_Testimonial();

endif;

/**
 * Check if testimonial is enabled
 */
function pawfect_testimonial_enabled($control)
{
    // Following main slider pattern - return true when testimonial is enabled
    // This makes other testimonial settings visible when main toggle is ON
    return true === ( $control->manager->get_setting( 'pawfect_testimonial_enabled' )->value() == true );
}


/**
 * Check if testimonial autoplay is enabled
 */
function pawfect_testimonial_autoplay_is_enabled($control)
{
    return get_theme_mod('pawfect_testimonial_enabled', true) === true &&
        get_theme_mod('pawfect_testimonial_autoplay', true) === true;
}




