Please provide at least two core concepts to generate topics.
';
return;
}
const topics = [
{ type: "Impact Study", text: `The Impact of ${data.concept1} on ${data.concept2} ${data.context || ''}.` },
{ type: "Correlational Study", text: `An Analysis of the Relationship Between ${data.concept1} and ${data.concept2} ${data.context || ''}.` },
{ type: "Exploratory Study", text: `Exploring the Role of ${data.concept1} in Influencing ${data.concept2} ${data.context || ''}.` },
{ type: "Comparative Analysis", text: `A Comparative Study of Method A vs. ${data.concept1} in affecting ${data.concept2}.` },
{ type: "Case Study", text: `A Case Study on the Implementation of ${data.concept1} and its Effects on ${data.concept2} ${data.context || ''}.` }
];
let html = `
Potential Research Topics
`;
topics.forEach(topic => {
html += `- ${topic.type}${topic.text.trim()}
`;
});
html += `
`;
topicsContainer.innerHTML = html;
}
function showMessage() {
messageBox.classList.remove('opacity-0', 'translate-y-10');
messageBox.classList.add('opacity-100', 'translate-y-0');
setTimeout(() => {
messageBox.classList.remove('opacity-100', 'translate-y-0');
messageBox.classList.add('opacity-0', 'translate-y-10');
}, 2000);
}
function generatePdf() {
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
const data = getFormData();
const topicsContainer = document.getElementById('topics-container');
const margin = 20;
const pageW = pdf.internal.pageSize.getWidth();
let y = 0;
const lineH = 7;
const today = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
const addHeaderFooter = (title) => {
const pageCount = pdf.internal.getNumberOfPages();
for (let i = 1; i <= pageCount; i++) {
pdf.setPage(i);
pdf.setFontSize(9);
pdf.setTextColor('#9ca3af');
pdf.text(title, margin, 12);
pdf.text(`Page ${i}`, pageW - margin, pdf.internal.pageSize.getHeight() - 10, { align: 'right' });
}
};
const addSectionHeader = (title) => {
y += lineH * 1.5;
if (y > 250) { pdf.addPage(); y = margin; }
pdf.setFontSize(16);
pdf.setFont('helvetica', 'bold');
pdf.setTextColor('#4c1d95'); // violet-900
pdf.text(title, margin, y);
y += lineH * 1.5;
};
const addText = (text, options={}) => {
const {size=10, style='normal', color='#334155', indent=0} = options;
if (!text || y > 260) {
if(y > 260) {
pdf.addPage(); y = margin;
} else {
return;
}
}
pdf.setFontSize(size);
pdf.setFont('helvetica', style);
pdf.setTextColor(color);
const lines = pdf.splitTextToSize(text, pageW - (margin * 2) - indent);
pdf.text(lines, margin + indent, y);
y += lines.length * lineH * 0.8;
};
// --- Build PDF Document ---
pdf.setFontSize(28);
pdf.setFont('helvetica', 'bold');
pdf.setTextColor('#1e293b');
pdf.text('Research Topic Exploration', margin, 35);
pdf.setFontSize(11);
pdf.setTextColor('#64748b');
pdf.text(`Generated on ${today}`, margin, 42);
y = 60;
addSectionHeader("Core Concepts");
addText(`Broad Subject: ${data.subject || 'N/A'}`, {style: 'bold'});
addText(`Specific Field: ${data.field || 'N/A'}`, {style: 'bold'});
y += lineH * 0.5;
addText(`Concept 1: ${data.concept1 || 'N/A'}`);
addText(`Concept 2: ${data.concept2 || 'N/A'}`);
addText(`Context: ${data.context || 'N/A'}`);
y += lineH;
addSectionHeader("Generated Research Topics");
const topicItems = topicsContainer.querySelectorAll('li');
topicItems.forEach(item => {
if (y > 250) { pdf.addPage(); y = margin; }
const type = item.querySelector('.topic-type').textContent;
const text = item.textContent.replace(type, '').trim();
addText(type, {style: 'bold', size: 9, color: '#6d28d9'});
addText(text, {indent: 2});
y += lineH;
});
addHeaderFooter('Research Topic Exploration');
pdf.save(`Research_Topics_${data.subject.replace(/\s/g, '_')}.pdf`);
}
// --- Event Listeners & Init ---
tabs.forEach(tab => tab.addEventListener('click', () => goToTab(parseInt(tab.dataset.tab))));
prevButton.addEventListener('click', () => goToTab(currentTab - 1));
nextButton.addEventListener('click', () => goToTab(currentTab + 1));
copyButton.addEventListener('click', () => {
const topics = document.getElementById('topics-container');
if(topics) {
navigator.clipboard.writeText(topics.innerText).then(() => {
showMessage();
}).catch(err => console.error('Copy failed:', err));
}
});
pdfDownloadButton.addEventListener('click', generatePdf);
updateTabUI();
});