3. Detailed Description of the Situation:
${data.conflictDescription.replace(/\n/g, '
')}
4. Proposed Mitigation Strategy:
${data.mitigationSteps.replace(/\n/g, '
')}
I affirm that the information provided in this disclosure is true and complete to the best of my knowledge. I understand that I have an ongoing obligation to update this disclosure if any of the circumstances described herein change.
Signature:
${data.fullName}
`;
document.getElementById('download-container').classList.remove('hidden');
};
// --- UI & NAVIGATION ---
const updateNavButtons = () => {
prevBtn.disabled = currentTab === '1';
nextBtn.disabled = currentTab === '3';
prevBtn.classList.toggle('opacity-50', prevBtn.disabled);
nextBtn.classList.toggle('opacity-50', nextBtn.disabled);
};
const validateTab = (tabId) => {
if(tabId === '1') {
return document.getElementById('fullName').value && document.getElementById('position').value;
}
if(tabId === '2') {
return document.getElementById('externalEntity').value && document.getElementById('conflictDescription').value;
}
return true;
}
window.switchTab = (tabId) => {
currentTab = tabId;
tabs.forEach(id => {
document.getElementById(`tab-content-${id}`).classList.toggle('hidden', id !== currentTab);
document.getElementById(`tab-btn-${id}`).classList.toggle('tab-active', id === currentTab);
document.getElementById(`tab-btn-${id}`).classList.toggle('tab-inactive', id !== currentTab);
});
if (tabId === '3') {
generateDisclosure();
}
updateNavButtons();
};
const navigateTabs = (direction) => {
const currentIdx = tabs.indexOf(currentTab);
if(direction > 0 && !validateTab(tabs[currentIdx])) {
alert('Please fill out all required fields before proceeding.');
return;
}
let nextIndex = currentIdx + direction;
if (nextIndex >= 0 && nextIndex < tabs.length) {
switchTab(tabs[nextIndex]);
}
};
// --- PDF GENERATION ---
const downloadPdf = () => {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({
orientation: 'p',
unit: 'pt',
format: 'a4'
});
const data = getInputs();
const margin = 40;
const pageWidth = doc.internal.pageSize.getWidth();
let y = margin;
doc.setFont('times', 'bold');
doc.setFontSize(16);
doc.text('Conflict of Interest Disclosure Form', pageWidth / 2, y, { align: 'center' });
y += 40;
doc.setFont('times', 'normal');
doc.setFontSize(12);
const addSection = (title, content, isHtml = false) => {
doc.setFont('times', 'bold');
doc.text(title, margin, y);
y += 15;
doc.setFont('times', 'normal');
const textLines = doc.splitTextToSize(content, pageWidth - margin * 2);
doc.text(textLines, margin, y);
y += (textLines.length * 12) + 20;
if (y > doc.internal.pageSize.getHeight() - 80) {
doc.addPage();
y = margin;
}
};
addSection('Date of Disclosure:', data.disclosureDate);
addSection('Discloser Information:', `Name: ${data.fullName}\nTitle: ${data.position}\nDepartment: ${data.department}`);
addSection('1. Identification of Potential Conflict:', `I hereby disclose a potential conflict of interest involving the following external entity/person: ${data.externalEntity}.`);
addSection('2. Nature of the Relationship:', `My relationship with the above-named entity/person is: ${data.relationship}.`);
addSection('3. Detailed Description of the Situation:', data.conflictDescription);
addSection('4. Proposed Mitigation Strategy:', data.mitigationSteps);
addSection('Affirmation:', 'I affirm that the information provided in this disclosure is true and complete to the best of my knowledge. I understand that I have an ongoing obligation to update this disclosure if any of the circumstances described herein change.');
y += 50;
doc.setFont('times', 'bold');
doc.text('Signature:', margin, y);
y += 40;
doc.setLineWidth(0.5);
doc.line(margin, y, margin + 250, y);
y += 15;
doc.setFont('times', 'normal');
doc.text(data.fullName, margin, y);
doc.save(`COI_Disclosure_${data.fullName.replace(/\s/g, '_')}.pdf`);
};
// --- EVENT LISTENERS & INITIAL SETUP ---
prevBtn.addEventListener('click', () => navigateTabs(-1));
nextBtn.addEventListener('click', () => navigateTabs(1));
document.getElementById('download-pdf-btn').addEventListener('click', downloadPdf);
updateNavButtons();
lucide.createIcons();
});