`;
// Communication Script Summary
summaryHtml += `
`;
summaryContent.innerHTML = summaryHtml;
};
downloadPdfBtn.addEventListener('click', () => {
if (!window.jspdf || !window.jspdf.jsPDF.autoTable) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'pt', format: 'letter' });
const getValue = id => document.getElementById(id).value;
const page = { width: doc.internal.pageSize.getWidth(), margin: 72 };
let y = page.margin;
// PDF Content
doc.setFont('times', 'bold');
doc.setFontSize(22);
doc.text('Cart Recovery System Configuration', page.width / 2, y, { align: 'center' });
y += 30;
doc.setFont('times', 'normal');
doc.setFontSize(14);
doc.text(getValue('companyName'), page.width / 2, y, { align: 'center' });
y += 40;
// Rules Section
const abandonTime = document.getElementById('abandonTime');
doc.setFont('times', 'bold');
doc.setFontSize(16);
doc.text('I. Recovery Rules', page.margin, y);
y += 20;
doc.setFont('times', 'normal');
doc.setFontSize(11);
doc.text(`- Cart is considered "abandoned" after ${abandonTime.options[abandonTime.selectedIndex].text} of inactivity.`, page.margin, y);
y += 30;
// Sequence Table
doc.setFont('times', 'bold');
doc.setFontSize(14);
doc.text('Recovery Sequence:', page.margin, y);
y += 20;
const head = [['Step', 'Send After', 'Channel', 'Incentive']];
const body = [];
document.querySelectorAll('.dynamic-step').forEach((step, index) => {
const delay = step.querySelector('.step-delay');
const channel = step.querySelector('.step-channel');
const offer = step.querySelector('.step-offer');
body.push([
`Step ${index + 1}`,
delay.options[delay.selectedIndex].text,
channel.options[channel.selectedIndex].text,
offer.options[offer.selectedIndex].text
]);
});
doc.autoTable({ startY: y, head, body, theme: 'grid', headStyles: { fillColor: [5, 150, 105] } });
y = doc.autoTable.previous.finalY + 40;
// Scripts Section
doc.setFont('times', 'bold');
doc.setFontSize(16);
doc.text('II. Communication Scripts', page.margin, y);
y += 20;
const addScriptSection = (title, content) => {
if (y > doc.internal.pageSize.getHeight() - 100) { doc.addPage(); y = page.margin; }
doc.setFont('times', 'bold');
doc.setFontSize(12);
doc.text(title, page.margin, y);
y += 15;
doc.setFont('times', 'normal');
doc.setFontSize(10);
const lines = doc.splitTextToSize(content, page.width - page.margin * 2);
doc.rect(page.margin, y - 10, page.width - page.margin*2, lines.length * 10 * 1.5 + 10);
doc.text(lines, page.margin + 5, y, { lineHeightFactor: 1.5 });
y += lines.length * 10 * 1.5 + 25;
};
addScriptSection('Initial Reminder Message:', getValue('reminderScript'));
addScriptSection('Follow-up with Offer Message:', getValue('offerScript'));
doc.save(`${getValue('systemName') || 'Cart-Recovery-Config'}.pdf`);
});
// --- Initial Setup ---
addStepBlock();
switchTab('setup');
});
Communication Scripts
Reminder Script:
${getValue('reminderScript').replace(/\n/g, '
')}
Offer Script:
${getValue('offerScript').replace(/\n/g, '
')}
