`;
}
// --- TAB NAVIGATION ---
window.prtg_showTab = function (tabIndex, element) {
if (!prtg_tabPanels || !prtg_tabLinks) return;
prtg_currentTab = tabIndex;
prtg_tabPanels.forEach((panel) => panel.classList.remove("prtg-active"));
prtg_tabLinks.forEach((link) => link.classList.remove("prtg-active"));
if (prtg_tabPanels[tabIndex]) {
prtg_tabPanels[tabIndex].classList.add("prtg-active");
}
if (element) {
element.classList.add("prtg-active");
}
prtg_updateNavButtons();
};
function prtg_goToNextTab() {
if (prtg_currentTab < prtg_tabPanels.length - 1) {
prtg_currentTab++;
prtg_showTab(prtg_currentTab, prtg_tabLinks[prtg_currentTab]);
}
}
function prtg_goToPrevTab() {
if (prtg_currentTab > 0) {
prtg_currentTab--;
prtg_showTab(prtg_currentTab, prtg_tabLinks[prtg_currentTab]);
}
}
function prtg_updateNavButtons() {
if (!prtg_prevBtn || !prtg_nextBtn) return;
prtg_prevBtn.disabled = prtg_currentTab === 0;
prtg_nextBtn.disabled = prtg_currentTab === prtg_tabPanels.length - 1;
}
function prtg_escapeHTML(str) {
if (typeof str !== 'string') return '';
return str.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"').replace(/'/g, ''');
}
// --- PDF EXPORT ---
function prtg_downloadPDF() {
if (typeof jspdf === "undefined") {
console.error("jsPDF library not loaded.");
alert("Error: PDF generation library failed to load.");
return;
}
const { jsPDF } = jspdf;
const doc = new jsPDF({
orientation: "p",
unit: "pt",
format: "a4",
});
const margin = 60; // Standard document margins
const pageWidth = doc.internal.pageSize.getWidth();
const contentWidth = pageWidth - margin * 2;
let yPos = margin;
// Use Times New Roman for standard press release look
doc.setFont('times', 'normal');
doc.setFontSize(11);
// Header
doc.setFont('times', 'bold');
doc.text("FOR IMMEDIATE RELEASE", pageWidth / 2, yPos, { align: 'center' });
yPos += 30;
// Headline
doc.setFontSize(16);
const headlineLines = doc.splitTextToSize(prtg_state.headline || "[Headline]", contentWidth);
doc.text(headlineLines, pageWidth / 2, yPos, { align: 'center' });
yPos += (headlineLines.length * 16 * 1.2) + 10; // Approx line height
// Dateline
doc.setFontSize(11);
const today = new Date();
const dateString = today.toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
const city = (prtg_state.city || "[City]").toUpperCase();
const state = (prtg_state.state || "[ST]").toUpperCase();
doc.text(`${city}, ${state} – ${dateString} –`, margin, yPos);
yPos += 15 + 5; // Extra space after dateline
// Intro
doc.setFont('times', 'normal');
const introLines = doc.splitTextToSize(prtg_state.intro || "[Intro]", contentWidth);
doc.text(introLines, margin, yPos);
yPos += (introLines.length * 11 * 1.5) + 12; // Approx line height + paragraph space
// Body (handle multiple paragraphs)
const bodyParagraphs = prtg_state.body.split(/\n\s*\n/); // Split by blank lines
bodyParagraphs.forEach(para => {
if (yPos > doc.internal.pageSize.getHeight() - margin - 50) { // Check space before adding para
doc.addPage();
yPos = margin;
}
const bodyLines = doc.splitTextToSize(para || "[Body]", contentWidth);
doc.text(bodyLines, margin, yPos);
yPos += (bodyLines.length * 11 * 1.5) + 12;
});
// Boilerplate
if (yPos > doc.internal.pageSize.getHeight() - margin - 50) { doc.addPage(); yPos = margin; }
doc.setFont('times', 'italic');
doc.setFontSize(10);
const boilerplateLines = doc.splitTextToSize(prtg_state.boilerplate || "[Boilerplate]", contentWidth);
doc.text(boilerplateLines, margin, yPos);
yPos += (boilerplateLines.length * 10 * 1.5) + 20;
// End Marker
if (yPos > doc.internal.pageSize.getHeight() - margin - 30) { doc.addPage(); yPos = margin; }
doc.setFont('times', 'bold');
doc.setFontSize(11);
doc.text("###", pageWidth / 2, yPos, { align: 'center' });
yPos += 30;
// Contact Info
if (yPos > doc.internal.pageSize.getHeight() - margin - 70) { doc.addPage(); yPos = margin; }
doc.setFontSize(10);
doc.text("Media Contact:", margin, yPos);
yPos += 15;
doc.setFont('times', 'normal');
doc.text(prtg_state.contactName || "[Name]", margin, yPos);
yPos += 13;
if (prtg_state.contactTitle) {
doc.text(prtg_state.contactTitle, margin, yPos);
yPos += 13;
}
doc.text(prtg_state.contactEmail || "[Email]", margin, yPos);
yPos += 13;
if (prtg_state.contactPhone) {
doc.text(prtg_state.contactPhone, margin, yPos);
}
doc.save("Press_Release.pdf");
}
})();