Automated Refund Policy Explainer
Simplify your refund policy into easy-to-understand answers for your customers.
Full Refund Policy Text
Key Policy Rules
Tell us about your purchase
Your Simplified Refund Explanation
Please enter your query on the previous tab to get an explanation.
${result.message}
`; }; // --- Event Handlers --- generateExplanationBtn.addEventListener('click', () => { saveConfig(); // Ensure latest policy rules are used generateExplanation(); switchTab('result'); }); // --- Tab & Navigation Logic --- function switchTab(targetTabId) { if(currentTab === 'config') saveConfig(); currentTab = targetTabId; const currentIndex = TABS_ORDER.indexOf(currentTab); tabs.forEach(tab => tab.classList.toggle('active', tab.dataset.tab === currentTab)); tabContents.forEach(content => content.classList.toggle('active', content.id === currentTab)); updateNavButtons(currentIndex); } function updateNavButtons(currentIndex) { prevBtn.style.display = (currentIndex === 0) ? 'none' : 'inline-flex'; nextBtn.style.display = (currentIndex === TABS_ORDER.length - 1) ? 'none' : 'inline-flex'; pdfButtonContainer.style.display = (currentTab === 'result') ? 'block' : 'none'; } tabs.forEach(tab => tab.addEventListener('click', () => switchTab(tab.dataset.tab))); nextBtn.addEventListener('click', () => { const currentIndex = TABS_ORDER.indexOf(currentTab); if (currentIndex < TABS_ORDER.length - 1) { switchTab(TABS_ORDER[currentIndex + 1]); } }); prevBtn.addEventListener('click', () => { const currentIndex = TABS_ORDER.indexOf(currentTab); if (currentIndex > 0) { switchTab(TABS_ORDER[currentIndex - 1]); } }); // --- PDF Download --- downloadPdfBtn.addEventListener('click', async () => { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const content = document.getElementById('pdf-content'); document.getElementById('pdf-date').textContent = `Generated on: ${new Date().toLocaleString()}`; const canvas = await html2canvas(content, { scale: 2 }); const imgData = canvas.toDataURL('image/jpeg', 1.0); const imgProps = doc.getImageProperties(imgData); const pdfWidth = doc.internal.pageSize.getWidth() - 28; const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; doc.addImage(imgData, 'JPEG', 14, 15, pdfWidth, pdfHeight); document.getElementById('pdf-date').textContent = ''; doc.save(`Refund-Explanation-${queryItemInput.value.replace(/\s/g, '_') || 'Report'}.pdf`); }); // --- Initial Load --- renderConfig(); updateNavButtons(0); // Initial state for buttons });