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

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

/**
 * Register Services section customizer settings
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function paws_and_care_customizer_services($wp_customize)
{

    // Services Section
    $wp_customize->add_section('paws_and_care_services', array(
        'title' => __('Services Settings', 'paws-and-care'),
        'panel' => 'paws_and_care_front_page',
        'priority' => 30,
    ));

    // Enable Services Section
    $wp_customize->add_setting('paws_and_care_services_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_services_enable', array(
        'label' => __('Enable Services Section', 'paws-and-care'),
        'description' => __('Show or hide the services section on homepage', 'paws-and-care'),
        'section' => 'paws_and_care_services',
    )));

    // Content Heading
    $wp_customize->add_setting('paws_and_care_services_content_heading', array(
        'sanitize_callback' => 'sanitize_text_field',
    ));

    $wp_customize->add_control(new Paws_And_Care_Customize_Heading_Control($wp_customize, 'paws_and_care_services_content_heading', array(
        'label' => __('Content Settings', 'paws-and-care'),
        'section' => 'paws_and_care_services',
        'active_callback' => 'paws_and_care_is_services_enabled',
    )));

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

    $wp_customize->add_control('paws_and_care_services_title', array(
        'label' => __('Section Title', 'paws-and-care'),
        'section' => 'paws_and_care_services',
        'type' => 'text',
        'active_callback' => 'paws_and_care_is_services_enabled',
    ));

    // Subtitle
    $wp_customize->add_setting('paws_and_care_services_subtitle', array(
        'default' => __('We offer a comprehensive range of services to keep your pets happy and healthy.', 'paws-and-care'),
        'sanitize_callback' => 'sanitize_text_field',
    ));

    $wp_customize->add_control('paws_and_care_services_subtitle', array(
        'label' => __('Subtitle', 'paws-and-care'),
        'section' => 'paws_and_care_services',
        'type' => 'text',
        'active_callback' => 'paws_and_care_is_services_enabled',
    ));

    // Services Heading
    $wp_customize->add_setting('paws_and_care_services_items_heading', array(
        'sanitize_callback' => 'sanitize_text_field',
    ));

    $wp_customize->add_control(new Paws_And_Care_Customize_Heading_Control($wp_customize, 'paws_and_care_services_items_heading', array(
        'label' => __('Service Items', 'paws-and-care'),
        'section' => 'paws_and_care_services',
        'active_callback' => 'paws_and_care_is_services_enabled',
    )));

    // Services Repeater
    $wp_customize->add_setting('paws_and_care_services_content', array(
        'default' => paws_and_care_get_services_default(),
        'sanitize_callback' => 'paws_and_care_repeater_sanitize',
    ));

    $wp_customize->add_control(new Paws_And_Care_Repeater($wp_customize, 'paws_and_care_services_content', array(
        'label' => __('Services', 'paws-and-care'),
        'section' => 'paws_and_care_services',
        'add_field_label' => __('Add New Service', 'paws-and-care'),
        'item_name' => __('Service', 'paws-and-care'),
        'max_items' => 6,
        'customizer_repeater_title_control' => true,
        'customizer_repeater_text_control' => true,
        'customizer_repeater_text2_control' => true,  // Button Text
        'customizer_repeater_designation_control' => true,  // Features List
        'customizer_repeater_link_control' => true,
        'customizer_repeater_icon_control' => true,
        'customizer_repeater_checkbox_control' => true,
        'active_callback' => 'paws_and_care_is_services_enabled',
    )));

    // Display Settings Heading
    $wp_customize->add_setting('paws_and_care_services_display_heading', array(
        'sanitize_callback' => 'sanitize_text_field',
    ));

    $wp_customize->add_control(new Paws_And_Care_Customize_Heading_Control($wp_customize, 'paws_and_care_services_display_heading', array(
        'label' => __('Display Settings', 'paws-and-care'),
        'section' => 'paws_and_care_services',
        'active_callback' => 'paws_and_care_is_services_enabled',
    )));

    // Show Features Toggle
    $wp_customize->add_setting('paws_and_care_services_show_features', 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_services_show_features', array(
        'label' => __('Show Features List', 'paws-and-care'),
        'description' => __('Display the features list on service cards.', 'paws-and-care'),
        'section' => 'paws_and_care_services',
        'active_callback' => 'paws_and_care_is_services_enabled',
    )));

    // Show Button Toggle
    $wp_customize->add_setting('paws_and_care_services_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_services_show_button', array(
        'label' => __('Show Button', 'paws-and-care'),
        'description' => __('Display the button on service cards.', 'paws-and-care'),
        'section' => 'paws_and_care_services',
        'active_callback' => 'paws_and_care_is_services_enabled',
    )));
}

/**
 * Filter to change labels for services repeater
 */
function paws_and_care_services_repeater_labels($string, $id, $control)
{
    if ($id === 'paws_and_care_services_content') {
        if ($control === 'customizer_repeater_designation_control') {
            return esc_html__('Features (one per line)', 'paws-and-care');
        }
        if ($control === 'customizer_repeater_text2_control') {
            return esc_html__('Button Text', 'paws-and-care');
        }
    }
    return $string;
}
add_filter('paws_and_care_repeater_input_labels_filter', 'paws_and_care_services_repeater_labels', 10, 3);

/**
 * Active callback for services section
 */
function paws_and_care_is_services_enabled()
{
    return get_theme_mod('paws_and_care_services_enable', true);
}

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