No forms have been generated yet.
'; } function renderGenerator() { genEmployeeSelect.innerHTML = state.employees.map(e => ``).join(''); genVerifierSelect.innerHTML = state.verifiers.map(v => ``).join(''); } function renderConfiguration() { companyNameInput.value = state.companyInfo.name; companyAddressInput.value = state.companyInfo.address; employeesList.innerHTML = state.employees.map(e => `${e.name}
`).join('');
verifiersList.innerHTML = state.verifiers.map(v => `${v.name}
`).join('');
}
// SECTION: Event Handlers
function handleTabClick(tabName) { state.activeTab = tabName; render(); }
function handleNavClick(dir) { const i = TABS.indexOf(state.activeTab); const newI = i + dir; if (newI >= 0 && newI < TABS.length) { state.activeTab = TABS[newI]; render(); } }
function handleSaveCompanyInfo(e) { e.preventDefault(); state.companyInfo = { name: companyNameInput.value, address: companyAddressInput.value }; saveState(); alert('Company info saved!'); }
function handleAdd(type, inputEl) { const name = inputEl.value.trim(); if(name){ state[type+'s'].push({id: Date.now(), name}); inputEl.value = ''; saveState(); render(); } }
function handleDelete(type, id) { if(confirm(`Delete this ${type}?`)){ state[type+'s'] = state[type+'s'].filter(item => item.id !== id); saveState(); render(); } }
function handleGenerateForm(e) {
e.preventDefault();
const formData = {
id: Date.now(),
employeeId: parseInt(genEmployeeSelect.value),
verifierId: parseInt(genVerifierSelect.value),
startDate: genStartDateInput.value,
jobTitle: genJobTitleInput.value,
generationDate: new Date()
};
state.generatedForms.push(formData);
saveState();
generatePDF(formData.id);
renderDashboard();
state.activeTab = 'dashboard';
renderTabs();
}
function generatePDF(formId) {
const form = state.generatedForms.find(f => f.id === formId);
if (!form) { alert('Could not find form data.'); return; }
const employee = state.employees.find(e => e.id === form.employeeId);
const verifier = state.verifiers.find(v => v.id === form.verifierId);
const company = state.companyInfo;
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const margin = 20;
const pageWidth = doc.internal.pageSize.getWidth();
// Header
doc.setFontSize(24); doc.setFont('helvetica', 'bold'); doc.text('Employee Work Authorization', pageWidth / 2, margin, { align: 'center' });
doc.setFontSize(11); doc.setFont('helvetica', 'normal');
// Section 1: Employee Information
let yPos = margin + 20;
doc.setFontSize(14); doc.setFont('helvetica', 'bold'); doc.text('Section 1: Employee Information', margin, yPos);
yPos += 8;
doc.autoTable({
startY: yPos, theme: 'plain',
body: [
['Employee Full Name:', employee.name],
['Job Title:', form.jobTitle],
['Employment Start Date:', new Date(form.startDate).toLocaleDateString()],
],
});
yPos = doc.autoTable.previous.finalY + 15;
// Section 2: Employer Certification
doc.setFontSize(14); doc.setFont('helvetica', 'bold'); doc.text('Section 2: Employer Certification', margin, yPos);
yPos += 8;
const certificationText = `I attest, under penalty of perjury, that I have examined the document(s) presented by the above-named employee, that the above-listed document(s) appear to be genuine and to relate to the employee named, and that to the best of my knowledge the employee is authorized to work in the United States.`;
doc.setFontSize(11);
doc.text(certificationText, margin, yPos, { maxWidth: pageWidth - (margin * 2) });
yPos += 30;
doc.autoTable({
startY: yPos, theme: 'plain',
body: [
['Company Name:', company.name],
['Company Address:', company.address],
],
});
yPos = doc.autoTable.previous.finalY + 25;
// Signature Lines
doc.line(margin, yPos, margin + 80, yPos); // Employee Signature
doc.text('Employee Signature', margin, yPos + 5);
doc.line(pageWidth - margin - 80, yPos, pageWidth - margin, yPos); // Date
doc.text('Date', pageWidth - margin - 80, yPos + 5);
yPos += 20;
doc.line(margin, yPos, margin + 80, yPos); // Verifier Signature
doc.text('Authorized Representative Signature', margin, yPos + 5);
doc.line(pageWidth - margin - 80, yPos, pageWidth - margin, yPos); // Date
doc.text('Date', pageWidth - margin - 80, yPos + 5);
yPos += 10;
doc.text(`Printed Name and Title: ${verifier.name}`, margin, yPos);
doc.save(`Work_Authorization_${employee.name.replace(/\s/g, '_')}.pdf`);
}
// SECTION: Event Listeners
Object.keys(tabButtons).forEach(id => tabButtons[id]?.addEventListener('click', () => handleTabClick(id)));
prevTabBtn?.addEventListener('click', () => handleNavClick(-1));
nextTabBtn?.addEventListener('click', () => handleNavClick(1));
formsList?.addEventListener('click', e => { if(e.target.classList.contains('download-pdf-btn')) generatePDF(parseInt(e.target.dataset.formId)); });
generateForm?.addEventListener('submit', handleGenerateForm);
companyInfoForm?.addEventListener('submit', handleSaveCompanyInfo);
addEmployeeForm?.addEventListener('submit', e => { e.preventDefault(); handleAdd('employee', employeeNameInput); });
addVerifierForm?.addEventListener('submit', e => { e.preventDefault(); handleAdd('verifier', verifierNameInput); });
employeesList?.addEventListener('click', e => { if(e.target.classList.contains('delete-employee-btn')) handleDelete('employee', parseInt(e.target.dataset.id)); });
verifiersList?.addEventListener('click', e => { if(e.target.classList.contains('delete-verifier-btn')) handleDelete('verifier', parseInt(e.target.dataset.id)); });
// SECTION: Initial Load
loadState();
render();
});
