`;
}
function updatePreview(){
previewEl.innerHTML = generatePreviewHTML();
// apply inline styles for preview container (keeps colors)
const header = previewEl.querySelector('.terms-header');
if(header){
header.style.background = `linear-gradient(135deg, ${primary}, ${secondary})`;
}
}
// Generate HTML code (standalone) for copying
function generateStandaloneHTML(){
const inner = generatePreviewHTML();
const style = `
`;
return `${style}\n${inner}`;
}
// Copy to clipboard
copyBtn.addEventListener('click', function(){
const code = generateStandaloneHTML();
// try clipboard
navigator.clipboard.writeText(code).then(()=>{
notif.classList.add('show');
setTimeout(()=> notif.classList.remove('show'), 3000);
}).catch(err=>{
alert('Copy failed. Please select and copy manually.');
console.error(err);
});
});
previewBtn.addEventListener('click', updatePreview);
// Reset default values
resetBtn.addEventListener('click', function(){
companyEl.value = 'Your Company Name';
websiteEl.value = 'https://www.example.com';
emailEl.value = 'info@example.com';
effectiveDateEl.value = (new Date()).toISOString().slice(0,10);
jurisdictionEl.value = 'State/Country name';
userObligationsEl.value = 'You agree to use the Service in compliance with applicable laws, not to abuse the service, and to keep your credentials secure.';
prohibitedEl.value = 'Unauthorized access, distribution of malware, infringement of IP, illegal activities.';
terminationEl.value = 'We may suspend or terminate accounts that violate these terms or for any reason with notice where required by law.';
liabilityEl.value = 'To the fullest extent permitted by law, we are not liable for indirect, incidental, or consequential damages.';
ipEl.value = 'All content on the Site is owned or licensed by the Company. Unauthorized use is prohibited.';
modificationEl.value = 'We may update these terms from time to time. Continued use after changes constitutes acceptance.';
cookiesEl.value = 'Use of cookies and privacy practices are described in our Privacy Policy.';
// reset color
document.querySelectorAll('.color-option').forEach((o,i)=>{ o.classList.toggle('active', i===0); });
primary = '#4a6fa5'; secondary = '#166088';
updatePreview();
});
// initial render
updatePreview();
// also update preview on field changes (light autosync)
const inputs = [companyEl, websiteEl, emailEl, effectiveDateEl, jurisdictionEl, userObligationsEl, prohibitedEl, terminationEl, liabilityEl, ipEl, modificationEl, cookiesEl];
inputs.forEach(inp => inp.addEventListener('input', updatePreview));
})();