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

/**
 * Frontpage Pet Shop Options
 *
 * @package pawfect
 */

if ( ! class_exists( 'Pawfect_Options_Pet_Shop' ) ) :

    class Pawfect_Options_Pet_Shop extends pawfect_Customize_Base_Option {

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

            return array(

                'pawfect_pet_shop_heading' => array(
                    'setting' => array(),
                    'control' => array(
                        'type' => 'heading',
                        'priority' => 1,
                        'label' => esc_html__( 'Pet Shop Section Options', 'pawfect' ),
                        'section' => 'pawfect_pet_shop_section',
                    ),
                ),
                
                'pawfect_pet_shop_enabled' => array(
                    'setting' => array(
                        'default' => true,
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_checkbox' ),
                    ),
                    'control' => array(
                        'type' => 'toggle',
                        'priority' => 2,
                        'label' => esc_html__( 'Enable Pet Shop Section', 'pawfect' ),
                        'description' => esc_html__( 'Toggle ON to show this section', 'pawfect' ),
                        'section' => 'pawfect_pet_shop_section',
                    ),
                ),

                'pawfect_pet_shop_subtitle' => array(
                    'setting' => array(
                        'default' => esc_html__( 'Pet Categories', 'pawfect' ),
                        'sanitize_callback' => 'sanitize_text_field',
                        'transport' => 'postMessage',
                    ),
                    'control' => array(
                        'type' => 'text',
                        'priority' => 2,
                        'label' => esc_html__( 'Section Subtitle', 'pawfect' ),
                        'section' => 'pawfect_pet_shop_section',
                        'active_callback' => 'pawfect_pet_shop_enabled',
                    ),
                ),

                'pawfect_pet_shop_title' => array(
                    'setting' => array(
                        'default' => esc_html__( 'Shop By Pets', 'pawfect' ),
                        'sanitize_callback' => 'sanitize_text_field'
                    ),
                    'control' => array(
                        'type' => 'text',
                        'priority' => 3,
                        'label' => esc_html__( 'Section Title', 'pawfect' ),
                        'section' => 'pawfect_pet_shop_section',
                        'active_callback' => 'pawfect_pet_shop_enabled',
                    ),
                ),

                'pawfect_pet_shop_desc' => array(
                    'setting' => array(
                        'default' => esc_html__( 'We create thoughtful, high-quality essentials that keep tails wagging â€” and hearts full.', 'pawfect' ),
                        'sanitize_callback' => 'sanitize_textarea_field'
                    ),
                    'control' => array(
                        'type' => 'textarea',
                        'priority' => 4,
                        'label' => esc_html__( 'Section Description', 'pawfect' ),
                        'section' => 'pawfect_pet_shop_section',
                        'active_callback' => 'pawfect_pet_shop_enabled',
                    ),
                ),

                'pawfect_pet_shop_items' => array(
                    'setting' => array(
                        'default' => json_encode([
                            [
                                'title' => esc_html__( 'Dogs', 'pawfect' ),
                                'image_url' => get_template_directory_uri() . '/assets/images/pets/dog.webp',
                                'link' => '/shop/dogs',
                                'text' => esc_html__( 'Everything for your loyal companion', 'pawfect' )
                            ],
                            [
                                'title' => esc_html__( 'Cats', 'pawfect' ),
                                'image_url' => get_template_directory_uri() . '/assets/images/pets/cat.webp',
                                'link' => '/shop/cats',
                                'text' => esc_html__( 'Premium products for feline friends', 'pawfect' )
                            ],
                            [
                                'title' => esc_html__( 'Birds', 'pawfect' ),
                                'image_url' => get_template_directory_uri() . '/assets/images/pets/bird.webp',
                                'link' => '/shop/birds',
                                'text' => esc_html__( 'Quality care for feathered companions', 'pawfect' )
                            ]
                        ]),
                        'sanitize_callback' => 'wp_kses_post',
                    ),
                    'control' => array(
                        'type' => 'repeater',
                        'priority' => 5,
                        'label' => esc_html__( 'Pet Shop Items', 'pawfect' ),
                        'section' => 'pawfect_pet_shop_section',
                        'add_field_label' => esc_html__('Add new pet category', 'pawfect'),
                        'item_name' => esc_html__('Pet Category', 'pawfect'),
                        'customizer_repeater_image_control' => true,
                        'customizer_repeater_title_control' => true,
                        'customizer_repeater_text_control' => true,
                        'customizer_repeater_link_control' => true,
                        'customizer_repeater_icon_control' => false,
                        'customizer_repeater_checkbox_control' => true,
                        'customizer_repeater_button_text_control' => false,
                        'active_callback' => 'pawfect_pet_shop_enabled',
                    ),
                ),

                // Upgrade control for pet shop limitation
                'pawfect_pet_shop_items_upsale' => array(
                    'setting' => array(
                        'sanitize_callback' => 'sanitize_text_field',
                    ),
                    'control' => array(
                        'type' => 'pawfect-upgrade',
                        'priority' => 6,
                        'label' => esc_html__('Pet Shop Features', 'pawfect'),
                        'section' => 'pawfect_pet_shop_section',
                        'active_callback' => 'pawfect_pet_shop_enabled',
                    ),
                ),

                'pawfect_pet_shop_container_size' => array(
                    'setting' => array(
                        'default' => 'pawfect-container',
                        'sanitize_callback' => array( 'pawfect_Customizer_Sanitize', 'sanitize_radio' ),
                    ),
                    'control' => array(
                        'type' => 'radio-switch',
                        'priority' => 6,
                        'label' => esc_html__( 'Container Width', 'pawfect' ),
                        'section' => 'pawfect_pet_shop_section',
                        'choices' => array(
                            'pawfect-container-small' => esc_html__( 'Small Container', 'pawfect' ),
                            'pawfect-container' => esc_html__( 'Standard Container', 'pawfect' ),
                            'pawfect-container-full' => esc_html__( 'Full Width Container', 'pawfect' ),
                        ),
                        'active_callback' => 'pawfect_pet_shop_enabled',
                    ),
                ),

              
                 'pawfect_pet_shop_column_layout' => array( 
                    'setting' => array(
                        'default' => 3,
                        'sanitize_callback' => array('pawfect_Customizer_Sanitize', 'sanitize_radio'),
                    ),
                    'control' => array(
                        'type' => 'select',
                        'priority' => 20,
                        'is_default_type' => true,
                        'label' => esc_html__( 'Column Layout', 'pawfect' ),
                        'section' => 'pawfect_pet_shop_section',
                        'choices' => array(
                            '1' => esc_html__('1', 'pawfect'),
                            '2' => esc_html__('2', 'pawfect'),
                            '3' => esc_html__('3', 'pawfect'),
                            '4' => esc_html__('4', 'pawfect'),
                            '5' => esc_html__('5', 'pawfect'),
                        ),
                        'active_callback' => 'pawfect_pet_shop_enabled',
                    ),
                ),



            );
        }

    }

    new Pawfect_Options_Pet_Shop();

endif;

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


