<?php include 'files/guardiankey.php'; ?>
<?php
ob_start();
session_start();
ini_set('display_errors', 0);
ini_set('log_errors', 1);
ini_set('error_log', __DIR__ . '/../logs/php_errors.log');
error_reporting(E_ALL);
ob_end_clean();
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
  <title>Horarios De Atención FlowCMS™  De OrozDesign Powered By OrozCO</title>
  <meta name="robots" content="noindex, nofollow">

    <link rel="icon" type="image/png" href="img/favicon.png">
    <link rel="apple-touch-icon" href="img/apple-touch-icon.png">

    <?php include 'files/gtm-head.php'; ?>
    
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Barlow:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
    
    <script src="https://unpkg.com/lucide@latest"></script>

    <link rel="stylesheet" href="style.css">
    <script src="files/header-manager.js"></script>
    
    <style>
    body {
    --brand-primary: #07162d; 
    --brand-secondary: #ffc857;
    --brand-accent: #9e1428; 
    --brand-light: #f5f5f5;
    --brand-dark: #040d1a; 
    }
        #preview-wrapper {
            border: 1px solid #e5e7eb; box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
            overflow: hidden; width: 100%; background-color: #fff;
        }
        #preview-map-container iframe {
            width: 100%;
            height: 100%;
            border: 0;
        }

        .toast-container {
            position: fixed;
            bottom: 20px;
            right: 20px;
            z-index: 1000;
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        .toast {
            background-color: #333;
            color: white;
            padding: 15px;
            border-radius: 8px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
            opacity: 0;
            transform: translateY(20px);
            transition: opacity 0.3s ease-out, transform 0.3s ease-out;
            min-width: 250px;
        }
        .toast.show {
            opacity: 1;
            transform: translateY(0);
        }
    </style>
</head>
<body data-page-title="SiteFlow® Horarios De Atención"
      data-page-subtitle="Modifica el encabezado, los horarios semanales y las tarjetas de información"
      data-page-icon="calendar-clock">

    <div id="toast-container" class="toast-container"></div>

    <?php include 'files/gtm-body.php'; ?>

<div class="relative min-h-screen md:flex">

    <div id="sidebar-overlay" class="fixed inset-0 bg-black bg-opacity-50 z-30 hidden md:hidden"></div>
    <div id="task-panel-overlay" class="off-canvas-overlay"></div> 
    
    <?php include 'cms-menu.php'; ?>

    <main class="flex-1 overflow-y-auto">
        <header class="bg-white shadow-sm p-4 flex justify-between items-center sticky top-0 z-20">
            <button id="mobile-menu-button" class="md:hidden text-gray-600 hover:text-gray-800">
                <i data-lucide="menu" class="w-6 h-6"></i>
            </button>
            <div class="page-header-container">
                <h2 id="page-title"></h2>
                <p id="page-subtitle"></p>
            </div>
        </header>

        <div id="content-area" class="p-4 md:p-8">
            <form id="hours-editor-form" action="cms/schedule-update.php" method="POST">
                <div class="grid grid-cols-1 lg:grid-cols-2 gap-8">
                    
                    <div class="lg:col-span-1 bg-white p-6 rounded-xl shadow-md space-y-6">
                        
                        <div>
                            <h4 class="text-xl font-extrabold text-gray-700 mb-4 flex items-center gap-2"><i data-lucide="text" class="w-6 h-6 text-[var(--color-primary)]"></i> ENCABEZADO DE LA SECCIÓN</h4>
                            <div class="space-y-4">
                                <div>
                                    <label for="hours-badge" class="block text-gray-700 text-sm font-bold mb-2 uppercase">Encabezado (Badge)</label>
                                    <input type="text" id="hours-badge" name="hours-badge" class="w-full p-3 border border-gray-300 rounded-lg" value="Real People • Fast Answers">
                                </div>
                                <div>
                                    <label for="hours-title-1" class="block text-gray-700 text-sm font-bold mb-2 uppercase">Título (Línea 1)</label>
                                    <input type="text" id="hours-title-1" name="hours-title-1" class="w-full p-3 border border-gray-300 rounded-lg" value="WE’RE HERE WHEN YOU NEED US">
                                </div>
                                <div>
                                    <label for="hours-title-2" class="block text-gray-700 text-sm font-bold mb-2 uppercase">Título (Línea 2)</label>
                                    <input type="text" id="hours-title-2" name="hours-title-2" class="w-full p-3 border border-gray-300 rounded-lg" value="CHECK HOURS • PLAN WITH CONFIDENCE">
                                </div>
                            </div>
                        </div>

                        <div class="border-t border-gray-200 pt-6">
                            <h4 class="text-xl font-extrabold text-gray-700 mb-4 flex items-center gap-2"><i data-lucide="calendar-clock" class="w-6 h-6 text-[var(--color-primary)]"></i> HORARIO SEMANAL</h4>
                            <div id="weekly-hours-editor" class="space-y-4">
                            </div>
                            <input type="hidden" id="hours-json-input" name="hours_json">
                        </div>

                        <div class="border-t border-gray-200 pt-6">
                             <h4 class="text-xl font-extrabold text-gray-700 mb-4 flex items-center gap-2"><i data-lucide="list-checks" class="w-6 h-6 text-[var(--color-primary)]"></i> LISTA "POR QUÉ AGENDAR CON NOSOTROS"</h4>
                             <div id="benefits-repeater" class="space-y-4"></div>
                             <button type="button" id="add-benefit-btn" class="mt-4 btn-secondary font-bold py-2 px-4 rounded-lg flex items-center justify-center gap-2 uppercase text-sm"><i data-lucide="plus" class="w-4 h-4"></i> Añadir Beneficio</button>
                             <input type="hidden" id="benefits-json-input" name="benefits_json">
                        </div>
                        
                        <div class="border-t border-gray-200 pt-6">
                            <h4 class="text-xl font-extrabold text-gray-700 mb-4 flex items-center gap-2"><i data-lucide="app-window" class="w-6 h-6 text-[var(--color-primary)]"></i> GALERÍA DE ICONOS</h4>
                            <p class="text-sm text-gray-500 mb-4">Haz clic en un campo de "Icono" y luego selecciona uno de esta galería.</p>
                            <div id="icon-gallery" class="grid grid-cols-8 md:grid-cols-6 gap-2 bg-gray-100 p-4 rounded-lg"></div>
                        </div>

                        <div class="border-t border-gray-200 pt-6 flex justify-end gap-4">
                            <button type="submit" class="btn-primary font-bold py-3 px-8 rounded-lg uppercase text-sm flex items-center justify-center gap-2">
                                <i data-lucide="save" class="w-5 h-5"></i>
                                <span>Guardar Cambios</span>
                            </button>
                        </div>
                    </div>
                    
                    <div class="lg:col-span-1 space-y-8">
                        <div class="space-y-4">
                            <div id="preview-wrapper" class="rounded-lg p-6">
                                <div class="text-center mb-8">
                                    <p id="preview-badge" class="font-bold text-xs text-[var(--color-secondary)]">Real People • Fast Answers</p>
                                    <h2 class="font-extrabold leading-tight mt-2 text-xl">
                                        <span id="preview-title-1" class="block text-gray-800">We’re Here When You Need Us</span>
                                        <span id="preview-title-2" class="block text-[var(--color-secondary)]">Check Hours • Plan With Confidence</span>
                                    </h2>
                                </div>
                                <div class="grid grid-cols-1 lg:grid-cols-7 gap-4">
                                    <div class="lg:col-span-4 bg-white rounded-xl shadow-md p-4">
                                        <h3 class="font-extrabold text-gray-800 text-lg ">Our Weekly Schedule</h3>
                                        <ul id="preview-hours-grid" class="mt-3 space-y-2 text-sm"></ul>
                                    </div>
                                    <div class="lg:col-span-3 space-y-4">
                                        <div class="bg-white/80 rounded-lg p-3 shadow-md">
                                            <p class="text-xs font-bold text-gray-500">Business Schedule Status</p>
                                            <p class="text-md font-extrabold text-gray-800">Loading...</p>
                                        </div>
                                        <div class="bg-white rounded-xl shadow-md p-4">
                                            <h4 class="font-extrabold text-gray-800 text-sm">Why Schedule With Us</h4>
                                            <ul id="preview-benefits-list" class="mt-2 space-y-2 text-xs"></ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        
                        <div id="video-instrucciones" class="space-y-6">
                            <div class="w-full">
                                <div class="bg-black/40 rounded-xl ring-1 ring-white/10 overflow-hidden">
                                    <div class="relative w-full" style="padding-bottom: 56.25%;">
                                        <video class="absolute top-0 left-0 w-full h-full object-cover" id="videoPlayer" controls controlslist="nodownload fullscreen" preload="metadata">
                                            <source src="https://samplelib.com/lib/preview/mp4/sample-5s.mp4" type="video/mp4">
                                            TU NAVEGADOR NO SOPORTA LA ETIQUETA DE VIDEO
                                        </video>
                                        <div id="playOverlay" class="absolute inset-0 flex justify-center items-center cursor-pointer group">
                                            <img src="img/VideoLeccion-IAMarketing.jpg" alt="VideoLeccion - IAMarketing" class="absolute inset-0 w-full h-full object-cover">
                                            <div class="absolute inset-0 w-full h-full bg-black/40 transition-colors group-hover:bg-black/60"></div>
                                            <i data-lucide="play" class="relative w-16 h-16 text-white opacity-80 group-hover:opacity-100 transition-opacity"></i>
                                        </div>
                                    </div>
                                    <div class="p-4 text-white/90 text-sm flex items-center justify-between">
                                        <span class="inline-flex items-center gap-2">
                                            <i data-lucide="play-circle" class="w-4 h-4"></i> Video Tutorial
                                        </span>
                                        <span class="inline-flex items-center gap-2">
                                            <i data-lucide="clock" class="w-4 h-4"></i> 2–3 min
                                        </span>
                                    </div>
                                </div>
                            </div>
                            <div class="bg-white p-6 rounded-xl shadow-md">
                                <div class="text-center md:text-left mb-6">
                                    <h4 class="text-2xl font-black uppercase text-black flex items-center justify-center md:justify-start">
                                        <i data-lucide="book-open" class="mr-3 text-[var(--color-highlight)] w-7 h-7"></i>
                                        INSTRUCCIONES IMPORTANTES
                                    </h4>
                                    <p class="step-subtitle uppercase text-sm mt-1 text-gray-500">REVISA ESTOS PUNTOS DETALLADAMENTE</p>
                                </div>

                                <div class="space-y-4">
                                    <div class="flex items-start gap-3">
                                        <i data-lucide="play-circle" class="w-5 h-5 mt-0.5" style="color: var(--color-secondary);"></i>
                                        <div>
                                            <h5 class="font-black text-gray-800">REVISA EL VIDEO DE INSTRUCCIONES</h5>
                                            <p class="text-sm text-gray-600">Comprende cómo utilizar la plataforma y sácale el máximo provecho a todas sus herramientas.</p>
                                        </div>
                                    </div>

                                    <div class="flex items-start gap-3">
                                        <i data-lucide="target" class="w-5 h-5 mt-0.5" style="color: var(--color-secondary);"></i>
                                        <div>
                                            <h5 class="font-black text-gray-800">DEFINE BIEN LOS OBJETIVOS</h5>
                                            <p class="text-sm text-gray-600">Identifica qué quieres lograr con esta sección de la página web para una estrategia más efectiva.</p>
                                        </div>
                                    </div>

                                    <div class="flex items-start gap-3">
                                        <i data-lucide="file-text" class="w-5 h-5 mt-0.5" style="color: var(--color-secondary);"></i>
                                        <div>
                                            <h5 class="font-black text-gray-800">SÉ PRECISO Y CONCISO</h5>
                                            <p class="text-sm text-gray-600">Redacta textos persuasivos y enfocados en el valor que ofreces para impulsar tus ventas.</p>
                                        </div>
                                    </div>

                                    <div class="flex items-start gap-3">
                                        <i data-lucide="refresh-cw" class="w-5 h-5 mt-0.5" style="color: var(--color-secondary);"></i>
                                        <div>
                                            <h5 class="font-black text-gray-800">MANTÉN LA INFORMACIÓN ACTUALIZADA</h5>
                                            <p class="text-sm text-gray-600">Actualiza la información regularmente (al menos cada 3 meses) para mantener tu contenido relevante y dinámico.</p>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </main>
</div>

<div id="toast-container" class="toast-container"></div>

<script>
document.addEventListener('DOMContentLoaded', () => {
    // --- SETUP BÁSICO ---
    const mobileMenuButton = document.getElementById('mobile-menu-button');
    const sidebar = document.getElementById('sidebar');
    const sidebarOverlay = document.getElementById('sidebar-overlay');
    if (mobileMenuButton && sidebar && sidebarOverlay) {
        mobileMenuButton.addEventListener('click', () => { sidebar.classList.toggle('-translate-x-full'); sidebarOverlay.classList.toggle('hidden'); });
        sidebarOverlay.addEventListener('click', () => { sidebar.classList.add('-translate-x-full'); sidebarOverlay.classList.toggle('hidden'); });
    }
    const form = document.getElementById('hours-editor-form');

    // --- EDITOR DE HORARIOS ---
    const weeklyHoursEditor = document.getElementById('weekly-hours-editor');
    const previewHoursGrid = document.getElementById('preview-hours-grid');
    const hoursJsonInput = document.getElementById('hours-json-input');
    const days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];

    const renderHoursPreview = () => {
        previewHoursGrid.innerHTML = '';
        const hoursData = [];
        days.forEach(day => {
            const dayId = day.toLowerCase();
            const dayContainer = document.getElementById(`day-${dayId}`);
            
            // Verificación añadida para evitar el error
            if (!dayContainer) return;

            const isOpen = dayContainer.querySelector('.day-status').checked;
            const openTimeInput = dayContainer.querySelector('.day-open');
            const closeTimeInput = dayContainer.querySelector('.day-close');

            const openTime = openTimeInput ? openTimeInput.value : '';
            const closeTime = closeTimeInput ? closeTimeInput.value : '';
            
            hoursData.push({ day: day, is_open: isOpen, open_time: openTime, close_time: closeTime });

            let timeString = '<span class="text-[var(--color-secondary)] font-bold">Closed</span>';
            if (isOpen) {
                const formatTime = (time) => {
                    if (!time) return 'N/A';
                    let [h, m] = time.split(':');
                    let ampm = h >= 12 ? 'PM' : 'AM';
                    h = h % 12 || 12;
                    return `${h}:${m} ${ampm}`;
                };
                timeString = `${formatTime(openTime)} - ${formatTime(closeTime)}`;
            }
            previewHoursGrid.innerHTML += `<li class="flex justify-between items-center"><span class="font-bold text-gray-600">${day}</span> <span>${timeString}</span></li>`;
        });
        hoursJsonInput.value = JSON.stringify(hoursData);
    };

    const createWeeklyHoursHTML = (hoursData) => {
        weeklyHoursEditor.innerHTML = '';
        hoursData.forEach(hour => {
            const dayId = hour.day.toLowerCase();
            const checkedAttr = hour.is_open ? 'checked' : '';
            const disabledAttr = !hour.is_open ? 'disabled' : '';
            const opacityStyle = !hour.is_open ? 'opacity: 0.5;' : 'opacity: 1;';
            const openTimeValue = hour.open_time ? hour.open_time.substring(0, 5) : '';
            const closeTimeValue = hour.close_time ? hour.close_time.substring(0, 5) : '';

            weeklyHoursEditor.innerHTML += `
                <div id="day-${dayId}" class="grid grid-cols-3 items-center gap-4 p-3 border rounded-lg bg-gray-50">
                    <div class="flex items-center">
                        <input type="checkbox" id="status-${dayId}" name="day-status-${dayId}" class="day-status h-4 w-4 rounded border-gray-300 text-indigo-600 focus:ring-indigo-500" ${checkedAttr}>
                        <label for="status-${dayId}" class="ml-2 block text-sm font-bold text-gray-900">${hour.day}</label>
                    </div>
                    <div class="col-span-2 grid grid-cols-2 gap-2 time-inputs" style="${opacityStyle}">
                        <input type="time" name="day-open-${dayId}" class="day-open w-full p-2 border border-gray-300 rounded-md" value="${openTimeValue}" ${disabledAttr}>
                        <input type="time" name="day-close-${dayId}" class="day-close w-full p-2 border border-gray-300 rounded-md" value="${closeTimeValue}" ${disabledAttr}>
                    </div>
                </div>`;
        });
        renderHoursPreview();
    };

    weeklyHoursEditor.addEventListener('change', e => {
        if (e.target.classList.contains('day-status')) {
            const timeInputs = e.target.closest('.grid').querySelector('.time-inputs');
            if (timeInputs) {
                timeInputs.querySelectorAll('input').forEach(input => input.disabled = !e.target.checked);
                timeInputs.style.opacity = e.target.checked ? '1' : '0.5';
            }
        }
        renderHoursPreview();
    });
    weeklyHoursEditor.addEventListener('input', renderHoursPreview);

    // --- REPEATER DE BENEFICIOS ---
    const benefitsRepeater = document.getElementById('benefits-repeater');
    const addBenefitBtn = document.getElementById('add-benefit-btn');
    const previewBenefitsList = document.getElementById('preview-benefits-list');
    const iconGallery = document.getElementById('icon-gallery');
    const benefitsJsonInput = document.getElementById('benefits-json-input');
    
    let benefitCounter = 0;
    let activeIconInput = null;

    const iconList = ['sparkles', 'users', 'clipboard-check', 'shield-check', 'award', 'thumbs-up', 'star', 'gem', 'verified', 'lock', 'clock'];
    iconGallery.innerHTML = iconList.map(name => `<button type="button" class="icon-gallery-btn" data-icon-name="${name}"><i data-lucide="${name}" class="w-6 h-6 text-gray-600"></i></button>`).join('');
    
    iconGallery.addEventListener('click', e => {
        const btn = e.target.closest('.icon-gallery-btn');
        if (btn && activeIconInput) {
            activeIconInput.value = btn.dataset.iconName;
            activeIconInput.dispatchEvent(new Event('input', { bubbles: true }));
            activeIconInput.classList.remove('is-active');
            activeIconInput = null;
        }
    });

    const createBenefitItemHTML = (id, icon = '', text = '') => `
        <div class="benefit-item border border-gray-200 p-4 rounded-lg bg-gray-50 flex items-center gap-2" data-id="${id}">
            <input type="text" name="benefit-icon-${id}" class="w-1/3 p-2 border border-gray-300 rounded-md benefit-icon-input" placeholder="Icono" value="${icon}" readonly>
            <input type="text" name="benefit-text-${id}" class="w-2/3 p-2 border border-gray-300 rounded-md benefit-text" placeholder="Texto del beneficio" value="${text}">
            <button type="button" class="remove-item-btn text-[var(--color-secondary)] hover:text-red-700 p-2"><i data-lucide="trash-2" class="w-4 h-4"></i></button>
        </div>`;

    const renderBenefitsPreview = () => {
        previewBenefitsList.innerHTML = '';
        const benefitsData = [];
        benefitsRepeater.querySelectorAll('.benefit-item').forEach(item => {
            const icon = item.querySelector('.benefit-icon-input').value || 'check';
            const text = item.querySelector('.benefit-text').value;
            if (text) { 
                benefitsData.push({ icon, text });
                previewBenefitsList.innerHTML += `<li class="flex items-center gap-2"><i data-lucide="${icon}" class="w-4 h-4 text-[var(--color-secondary)]"></i> ${text}</li>`; 
            }
        });
        benefitsJsonInput.value = JSON.stringify(benefitsData);
        lucide.createIcons();
    };

    addBenefitBtn.addEventListener('click', () => { benefitCounter++; benefitsRepeater.insertAdjacentHTML('beforeend', createBenefitItemHTML(benefitCounter)); lucide.createIcons(); renderBenefitsPreview(); });
    benefitsRepeater.addEventListener('click', e => { if (e.target.closest('.remove-item-btn')) { e.target.closest('.benefit-item').remove(); renderBenefitsPreview(); } });
    benefitsRepeater.addEventListener('focusin', e => { if (e.target.classList.contains('benefit-icon-input')) { document.querySelectorAll('.benefit-icon-input.is-active').forEach(el => el.classList.remove('is-active')); activeIconInput = e.target; activeIconInput.classList.add('is-active'); } });
    benefitsRepeater.addEventListener('input', renderBenefitsPreview);
    
    // --- BINDING DE TEXTOS ---
    const bindings = {
        'hours-badge': document.getElementById('preview-badge'),
        'hours-title-1': document.getElementById('preview-title-1'),
        'hours-title-2': document.getElementById('preview-title-2'),
    };
    const updatePreview = (input) => { if (bindings[input.id]) { bindings[input.id].textContent = input.value; } };
    form.addEventListener('input', e => updatePreview(e.target));
    
    // Función para mostrar toasts de notificación
    const showToast = (message, isSuccess) => {
        const toastContainer = document.getElementById('toast-container');
        const toast = document.createElement('div');
        toast.className = `toast ${isSuccess ? 'bg-green-500' : 'bg-red-500'}`;
        toast.textContent = message;
        toastContainer.appendChild(toast);
        setTimeout(() => toast.classList.add('show'), 10);
        setTimeout(() => {
            toast.classList.remove('show');
            setTimeout(() => toast.remove(), 300);
        }, 3000);
    };

    // Handle form submission with AJAX
    form.addEventListener('submit', async e => {
        e.preventDefault();
        const saveButton = form.querySelector('button[type="submit"]');
        const originalButtonText = saveButton.innerHTML;

        saveButton.disabled = true;
        saveButton.innerHTML = '<i data-lucide="loader" class="w-5 h-5 animate-spin"></i><span>Guardando...</span>';
        lucide.createIcons();

        const formData = new FormData(form);
        
        try {
            const response = await fetch(form.action, {
                method: 'POST',
                body: formData
            });
            const responseText = await response.text();
            
            let result;
            try {
                result = JSON.parse(responseText);
            } catch (jsonError) {
                showToast(`Error de servidor: Respuesta inesperada.<br><br>Revisa el archivo PHP.<br>Respuesta: ${responseText}`, false);
                console.error("Error al parsear JSON:", jsonError, "Respuesta del servidor:", responseText);
                return;
            }

            showToast(result.message, result.success);

            if (result.success) {
                loadData();
            }
        } catch (error) {
            console.error('Error:', error);
            showToast('Ocurrió un error al guardar los cambios.', false);
        } finally {
            saveButton.disabled = false;
            saveButton.innerHTML = originalButtonText;
            lucide.createIcons();
        }
    });

    // Load data from backend on page load
    const loadData = async () => {
        try {
            const response = await fetch('cms/schedule-read.php');
            const responseText = await response.text();

            let result;
            try {
                result = JSON.parse(responseText);
            } catch (jsonError) {
                showToast(`Error de servidor al cargar datos.<br><br>Revisa el archivo PHP.<br>Respuesta: ${responseText}`, false);
                console.error("Error al parsear JSON:", jsonError, "Respuesta del servidor:", responseText);
                return;
            }

            if (result.success && result.data) {
                const generalData = result.data.general;
                const hoursData = result.data.hours;
                const benefitsData = result.data.benefits;

                document.getElementById('hours-badge').value = generalData.schedule_badge;
                document.getElementById('preview-badge').textContent = generalData.schedule_badge;
                document.getElementById('hours-title-1').value = generalData.schedule_title_1;
                document.getElementById('preview-title-1').textContent = generalData.schedule_title_1;
                document.getElementById('hours-title-2').value = generalData.schedule_title_2;
                document.getElementById('preview-title-2').textContent = generalData.schedule_title_2;
                
                // Cargar horarios
                createWeeklyHoursHTML(hoursData);
                
                // Cargar beneficios
                benefitsRepeater.innerHTML = '';
                benefitCounter = 0;
                benefitsData.forEach(b => {
                    benefitCounter++;
                    benefitsRepeater.insertAdjacentHTML('beforeend', createBenefitItemHTML(benefitCounter, b.benefit_icon, b.benefit_text));
                });
                renderBenefitsPreview();

            }
        } catch (error) {
            console.error('Error al cargar los datos:', error);
            showToast('Error al cargar los datos.', false);
        } finally {
            lucide.createIcons();
        }
    };
    loadData();
});
</script>

</body>
</html>