`;
summaryHtml += `
`;
});
summaryHtml += ``;
summaryHtml += `
`;
});
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;
doc.setFont('times', 'bold');
doc.setFontSize(22);
doc.text('Shopping Assistant Chatbot Configuration', page.width / 2, y, { align: 'center' });
y += 30;
doc.setFont('times', 'normal');
doc.setFontSize(14);
doc.text(getValue('chatbotName'), page.width / 2, y, { align: 'center' });
y += 40;
const addSection = (title, content) => {
doc.setFont('times', 'bold');
doc.setFontSize(16);
doc.text(title, page.margin, y);
y += 20;
doc.setFont('times', 'normal');
doc.setFontSize(11);
const lines = doc.splitTextToSize(content, page.width - page.margin * 2);
doc.text(lines, page.margin, y, { lineHeightFactor: 1.5 });
y += lines.length * 11 * 1.5 + 20;
};
const tone = document.getElementById('tone');
addSection('I. Setup & Personality', `Personality: ${tone.options[tone.selectedIndex].text}\n\nWelcome Message:\n${getValue('welcomeMessage')}`);
doc.addPage();
y = page.margin;
// Q&A Table
doc.setFont('times', 'bold');
doc.setFontSize(16);
doc.text('II. Conversation Flow', page.margin, y);
y += 20;
const qaHead = [['User Asks About', 'Chatbot Responds With']];
const qaBody = [];
document.querySelectorAll('#qaContainer .dynamic-block').forEach(b => {
qaBody.push([b.querySelector('.qa-query').value, b.querySelector('.qa-response').value]);
});
doc.autoTable({ startY: y, head: qaHead, body: qaBody, theme: 'grid', headStyles: { fillColor: [13, 148, 136] } });
y = doc.autoTable.previous.finalY + 30;
// Rules Table
doc.setFont('times', 'bold');
doc.setFontSize(16);
doc.text('III. Product Recommendation Rules', page.margin, y);
y += 20;
const rulesHead = [['If User Mentions Keywords', 'Recommend Product(s)']];
const rulesBody = [];
document.querySelectorAll('#rulesContainer .dynamic-block').forEach(b => {
rulesBody.push([b.querySelector('.rule-keywords').value, b.querySelector('.rule-products').value]);
});
doc.autoTable({ startY: y, head: rulesHead, body: rulesBody, theme: 'grid', headStyles: { fillColor: [13, 148, 136] } });
doc.save(`${getValue('chatbotName') || 'Chatbot-Config'}.pdf`);
});
// --- Initial Setup ---
addQaBlock();
addRuleBlock();
switchTab('setup');
});
Conversation Flow
`; document.querySelectorAll('#qaContainer .dynamic-block').forEach(b => { summaryHtml += `User Query: ${b.querySelector('.qa-query').value}
Bot Response: ${b.querySelector('.qa-response').value}
Product Rules
`; document.querySelectorAll('#rulesContainer .dynamic-block').forEach(b => { summaryHtml += `Keywords: ${b.querySelector('.rule-keywords').value}
Recommendations: ${b.querySelector('.rule-products').value}
