`;
devicesContainer.appendChild(card);
card.addEventListener('click', (e) => {
card.classList.toggle('selected');
const checkbox = card.querySelector('input[type="checkbox"]');
checkbox.checked = card.classList.contains('selected');
});
});
const showTab = (n) => {
tabContents.forEach(c => c.style.display = 'none');
tabs.forEach(t => t.classList.remove('active'));
if(tabContents[n]) tabContents[n].style.display = 'block';
if(tabs[n]) tabs[n].classList.add('active');
prevBtn.style.display = (n === 0) ? 'none' : 'inline-block';
nextBtn.style.display = (n === tabs.length - 1) ? 'none' : 'inline-block';
if (n === tabs.length - 1) { // Review & Export tab
updatePreview();
}
currentTab = n;
};
const updatePreview = () => {
previewTitle.textContent = writingTitle.value || "Your Title Here";
previewBody.textContent = writingArea.value || "Your satirical masterpiece will appear here. Go back to the 'Outline & Write' tab to draft it.";
}
const navigateTab = (n) => {
const newIndex = currentTab + n;
if (newIndex >= 0 && newIndex < tabs.length) {
showTab(newIndex);
}
};
const updateWordCount = () => {
const text = writingArea.value;
const words = text.trim() === '' ? 0 : text.trim().split(/\s+/).length;
wordCountDisplay.textContent = `Word Count: ${words}`;
};
const downloadPDF = () => {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'a4' });
const theme = document.querySelector('input[name="theme"]:checked').value;
const title = writingTitle.value || 'Untitled Satire';
const body = writingArea.value || 'No content was written.';
const page = { width: doc.internal.pageSize.getWidth(), height: doc.internal.pageSize.getHeight() };
const margin = 50;
if (theme === 'modern_blog') {
doc.setFont('helvetica', 'bold');
doc.setFontSize(24);
doc.text(title, page.width / 2, margin, { align: 'center', maxWidth: page.width - margin * 2 });
doc.setFont('helvetica', 'normal');
doc.setFontSize(11);
const bodyLines = doc.splitTextToSize(body, page.width - margin * 2);
doc.text(bodyLines, margin, margin + 40);
} else { // news_column
doc.setFont('times', 'bold');
doc.setFontSize(32);
doc.text(title, page.width / 2, margin, { align: 'center', maxWidth: page.width - margin * 2 });
doc.setLineWidth(1);
doc.line(margin, margin + 15, page.width - margin, margin + 15);
doc.setFont('times', 'normal');
doc.setFontSize(10);
const colWidth = (page.width - margin * 2 - 20) / 2;
doc.text(body, margin, margin + 40, {
columns: [
{ align: 'left', width: colWidth },
{ align: 'left', width: colWidth }
],
lineHeightFactor: 1.5
});
}
doc.save('satire-piece.pdf');
};
// Event Listeners
tabs.forEach((tab, index) => tab.addEventListener('click', () => showTab(index)));
prevBtn.addEventListener('click', () => navigateTab(-1));
nextBtn.addEventListener('click', () => navigateTab(1));
downloadPdfBtn.addEventListener('click', downloadPDF);
writingArea.addEventListener('input', updateWordCount);
// Initialization
showTab(0);
});
