Phase 3: Agreement & Closing
Facilitator: Summarizing the Agreement
${escapeHTML(data.closingAgreement)}
Facilitator: Final Closing Statement
${escapeHTML(data.closingFinal)}
`;
};
const downloadTxt = () => {
const data = getData();
const VName = data.victim;
const AName = data.offender;
let content = `RESTORATIVE JUSTICE CONFERENCE SCRIPT\n`;
content += "========================================================\n";
content += `CASE: ${data.caseTitle}\n`;
content += `RESPONSIBLE PARTY: ${AName}\n`;
content += `HARMED PARTY: ${VName}\n`;
content += `HARM SUMMARY: ${data.harmSummary}\n\n`;
content += "--------------------------------------------------------\n";
content += "PHASE 1: INTRODUCTION (SETTING THE STAGE)\n";
content += "--------------------------------------------------------\n";
content += `[FACILITATOR - PURPOSE]: ${data.introPurpose}\n\n`;
content += `[FACILITATOR - PARTICIPANTS]: ${data.introWho}\n\n`;
content += "--------------------------------------------------------\n";
content += "PHASE 2: STORYTELLING & ACCOUNTABILITY\n";
content += "--------------------------------------------------------\n";
content += `\n--- QUESTIONS FOR ${VName.toUpperCase()} ---\n`;
content += formatScriptLinesForTxt(data.storyVictim, 'Facilitator') + '\n';
content += `\n--- QUESTIONS FOR ${AName.toUpperCase()} ---\n`;
content += formatScriptLinesForTxt(data.storyOffender, 'Facilitator') + '\n';
content += "--------------------------------------------------------\n";
content += "PHASE 3: AGREEMENT & CLOSING\n";
content += "--------------------------------------------------------\n";
content += `[FACILITATOR - AGREEMENT SUMMARY]: ${data.closingAgreement}\n\n`;
content += `[FACILITATOR - FINAL CLOSING]: ${data.closingFinal}\n`;
const blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
const a = document.createElement('a');
a.href = URL.createObjectURL(blob);
a.download = `RJ_Script_${data.caseTitle.replace(/ /g, '_')}.txt`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(a.href);
};
const downloadPDF = () => {
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
alert('Error: jsPDF library not loaded.');
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'mm', 'a4');
const data = getData();
const margin = 15;
const pageWidth = doc.internal.pageSize.getWidth();
const usableWidth = pageWidth - (margin * 2);
let yPos = 20;
const addSectionTitle = (text) => {
if (yPos > 270) { doc.addPage(); yPos = 20; }
yPos += 5;
doc.setFontSize(14);
doc.setFont(undefined, 'bold');
doc.setTextColor(52, 73, 94);
doc.text(text, margin, yPos);
doc.setDrawColor(224, 224, 224);
doc.line(margin, yPos + 1, pageWidth - margin, yPos + 1);
yPos += 8;
};
const addText = (text, isScriptLine = false, isBold = false) => {
if (yPos > 280) { doc.addPage(); yPos = 20; }
doc.setFontSize(10);
doc.setFont(undefined, isBold ? 'bold' : 'normal');
doc.setTextColor(isScriptLine ? 85 : 52, 73, 94); // Script lines slightly lighter
let linePrefix = '';
let textWidth = usableWidth;
if (isScriptLine) {
textWidth -= 10;
linePrefix = '>>> ';
doc.setTextColor(52, 152, 219); // Blue for facilitator
}
const lines = doc.splitTextToSize(text, textWidth);
if (lines.length * 5 + yPos > 285) { doc.addPage(); yPos = 20; }
lines.forEach((line, index) => {
doc.text((index === 0 ? linePrefix : '') + line, margin + (isScriptLine ? 5 : 0), yPos);
yPos += 5;
});
yPos += 3;
};
// --- Build PDF Document ---
// Header
doc.setFontSize(18);
doc.setFont(undefined, 'bold');
doc.setTextColor(44, 62, 80);
doc.text("Restorative Justice Conference Guide", pageWidth / 2, yPos, { align: 'center' });
yPos += 8;
doc.setFontSize(12);
doc.setFont(undefined, 'normal');
doc.text(`${data.caseTitle}`, pageWidth / 2, yPos, { align: 'center' });
yPos += 10;
// Case Context
addSectionTitle("Case Context");
addText(`Harm Causer: ${data.offender}`, false, true);
addText(`Harm Caused: ${data.victim}`, false, true);
addText(`Summary of Harm: ${data.harmSummary}`, false);
yPos += 5;
// Phase 1: Introduction
addSectionTitle("Phase 1: Introduction (Setting the Stage)");
addText("Facilitator Purpose & Rules:", false, true);
addText(data.introPurpose, true);
addText("Acknowledging Participants:", false, true);
addText(data.introWho, true);
yPos += 5;
// Phase 2: Storytelling
addSectionTitle("Phase 2: Storytelling & Accountability");
doc.setFontSize(11);
doc.setFont(undefined, 'bold');
doc.setTextColor(44, 62, 80);
doc.text(`Questions for Person Harmed (${data.victim}):`, margin, yPos);
yPos += 6;
data.storyVictim.split('\n').filter(l => l.trim() !== '').forEach(l => addText(l, true));
doc.text(`Questions for Person Responsible (${data.offender}):`, margin, yPos);
yPos += 6;
data.storyOffender.split('\n').filter(l => l.trim() !== '').forEach(l => addText(l, true));
yPos += 5;
// Phase 3: Closing
addSectionTitle("Phase 3: Agreement & Closing");
addText("Agreement Summary:", false, true);
addText(data.closingAgreement, true);
addText("Final Closing Statement:", false, true);
addText(data.closingFinal, true);
doc.save(`RJ_Guide_${data.caseTitle.replace(/ /g, '_')}.pdf`);
};
// --- Event Listeners ---
// Tab Buttons
tabButtons.forEach((btn, index) => {
btn.addEventListener('click', () => showTab(index + 1));
});
// Next/Prev Navigation
nextBtn.addEventListener('click', () => showTab(currentTab + 1));
prevBtn.addEventListener('click', () => showTab(currentTab - 1));
// Tab 4 Actions
downloadPdfBtn.addEventListener('click', downloadPDF);
downloadTxtBtn.addEventListener('click', downloadTxt);
refreshPreviewBtn.addEventListener('click', generatePreview);
// --- Initialization ---
// Pre-populate placeholders with sample names for demonstration
inputs.offender.value = "Alex Johnson";
inputs.victim.value = "Ms. Lee / School Admin";
showTab(1);
});