A summary report for the LEI ${attributes.lei} is ready for download.
Legal Name: ${entity.legalName.name}
Status: ${entity.status}
Jurisdiction: ${entity.jurisdiction}
Next Renewal Date: ${new Date(registration.nextRenewalDate).toLocaleDateString()}
`;
downloadBtnContainer.classList.remove('hidden');
};
// --- UI & NAVIGATION ---
const updateNavButtons = () => {
prevBtn.disabled = currentTab === '1';
nextBtn.disabled = currentTab === '3' || !leiData;
prevBtn.classList.toggle('opacity-50', prevBtn.disabled);
nextBtn.classList.toggle('opacity-50', nextBtn.disabled);
};
window.switchTab = (tabId) => {
if (!leiData && (tabId === '2' || tabId === '3')) {
leiInput.classList.add('border-red-500', 'ring-2', 'ring-red-200');
setTimeout(() => {
leiInput.classList.remove('border-red-500', 'ring-2', 'ring-red-200');
}, 2000);
return;
}
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);
});
updateNavButtons();
};
const navigateTabs = (direction) => {
const currentIndex = tabs.indexOf(currentTab);
let nextIndex = currentIndex + direction;
if (nextIndex >= 0 && nextIndex < tabs.length) {
switchTab(tabs[nextIndex]);
}
};
// --- PDF GENERATION ---
const downloadPdf = () => {
if (!leiData) return;
const { attributes } = leiData;
const entity = attributes.entity;
const registration = attributes.registration;
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFontSize(18);
doc.text("Legal Entity Identifier (LEI) Report", 14, 22);
doc.setFontSize(12);
doc.text(`LEI: ${attributes.lei}`, 14, 32);
const tableBody = [
['Legal Name', entity.legalName.name],
['Status', entity.status],
['Jurisdiction', entity.jurisdiction],
['Initial Registration Date', new Date(registration.initialRegistrationDate).toLocaleDateString()],
['Last Update Date', new Date(attributes.lastUpdateDate).toLocaleDateString()],
['Next Renewal Date', new Date(registration.nextRenewalDate).toLocaleDateString()],
['Managing LOU', registration.managingLou],
['Legal Address', `${entity.legalAddress.addressLines.join(', ')}, ${entity.legalAddress.city}, ${entity.legalAddress.country}`],
['Headquarters Address', `${entity.headquartersAddress.addressLines.join(', ')}, ${entity.headquartersAddress.city}, ${entity.headquartersAddress.country}`],
];
doc.autoTable({
startY: 40,
head: [['Field', 'Information']],
body: tableBody,
theme: 'grid',
headStyles: { fillColor: [45, 102, 193] },
columnStyles: { 0: { fontStyle: 'bold' } }
});
doc.save(`LEI_Report_${attributes.lei}.pdf`);
};
// --- EVENT LISTENERS & FINAL SETUP ---
checkLeiBtn.addEventListener('click', () => {
const leiValue = leiInput.value.trim().toUpperCase();
if (leiValue.length === 20) {
fetchLeiData(leiValue);
} else {
resultsContent.innerHTML = `
Invalid Input
An LEI must be exactly 20 characters long.
`;
lucide.createIcons();
leiData = null;
updateNavButtons();
}
});
document.getElementById('download-pdf-btn').addEventListener('click', downloadPdf);
updateNavButtons();
lucide.createIcons();
prevBtn.addEventListener('click', () => navigateTabs(-1));
nextBtn.addEventListener('click', () => navigateTabs(1));
});