// arquivo: script.js - Para integrar com o frontend existente // Configuração da API const API_URL = 'https://seu-backend-goalmaster-ai.hf.space'; // Substitua pelo URL real quando implantar // Selecionar elementos importantes do DOM document.addEventListener('DOMContentLoaded', () => { const generatePlanBtn = document.getElementById('generate-plan'); const aiLoadingSection = document.getElementById('ai-loading'); const aiPlanSection = document.getElementById('ai-plan-section'); const goalTitleInput = document.getElementById('goal-title'); const goalCategorySelect = document.getElementById('goal-category'); const goalDescriptionInput = document.getElementById('goal-description'); const goalTimelineSelect = document.getElementById('goal-timeline'); // Capturar opções da IA const stepByStepOption = document.querySelector('input[type="checkbox"][checked]:nth-of-type(1)'); const metricsOption = document.querySelector('input[type="checkbox"][checked]:nth-of-type(2)'); const remindersOption = document.querySelector('input[type="checkbox"][checked]:nth-of-type(3)'); const benchmarksOption = document.querySelector('input[type="checkbox"]:not([checked])'); // Substituir o evento de clique simulado por uma chamada real à API if (generatePlanBtn) { generatePlanBtn.addEventListener('click', async function() { if (!goalTitleInput.value.trim()) { alert('Por favor, informe um título para sua meta.'); return; } // Mostrar estado de carregamento aiLoadingSection.classList.remove('hidden'); generatePlanBtn.disabled = true; try { // Preparar dados para enviar à API const planData = { title: goalTitleInput.value, category: goalCategorySelect.value, description: goalDescriptionInput.value, timeframe: goalTimelineSelect.value, options: { step_by_step: stepByStepOption.checked, metrics: metricsOption.checked, reminders: remindersOption.checked, benchmarks: benchmarksOption.checked } }; // Fazer chamada à API const response = await fetch(`${API_URL}/generate-plan`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(planData) }); const result = await response.json(); if (result.success) { // Atualizar a UI com o plano gerado updatePlanUI(result.plan, planData.title, planData.category); } else { throw new Error(result.error || 'Erro ao gerar o plano'); } } catch (error) { console.error('Erro:', error); // Em caso de erro, exibir um plano genérico displayFallbackPlan(goalTitleInput.value, goalCategorySelect.value); } finally { // Ocultar carregamento e mostrar seção do plano aiLoadingSection.classList.add('hidden'); aiPlanSection.classList.remove('hidden'); generatePlanBtn.disabled = false; // Rolar até a seção do plano aiPlanSection.scrollIntoView({ behavior: 'smooth' }); } }); } }); // Função para atualizar a UI com o plano gerado pela IA function updatePlanUI(plan, goalTitle, category) { // Selecionar elementos que precisam ser atualizados const planSummaryContainer = document.querySelector('.bg-gray-50.p-4.rounded-lg.mb-6 ul'); const planStepsContainer = document.querySelector('.mb-6 .space-y-4'); const resourcesContainer = document.querySelector('.bg-blue-50.p-4.rounded-lg ul'); const checkpointsContainer = document.querySelector('.bg-green-50.p-4.rounded-lg ul'); // Atualizar resumo if (planSummaryContainer) { planSummaryContainer.innerHTML = `
${tasks}