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

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

/**
 * Add Slider customizer settings
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function paws_and_care_customizer_slider($wp_customize)
{

    // ========================================
    // Slider Section
    // ========================================
    $wp_customize->add_section('paws_and_care_slider', array(
        'title' => __('Slider Settings', 'paws-and-care'),
        'panel' => 'paws_and_care_front_page',
        'priority' => 10,
    ));

    // Enable Slider - Toggle Control
    $wp_customize->add_setting('paws_and_care_slider_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_slider_enable', array(
        'label' => __('Enable Slider Section', 'paws-and-care'),
        'section' => 'paws_and_care_slider',
    )));

    // Content Settings Heading
    $wp_customize->add_setting('paws_and_care_slider_content_heading', array(
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control(new Paws_And_Care_Customize_Heading_Control($wp_customize, 'paws_and_care_slider_content_heading', array(
        'label' => __('Content Settings', 'paws-and-care'),
        'section' => 'paws_and_care_slider',
        'active_callback' => 'paws_and_care_is_slider_enabled',
    )));

    // Slider Content Repeater
    $wp_customize->add_setting('paws_and_care_slider_content', array(
        'default' => paws_and_care_get_slider_default(),
        'sanitize_callback' => 'paws_and_care_repeater_sanitize',
    ));

    $wp_customize->add_control(new Paws_And_Care_Repeater($wp_customize, 'paws_and_care_slider_content', array(
        'label' => __('Slider Slides', 'paws-and-care'),
        'section' => 'paws_and_care_slider',
        'add_field_label' => __('Add New Slide', 'paws-and-care'),
        'item_name' => __('Slide', 'paws-and-care'),
        'max_items' => 6,
        'customizer_repeater_title_control' => true,
        'customizer_repeater_image_control' => true,
        'customizer_repeater_text2_control' => true,
        'customizer_repeater_link_control' => true,
        'customizer_repeater_checkbox_control' => true,
        'active_callback' => 'paws_and_care_is_slider_enabled',
    )));

    // Extra Settings Heading
    $wp_customize->add_setting('paws_and_care_slider_extra_heading', array(
        'sanitize_callback' => 'sanitize_text_field',
    ));
    $wp_customize->add_control(new Paws_And_Care_Customize_Heading_Control($wp_customize, 'paws_and_care_slider_extra_heading', array(
        'label' => __('Extra Settings', 'paws-and-care'),
        'section' => 'paws_and_care_slider',
        'active_callback' => 'paws_and_care_is_slider_enabled',
    )));

    // Carousel Caption Background Color - Alpha Color Picker
    $wp_customize->add_setting('paws_and_care_slider_caption_bg', array(
        'default' => 'rgba(0,0,0,0.5)',
        'sanitize_callback' => 'paws_and_care_sanitize_rgba_color',
    ));
    $wp_customize->add_control(new Paws_And_Care_Customize_Color_Control($wp_customize, 'paws_and_care_slider_caption_bg', array(
        'label' => __('Caption Box Background', 'paws-and-care'),
        'description' => __('Select color with transparency', 'paws-and-care'),
        'section' => 'paws_and_care_slider',
        'choices' => array(
            'alpha' => true,
        ),
        'active_callback' => 'paws_and_care_is_slider_enabled',
    )));

    // Slider Height Control - Range Slider
    $wp_customize->add_setting('paws_and_care_slider_height', array(
        'default' => 100,
        'sanitize_callback' => 'absint',
        'transport' => 'refresh',
    ));
    $wp_customize->add_control(new Paws_And_Care_Customize_Range_Control($wp_customize, 'paws_and_care_slider_height', array(
        'label' => __('Slider Height (%)', 'paws-and-care'),
        'description' => __('Height as percentage of viewport (50-100)', 'paws-and-care'),
        'section' => 'paws_and_care_slider',
        'input_attrs' => array(
            'min' => 50,
            'max' => 100,
            'step' => 5,
        ),
        'active_callback' => 'paws_and_care_is_slider_enabled',
    )));

    // Slider Image Position - Select Control
    $wp_customize->add_setting('paws_and_care_slider_image_position', array(
        'default' => 'bottom',
        'sanitize_callback' => 'paws_and_care_sanitize_select',
    ));
    $wp_customize->add_control('paws_and_care_slider_image_position', array(
        'label' => __('Image Position', 'paws-and-care'),
        'description' => __('Vertical position of the slider image', 'paws-and-care'),
        'section' => 'paws_and_care_slider',
        'type' => 'select',
        'choices' => array(
            'top' => __('Top', 'paws-and-care'),
            'center' => __('Center', 'paws-and-care'),
            'bottom' => __('Bottom', 'paws-and-care'),
        ),
        'active_callback' => 'paws_and_care_is_slider_enabled',
    ));

    // Slider Autoplay - Toggle Control
    $wp_customize->add_setting('paws_and_care_slider_autoplay', 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_slider_autoplay', array(
        'label' => __('Enable Autoplay', 'paws-and-care'),
        'description' => __('Automatically cycle through slides', 'paws-and-care'),
        'section' => 'paws_and_care_slider',
        'active_callback' => 'paws_and_care_is_slider_enabled',
    )));

    // Slider Interval - Range Slider Control
    $wp_customize->add_setting('paws_and_care_slider_interval', array(
        'default' => 5000,
        'sanitize_callback' => 'absint',
    ));
    $wp_customize->add_control(new Paws_And_Care_Customize_Range_Control($wp_customize, 'paws_and_care_slider_interval', array(
        'label' => __('Autoplay Interval (ms)', 'paws-and-care'),
        'description' => __('Time between slides in milliseconds', 'paws-and-care'),
        'section' => 'paws_and_care_slider',
        'input_attrs' => array(
            'min' => 1000,
            'max' => 20000,
            'step' => 500,
        ),
        'active_callback' => 'paws_and_care_is_slider_autoplay_enabled',
    )));

    // Slider Touch/Drag - Toggle Control
    $wp_customize->add_setting('paws_and_care_slider_touch', 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_slider_touch', array(
        'label' => __('Enable Touch/Swipe', 'paws-and-care'),
        'description' => __('Allow touch swipe on mobile devices', 'paws-and-care'),
        'section' => 'paws_and_care_slider',
        'active_callback' => 'paws_and_care_is_slider_enabled',
    )));

    // Slider Mouse Drag - Toggle Control
    $wp_customize->add_setting('paws_and_care_slider_mouse_drag', 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_slider_mouse_drag', array(
        'label' => __('Enable Mouse Drag', 'paws-and-care'),
        'description' => __('Allow mouse drag on desktop', 'paws-and-care'),
        'section' => 'paws_and_care_slider',
        'active_callback' => 'paws_and_care_is_slider_enabled',
    )));
}

/**
 * Active callback: Check if slider is enabled
 */
function paws_and_care_is_slider_enabled()
{
    return (bool) get_theme_mod('paws_and_care_slider_enable', true);
}

/**
 * Active callback: Check if slider AND autoplay are enabled
 */
function paws_and_care_is_slider_autoplay_enabled()
{
    $slider_enabled = (bool) get_theme_mod('paws_and_care_slider_enable', true);
    $autoplay_enabled = (bool) get_theme_mod('paws_and_care_slider_autoplay', true);
    return $slider_enabled && $autoplay_enabled;
}

// Default function moved to inc/customizer/defaults.php

