Auto-Generated Refund Policy Creator

Auto-Generated Refund Policy Creator

Easily create a comprehensive refund policy for your business.

If you have any questions about our Returns and Refunds Policy, please contact us at: ${contactEmail}

`; return policyHtml; }; // --- UI & RENDERING FUNCTIONS --- const renderPolicyPreview = () => { const previewContent = document.getElementById('content-policy-preview'); if (!previewContent) return; const policyHtml = generatePolicyText(); previewContent.innerHTML = `
${policyHtml}
`; document.getElementById('download-pdf-btn').addEventListener('click', generatePdf); }; const renderDataConfig = () => { const configContent = document.getElementById('content-data-config'); if (!configContent) return; configContent.innerHTML = `
Company Information
Policy Details
`; document.getElementById('update-data-btn').addEventListener('click', handleConfigUpdate); }; const handleConfigUpdate = () => { appData.companyName = document.getElementById('companyName').value; appData.websiteUrl = document.getElementById('websiteUrl').value; appData.contactEmail = document.getElementById('contactEmail').value; appData.refundPeriod = parseInt(document.getElementById('refundPeriod').value) || 30; appData.policyTypes.physical = document.getElementById('covers-physical').checked; appData.policyTypes.digital = document.getElementById('covers-digital').checked; appData.policyTypes.services = document.getElementById('covers-services').checked; appData.refundConditions = document.getElementById('refundConditions').value; appData.nonRefundableItems = document.getElementById('nonRefundableItems').value; appData.refundProcess = document.getElementById('refundProcess').value; renderPolicyPreview(); alert('Policy updated! Check the preview.'); switchTab(0); }; const generatePdf = () => { loadingOverlay.style.display = 'flex'; const { jsPDF } = window.jspdf; const pdfContent = document.getElementById('pdf-content-area'); html2canvas(pdfContent, { scale: 2, useCORS: true, logging: false }) .then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'px', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / canvasHeight; const imgWidth = pdfWidth - 80; // Add margin const imgHeight = imgWidth / ratio; let heightLeft = imgHeight; let position = 0; pdf.addImage(imgData, 'PNG', 40, position + 40, imgWidth, imgHeight); heightLeft -= (pdfHeight - 80); while (heightLeft > 0) { position = heightLeft - imgHeight + 40; pdf.addPage(); pdf.addImage(imgData, 'PNG', 40, position, imgWidth, imgHeight); heightLeft -= pdfHeight; } pdf.save(`Refund-Policy-${appData.companyName.replace(/\s+/g, '-')}.pdf`); loadingOverlay.style.display = 'none'; }).catch(err => { console.error("PDF generation failed:", err); loadingOverlay.style.display = 'none'; alert('An error occurred generating the PDF.'); }); }; // --- TAB NAVIGATION & INITIALIZATION --- const switchTab = (tabIndex) => { activeTabIndex = tabIndex; document.querySelectorAll('.tab-btn').forEach((btn, i) => btn.classList.toggle('active', i === tabIndex)); document.querySelectorAll('.tab-content').forEach((content, i) => content.classList.toggle('hidden', i !== tabIndex)); updateNavButtons(); }; const updateNavButtons = () => { prevTabBtn.disabled = activeTabIndex === 0; nextTabBtn.disabled = activeTabIndex === tabIdentifiers.length - 1; }; const initializeUI = () => { const tabs = [ { name: 'Policy Preview', id: 'policy-preview' }, { name: 'Policy Configuration', id: 'data-config' } ]; tabIdentifiers = tabs.map(t => t.id); tabsContainer.innerHTML = tabs.map(tab => ``).join(''); mainContent.innerHTML = tabs.map(tab => `
`).join(''); tabs.forEach((tab, index) => { document.getElementById(`tab-${tab.id}`).addEventListener('click', () => switchTab(index)); }); renderPolicyPreview(); renderDataConfig(); switchTab(0); }; initializeUI(); lucide.createIcons(); prevTabBtn.addEventListener('click', () => { if (activeTabIndex > 0) switchTab(activeTabIndex - 1); }); nextTabBtn.addEventListener('click', () => { if (activeTabIndex < tabIdentifiers.length - 1) switchTab(activeTabIndex + 1); }); });
Scroll to Top