`).join('');
}
// --- CORE LOGIC ---
function handleQuerySubmit() {
const query = queryInput.value.trim();
if (!query) {
alert('Please enter a query.'); // Per specs, alert is okay for validation, but modals are preferred. Sticking to simple validation here.
return;
}
showLoadingResponse();
setTimeout(() => {
const response = generateAiResponse(query, state.config);
const timestamp = new Date().toLocaleString('en-US');
state.queryLog.unshift({ query, response, timestamp }); // Add to beginning
showSuccessResponse(response);
queryInput.value = '';
renderLog();
}, 1500); // Simulate network delay
}
function showLoadingResponse() {
responseContainer.innerHTML = `
`;
}
function showSuccessResponse(response) {
responseContainer.innerHTML = `
`;
}
function generateAiResponse(query, config) {
let response = `Based on your query for the **${config.industry}** sector, considering the jurisdictions of **${config.jurisdictions.join(', ')}**, here is a general analysis:\n\n`;
const qLower = query.toLowerCase();
if (qLower.includes('data privacy') || qLower.includes('personal information')) {
response += "Data privacy is a critical concern. Key regulations include:\n";
if (config.jurisdictions.includes('European Union (GDPR)')) {
response += "- **GDPR:** Requires explicit user consent, data breach notifications within 72 hours, and honors user rights like data portability and erasure.\n";
}
if (config.jurisdictions.includes('California (CCPA/CPRA)')) {
response += "- **CCPA/CPRA:** Grants California consumers the right to know about, delete, and opt-out of the sale or sharing of their personal information.\n";
}
if (config.industry === 'Healthcare' && config.jurisdictions.includes('Federal (USA)')) {
response += "- **HIPAA:** The Health Insurance Portability and Accountability Act strictly governs the use and disclosure of Protected Health Information (PHI).\n";
}
if (config.industry === 'Finance' && config.jurisdictions.includes('Federal (USA)')) {
response += "- **GLBA:** The Gramm-Leach-Bliley Act requires financial institutions to explain their information-sharing practices to their customers and to safeguard sensitive data.\n";
}
} else if (qLower.includes('reporting requirement') || qLower.includes('breach notification')) {
response += "Regarding incident reporting and breach notifications:\n";
if (config.industry === 'Finance' && config.jurisdictions.includes('New York (NYDFS)')) {
response += "- **NYDFS Cybersecurity Regulation:** Mandates notification to the NYDFS within 72 hours of determining a cybersecurity event has occurred.\n";
} else {
response += "- Most jurisdictions require 'prompt' or 'reasonable' notification to affected individuals and relevant authorities, typically within 30-60 days unless otherwise specified (e.g., GDPR's 72 hours).\n";
}
} else {
response += "Your query appears to be general. For specific guidance, please formulate a question related to topics like 'data privacy', 'reporting requirements', or 'consumer rights'. The bot will tailor its response based on the active configuration.\n";
}
response += "\n*Disclaimer: This is a simulated AI response for demonstration purposes and does not constitute legal advice. Always consult with a qualified legal professional for compliance matters.*";
return response;
}
// --- NAVIGATION & TAB LOGIC ---
function switchTab(tabName) {
updateUIFromState(); // Ensure UI is fresh before switching
tabNavigation.querySelectorAll('.tab-button').forEach(btn => btn.classList.toggle('active', btn.dataset.tab === tabName));
tabContents.querySelectorAll('.tab-content').forEach(content => content.classList.toggle('active', content.id === `${tabName}-tab`));
updateNavButtons();
}
function navigateTabs(direction) {
currentTabIndex = Math.max(0, Math.min(tabs.length - 1, currentTabIndex + direction));
switchTab(tabs[currentTabIndex]);
}
function updateNavButtons() {
prevBtn.style.visibility = currentTabIndex === 0 ? 'hidden' : 'visible';
nextBtn.style.visibility = currentTabIndex === tabs.length - 1 ? 'hidden' : 'visible';
}
// --- PDF GENERATION ---
function generatePDF() {
if(state.queryLog.length === 0) {
alert("Query log is empty. Nothing to download.");
return;
}
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFontSize(20);
doc.setFont("helvetica", "bold");
doc.text("AI Compliance Bot - Query Log", 105, 20, { align: 'center' });
doc.setFontSize(10);
doc.text(`Report Generated: ${new Date().toLocaleString('en-US')}`, 105, 26, {align: 'center'});
const body = state.queryLog.map(entry => {
return [{ content: `Q: ${entry.query}\n\nTimestamp: ${entry.timestamp}`, styles: { fontStyle: 'bold' } }, { content: entry.response }];
});
doc.autoTable({
startY: 35,
head: [['Query Details', 'AI-Generated Response']],
body: body,
theme: 'grid',
headStyles: { fillColor: [20, 184, 166] }, // Teal
columnStyles: {
0: { cellWidth: 60 },
1: { cellWidth: 'auto' }
},
didParseCell: function(data) {
if (data.section === 'body') {
data.cell.styles.valign = 'top';
}
}
});
doc.save('AI_Compliance_Log.pdf');
}
// --- START THE APP ---
init();
});
Generating Response...
The AI is analyzing your query based on the configured industry and jurisdictions. Please wait.
AI Compliance Analysis
${response}
