6. Governing Law & Jurisdiction
These Terms shall be governed and construed in accordance with the laws of ${jurisdiction}, without regard to its conflict of law provisions.
7. Contact Information
Questions about these Terms should be sent to us at: ${email}.
`;
}
function getPrivacyPolicyContent(data) {
const company = data.meta.company || 'the Company';
const url = data.meta.url || 'the website';
const email = data.meta.email || 'the designated contact email';
const collectedList = data.privacy.collected.split(',').map(c => c.trim()).filter(c => c.length > 0);
let content = `
1. Information We Collect
We collect various types of information for purposes of providing and improving our Service. This includes personal identification information (PII) and usage data. Specifically, we collect: ${collectedList.join('; ')}.
2. How We Use Your Data
We use the collected data for the following primary purposes: ${data.privacy.usage}
3. Data Security
The security of your data is important to us, but remember that no method of transmission over the Internet or method of electronic storage is 100% secure. We strive to use commercially acceptable means to protect your Personal Data but cannot guarantee its absolute security.
`;
// Add GDPR Clause
if (data.privacy.gdpr) {
content += `
4. GDPR Rights (EU Users)
If you are a resident of the European Economic Area (EEA), you have certain data protection rights, including the right to access, rectify, or erase your Personal Data (Right to be Forgotten).
`;
}
// Add CCPA Clause
if (data.privacy.ccpa) {
content += `
5. CCPA Rights (California)
If you are a California resident, you may be entitled to certain information regarding the disclosure of Personal Data to third parties for their direct marketing purposes. We do not sell your personal data.
`;
}
content += `
6. Contact for Privacy Questions
If you have any questions about this Privacy Policy, please contact us by email at ${email}.
`;
return content;
}
// --- 5. RENDER LOGIC ---
function renderAll() {
// 1. Sync Data from Inputs
Object.keys(legalData.meta).forEach(key => { if (inputs[key]) legalData.meta[key] = inputs[key].value; });
Object.keys(legalData.tos).forEach(key => { if (inputs[key]) legalData.tos[key] = inputs[key].value; });
Object.keys(legalData.privacy).forEach(key => { if (inputs[key] && inputs[key].type !== 'checkbox') legalData.privacy[key] = inputs[key].value; });
legalData.privacy.gdpr = inputs.gdpr.checked;
legalData.privacy.ccpa = inputs.ccpa.checked;
// 2. Update Metadata Headers
outputs.dateTos.textContent = inputs.date.value || "Draft Date";
outputs.datePp.textContent = inputs.date.value || "Draft Date";
outputs.jurisdiction.textContent = inputs.jurisdiction.value || "N/A";
let badges = [];
if (legalData.privacy.gdpr) badges.push('GDPR');
if (legalData.privacy.ccpa) badges.push('CCPA');
outputs.complianceBadges.textContent = badges.join(', ') || "None Specified";
// 3. Render Document Bodies
outputs.tosBody.innerHTML = getTOSContent(legalData);
outputs.ppBody.innerHTML = getPrivacyPolicyContent(legalData);
}
// --- 6. EVENT LISTENERS ---
function attachListeners() {
// Attach listener to every single input/textarea/checkbox
const allInputs = document.querySelectorAll('.lg-input, .lg-checkbox-label input');
allInputs.forEach(inp => inp.addEventListener('input', renderAll));
}
// --- 7. TAB NAVIGATION ---
window.lgSwitchTab = function(tabId) {
document.querySelectorAll('.lg-tab-pane').forEach(p => p.classList.remove('active'));
document.querySelectorAll('.lg-tab-btn').forEach(b => b.classList.remove('active'));
document.getElementById(tabId).classList.add('active');
document.querySelector(`.lg-tab-btn[data-tab="${tabId}"]`).classList.add('active');
document.getElementById('legal-generator-tool').scrollIntoView({behavior: 'smooth'});
};
document.querySelectorAll('.lg-tab-btn').forEach(btn => {
btn.addEventListener('click', function() { lgSwitchTab(this.dataset.tab); });
});
// --- 8. PDF EXPORT ---
const btnDown = document.getElementById('lg-download-btn');
if(btnDown) {
btnDown.addEventListener('click', function() {
renderAll();
const element = document.getElementById('lg-render-area');
const filename = (inputs.company.value || 'Legal_Packet').replace(/[^a-z0-9]/gi, '_');
const opt = {
margin: 0.5,
filename: `${filename}_Legal_Packet.pdf`,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, useCORS: true },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
const origText = btnDown.innerText;
btnDown.innerText = "Generating Documents...";
html2pdf().set(opt).from(element).save().then(() => {
btnDown.innerText = origText;
});
});
}
// Start
init();
});