`;
container.innerHTML = html;
}
function argSwitchTab(tabId) {
document.querySelectorAll('.arg-tab-btn').forEach(b => b.classList.remove('active'));
document.querySelectorAll('.arg-content').forEach(c => c.classList.remove('active'));
const idx = tabId === 'builder' ? 0 : 1;
document.querySelectorAll('.arg-tab-btn')[idx].classList.add('active');
document.getElementById('arg-' + tabId).classList.add('active');
if (tabId === 'preview') {
argRenderReport();
}
}
function argLoadExample() {
if(!confirm("Overwrite current data with example report data?")) return;
document.getElementById('inp-report-id').value = "AR-2025-0987";
document.getElementById('inp-officer').value = "Officer R. Jenkins / Badge 122";
document.getElementById('inp-subject-name').value = "Michael A. Davis";
document.getElementById('inp-dob').value = "1988-01-15";
document.getElementById('inp-location').value = "300 Block of Elmwood Avenue (Parking Lot)";
document.getElementById('inp-datetime').value = "2025-11-28, 23:10 PST";
document.getElementById('inp-charges').value = "PC 273.5 (Domestic Violence, Felony)\nPC 243(e)(1) (Battery on Spouse/Cohabitant, Misdemeanor)";
document.getElementById('inp-narrative').value = "1. On 2025-11-28 at 23:00, I responded to a 911 call reporting a domestic disturbance.
2. Upon arrival, I observed the victim, J. Doe, with visible bruising and swelling on her left cheek.
3. The victim stated the subject, M. Davis, struck her following a verbal dispute.
4. Subject was located sitting inside a vehicle parked 50 feet from the residence. Subject admitted to arguing with the victim but denied physical contact.
5. Due to visible injuries and probable cause, the subject was placed under arrest at 23:10 PST.";
document.getElementById('inp-miranda').value = "Yes";
document.getElementById('inp-miranda-time').value = "23:15";
document.getElementById('inp-evidence').value = "Item 1: Victim's recorded statement (Audio). Item 2: Photographs of victim's injuries. Item 3: Subject's car keys. All stored in Lockbox 7.";
argRenderReport();
argSwitchTab('preview');
}
/* --- PDF Generation --- */
async function argGeneratePDF() {
argRenderReport(); // Final render check
const data = {
reportId: document.getElementById('inp-report-id').value || "AR-0000",
officer: document.getElementById('inp-officer').value || "N/A Officer",
subjectName: document.getElementById('inp-subject-name').value || "N/A Subject",
dob: document.getElementById('inp-dob').value || "N/A",
datetime: document.getElementById('inp-datetime').value || "N/A Datetime",
location: document.getElementById('inp-location').value || "N/A Location",
charges: document.getElementById('inp-charges').value || "No charges listed.",
narrative: document.getElementById('inp-narrative').value || "No narrative provided.",
miranda: document.getElementById('inp-miranda').value,
mirandaTime: document.getElementById('inp-miranda-time').value,
evidence: document.getElementById('inp-evidence').value || "No evidence collected."
};
if (data.subjectName === "N/A Subject" || data.charges === "No charges listed.") {
alert("Please fill in Subject Name and Charges before generating the PDF.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF('p', 'mm', 'a4');
const navy = [30, 58, 138];
const red = [231, 76, 60];
let y = 20;
// 1. Header Block
doc.setFillColor(...navy);
doc.rect(0, 0, 210, 20, 'F');
doc.setTextColor(255, 255, 255);
doc.setFontSize(16);
doc.text(`OFFICIAL ARREST REPORT`, 105, 10, { align: 'center' });
doc.setFontSize(10);
doc.text(`Report ID: ${data.reportId}`, 14, 16);
doc.text(`Officer: ${data.officer}`, 105, 16);
y = 35;
// 2. Subject & Incident Data
doc.setTextColor(0, 0, 0);
doc.setFontSize(10);
doc.setFont("times", "bold");
doc.text("I. SUBJECT AND INCIDENT DATA", 14, y);
y += 5;
doc.setFont("times", "normal");
doc.text(`Subject Name: ${data.subjectName}`, 14, y + 5);
doc.text(`DOB: ${data.dob}`, 105, y + 5);
y += 5;
doc.text(`Arrest Time: ${data.datetime}`, 14, y + 5);
doc.text(`Location: ${data.location}`, 105, y + 5);
y += 15;
// 3. Charges
doc.setFont("times", "bold");
doc.setTextColor(...navy);
doc.setFontSize(12);
doc.text("II. APPLICABLE CHARGES", 14, y);
y += 5;
doc.setFont("times", "normal");
doc.setFontSize(10);
doc.setTextColor(red);
const splitCharges = doc.splitTextToSize(data.charges, 180);
doc.text(splitCharges, 18, y + 5);
y += (splitCharges.length * 5) + 10;
// 4. Narrative
doc.setFont("times", "bold");
doc.setTextColor(...navy);
doc.setFontSize(12);
doc.text("III. CHRONOLOGICAL NARRATIVE (Body of Report)", 14, y);
y += 5;
doc.setFont("times", "normal");
doc.setFontSize(10);
doc.setTextColor(0, 0, 0);
doc.setLineHeightFactor(1.5); // Slightly spaced narrative
const narrativeLines = doc.splitTextToSize(data.narrative, 180);
doc.text(narrativeLines, 14, y + 5);
y += (narrativeLines.length * 7) + 10;
doc.setLineHeightFactor(1.0); // Reset spacing
// 5. Post-Arrest Actions
doc.setFont("times", "bold");
doc.setTextColor(...navy);
doc.setFontSize(12);
doc.text("IV. POST-ARREST ACTIONS", 14, y);
y += 5;
doc.setFont("times", "normal");
doc.setFontSize(10);
doc.text(`Miranda Warning Issued: ${data.miranda} (Time: ${data.mirandaTime})`, 14, y + 5);
y += 5;
doc.text(`Evidence/Custody Log:`, 14, y + 5);
y += 5;
doc.text(doc.splitTextToSize(data.evidence, 170), 18, y + 5);
y += 15;
// 6. Certification
doc.setFontSize(10);
doc.text("Certification:", 14, y);
doc.text("I certify that this report is true and accurate to the best of my knowledge and belief.", 40, y);
y += 10;
doc.line(14, y, 100, y);
doc.text("Arresting Officer Signature / Badge No.", 14, y + 5);
doc.save(`ArrestReport_${data.reportId}.pdf`);
}
