`;
return text;
}
// --- RENDER FUNCTIONS ---
function renderAgreementPreview() {
if (state.agreementText) {
agreementPreview.innerHTML = state.agreementText;
pdfBtnContainer.classList.remove('hidden');
} else {
agreementPreview.innerHTML = `
Complete the form in the 'Data Configuration' tab to generate the agreement.
`; pdfBtnContainer.classList.add('hidden'); } } // --- EVENT HANDLERS & LOGIC --- function switchTab(tabName) { state.currentTab = tabName; Object.values(tabs).forEach(tab => tab.classList.remove('active')); Object.values(contents).forEach(content => content.classList.add('hidden')); tabs[tabName].classList.add('active'); contents[tabName].classList.remove('hidden'); updateNavButtons(); } function updateNavButtons() { navButtons.prev.disabled = state.currentTab === 'dashboard'; navButtons.next.disabled = state.currentTab === 'config'; } ncaForm.addEventListener('submit', (e) => { e.preventDefault(); const formData = { companyName: document.getElementById('company-name').value, employeeName: document.getElementById('employee-name').value, effectiveDate: document.getElementById('effective-date').value, restrictedTerritory: document.getElementById('restricted-territory').value, restrictedPeriod: document.getElementById('restricted-period').value, restrictedActivities: document.getElementById('restricted-activities').value, }; state.agreementText = generateAgreementText(formData); renderAgreementPreview(); switchTab('dashboard'); }); downloadPdfBtn.addEventListener('click', () => { if (!state.formData) return; const { jsPDF } = window.jspdf; const doc = new jsPDF({ unit: 'pt', format: 'a4' }); const data = state.formData; const margin = 40; const maxWidth = doc.internal.pageSize.getWidth() - margin * 2; let y = margin; doc.setFont('times', 'bold'); doc.setFontSize(14); doc.text('NON-COMPETE AGREEMENT', doc.internal.pageSize.getWidth() / 2, y, { align: 'center' }); y += 30; doc.setFont('times', 'normal'); doc.setFontSize(12); const addWrappedText = (text, yPos) => { const lines = doc.splitTextToSize(text, maxWidth); doc.text(lines, margin, yPos); return yPos + (lines.length * 14); // 12pt font size + line spacing }; y = addWrappedText(`This Non-Compete Agreement (the "Agreement") is entered into as of ${data.effectiveDate}, by and between ${data.companyName} (the "Company") and ${data.employeeName} (the "Employee").`, y); y += 14; y = addWrappedText(`1. Purpose. The Company is engaged in the business of ${data.restrictedActivities}. The Employee is being engaged by the Company in a capacity that will provide them with access to Confidential Information. In consideration of employment and access to this information, the Employee agrees to the terms of this Agreement.`, y); y += 14; y = addWrappedText(`2. Non-Competition. For a period of ${data.restrictedPeriod} months following the termination of employment for any reason (the "Restricted Period"), the Employee shall not, directly or indirectly, own, manage, operate, join, control, or participate in any business entity that engages in activities competitive with the Company's business within ${data.restrictedTerritory} (the "Restricted Territory").`, y); y += 14; y = addWrappedText(`3. Confidentiality. The Employee agrees to hold all Confidential Information of the Company in the strictest confidence and not to disclose it to any third party during or after the term of employment.`, y); y += 14; y = addWrappedText(`4. Governing Law. This Agreement shall be governed by and construed in accordance with the laws of the State of Delaware, without regard to its conflict of laws principles.`, y); y += 14; y = addWrappedText(`5. Acknowledgment. The Employee acknowledges that they have had the opportunity to read this Agreement, understand its terms, and have been advised to consult with legal counsel prior to execution.`, y); y += 30; y = addWrappedText('IN WITNESS WHEREOF, the parties have executed this Agreement as of the date first above written.', y); y += 40; doc.text(`COMPANY: ${data.companyName}`, margin, y); y += 30; doc.text('By: _________________________', margin, y); y += 30; doc.text('Name: _______________________', margin, y); y += 30; doc.text('Title: ________________________', margin, y); y += 60; doc.text('EMPLOYEE:', margin, y); y += 30; doc.text('___________________________', margin, y); y += 20; doc.text(data.employeeName, margin, y); doc.save('Non-Compete_Agreement.pdf'); }); // --- ATTACH EVENT LISTENERS --- tabs.dashboard.addEventListener('click', () => switchTab('dashboard')); tabs.config.addEventListener('click', () => switchTab('config')); navButtons.next.addEventListener('click', () => switchTab('config')); navButtons.prev.addEventListener('click', () => switchTab('dashboard')); init(); });