Criando novo módulo Estúdio de Poesia e renomeando botões

This commit is contained in:
2026-06-05 13:50:39 +00:00
parent 0456617717
commit 7fa88481b7
3 changed files with 410 additions and 4 deletions
+191
View File
@@ -5170,6 +5170,197 @@ const initApp = () => {
}
}
// ============================================================
// ESTÚDIO DE POESIA
// ============================================================
const poesiaModal = document.getElementById('poesiaModal');
const btnClosePoesiaModal = document.getElementById('btnClosePoesiaModal');
const barBtnPoesia = document.getElementById('barBtnPoesia');
const btnOpenPoesiaHistory = document.getElementById('btnOpenPoesiaHistory');
const poesiaHistoryModal = document.getElementById('poesiaHistoryModal');
const btnClosePoesiaHistory = document.getElementById('btnClosePoesiaHistory');
const btnGeneratePoesia = document.getElementById('btnGeneratePoesia');
const poesiaGenerateLoader = document.getElementById('poesiaGenerateLoader');
const poesiaResultArea = document.getElementById('poesiaResultArea');
const poesiaTextOutput = document.getElementById('poesiaTextOutput');
const btnCopyPoesia = document.getElementById('btnCopyPoesia');
const btnDownloadPoesiaPdf = document.getElementById('btnDownloadPoesiaPdf');
const poesiaTemaInput = document.getElementById('poesiaTemaInput');
const poesiaFaixaEtaria = document.getElementById('poesiaFaixaEtaria');
let currentPoesia = null;
let selectedEstrofes = 3;
// Seleção de estrofes
document.querySelectorAll('.btn-poesia-estrofes').forEach(btn => {
btn.addEventListener('click', (e) => {
document.querySelectorAll('.btn-poesia-estrofes').forEach(b => b.classList.remove('active'));
e.target.classList.add('active');
selectedEstrofes = parseInt(e.target.dataset.estrofes);
});
});
// Abrir/Fechar Modal Principal
if (barBtnPoesia) {
barBtnPoesia.addEventListener('click', () => {
poesiaModal.style.display = 'flex';
poesiaTemaInput.value = '';
poesiaResultArea.style.display = 'none';
poesiaGenerateLoader.style.display = 'none';
btnGeneratePoesia.disabled = false;
currentPoesia = null;
});
}
if (btnClosePoesiaModal) {
btnClosePoesiaModal.addEventListener('click', () => {
poesiaModal.style.display = 'none';
});
}
// Abrir/Fechar Modal de Histórico
if (btnOpenPoesiaHistory) {
btnOpenPoesiaHistory.addEventListener('click', () => {
poesiaHistoryModal.style.display = 'flex';
loadPoesiaHistory();
});
}
if (btnClosePoesiaHistory) {
btnClosePoesiaHistory.addEventListener('click', () => {
poesiaHistoryModal.style.display = 'none';
});
}
window.addEventListener('click', (e) => {
if (e.target === poesiaModal) poesiaModal.style.display = 'none';
if (e.target === poesiaHistoryModal) poesiaHistoryModal.style.display = 'none';
});
// Gerar Poesia
if (btnGeneratePoesia) {
btnGeneratePoesia.addEventListener('click', async () => {
const tema = poesiaTemaInput.value.trim();
const faixaEtaria = poesiaFaixaEtaria.value;
if (!tema) {
showToast('Por favor, digite o tema da poesia.', 'error');
return;
}
btnGeneratePoesia.disabled = true;
poesiaGenerateLoader.style.display = 'flex';
poesiaResultArea.style.display = 'none';
try {
const response = await fetch('/api/poesias/generate', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ faixaEtaria, estrofes: selectedEstrofes, tema })
});
const data = await response.json();
if (response.ok && data.success) {
currentPoesia = data.poesia;
poesiaTextOutput.innerHTML = window.marked ? marked.parse(currentPoesia) : currentPoesia;
poesiaResultArea.style.display = 'flex';
showToast('Poesia criada com sucesso!', 'success');
} else {
showToast(data.error || 'Falha ao gerar poesia.', 'error');
}
} catch (err) {
console.error('Erro na geração da poesia:', err);
showToast('Erro de conexão ao gerar poesia.', 'error');
} finally {
btnGeneratePoesia.disabled = false;
poesiaGenerateLoader.style.display = 'none';
}
});
}
// Copiar e Baixar
if (btnCopyPoesia) {
btnCopyPoesia.addEventListener('click', () => {
if (currentPoesia) {
navigator.clipboard.writeText(currentPoesia);
showToast('Poesia copiada para a área de transferência!', 'success');
}
});
}
if (btnDownloadPoesiaPdf) {
btnDownloadPoesiaPdf.addEventListener('click', () => {
if (!currentPoesia) return;
const element = document.createElement('div');
element.innerHTML = window.marked ? marked.parse(currentPoesia) : currentPoesia;
element.style.padding = '20px';
element.style.fontFamily = 'Arial, sans-serif';
element.style.color = '#333';
html2pdf().set({
margin: 15,
filename: 'poesia_pedagogica.pdf',
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2 },
jsPDF: { unit: 'mm', format: 'a4', orientation: 'portrait' }
}).from(element).save();
});
}
// Carregar Histórico
async function loadPoesiaHistory() {
const listContainer = document.getElementById('poesiaHistoryList');
if (!listContainer) return;
listContainer.innerHTML = '<p style="text-align:center; color:var(--text-secondary);">Carregando...</p>';
try {
const response = await fetch('/api/poesias/list');
const data = await response.json();
if (data && data.length > 0) {
listContainer.innerHTML = '';
data.forEach(item => {
const date = new Date(item.created_at).toLocaleString('pt-BR');
const div = document.createElement('div');
div.className = 'history-item-card';
div.style.cssText = 'background: rgba(255,255,255,0.02); padding: 14px; border-radius: 8px; border: 1px solid var(--border-light); display: flex; flex-direction: column; gap: 8px; cursor: pointer;';
div.innerHTML = `
<div style="display: flex; justify-content: space-between; align-items: flex-start;">
<strong style="color: var(--brand-green); font-size: 0.95rem;">${item.faixa_etaria} (${item.estrofes} Estrofes)</strong>
<span style="font-size: 0.75rem; color: var(--text-secondary);">${date}</span>
</div>
<p style="margin: 0; font-size: 0.85rem; color: var(--text-primary); opacity: 0.9;">Tema: ${item.tema}</p>
`;
div.addEventListener('click', async () => {
try {
const res = await fetch(`/api/poesias/${item.id}`);
const detail = await res.json();
if (res.ok) {
currentPoesia = detail.poesia;
poesiaTextOutput.innerHTML = window.marked ? marked.parse(currentPoesia) : currentPoesia;
poesiaResultArea.style.display = 'flex';
poesiaHistoryModal.style.display = 'none';
}
} catch (err) {
showToast('Erro ao carregar poesia.', 'error');
}
});
listContainer.appendChild(div);
});
} else {
listContainer.innerHTML = '<p style="text-align:center; color:var(--text-secondary);">Nenhuma poesia salva ainda.</p>';
}
} catch (err) {
listContainer.innerHTML = '<p style="text-align:center; color:#ef4444;">Erro ao carregar histórico.</p>';
}
}
// ============================================================
// BRINCARATIVO (CIRCUITOS PSICOMOTORES E BRINCADEIRAS)
// ============================================================