No relevant questions found. Try broadening your criteria.
';
return;
}
let html = `
Interview Questions for a ${experience} ${jobTitle}
`;
html += '
';
questions.forEach(q => {
html += `- ${q}
`;
});
html += '
';
outputContainer.innerHTML = html;
};
/**
* Generates and triggers the download of a PDF with the interview questions.
*/
const downloadPdf = () => {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({
orientation: 'p',
unit: 'mm',
format: 'a4'
});
// IV. B. Robust null checks for output content
const outputContent = outputContainer.querySelector('ol');
if (!outputContent) {
// Provide non-alert feedback as per standards
const originalButtonText = downloadPdfBtn.textContent;
downloadPdfBtn.textContent = 'Please generate questions first!';
const originalClasses = [...downloadPdfBtn.classList];
downloadPdfBtn.className = "bg-red-600 text-white font-bold py-3 px-8 rounded-lg transition duration-300 shadow-md";
setTimeout(() => {
downloadPdfBtn.textContent = originalButtonText;
downloadPdfBtn.className = originalClasses.join(' ');
}, 3000);
return;
}
const jobTitle = jobTitleInput.value.trim() || "Selected Role";
const experience = experienceLevelSelect.value;
const interviewType = interviewTypeSelect.value;
const generationDate = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
// --- PDF Header ---
doc.setFont('helvetica', 'bold');
doc.setFontSize(22);
doc.setTextColor(40, 40, 40); // Dark Gray
doc.text('Interview Question Report', doc.internal.pageSize.getWidth() / 2, 20, { align: 'center' });
doc.setFont('helvetica', 'normal');
doc.setFontSize(11);
doc.setTextColor(100);
doc.text(`Generated on: ${generationDate}`, 15, 30);
// --- Report Parameters Section ---
doc.setFont('helvetica', 'bold');
doc.setFontSize(12);
doc.setTextColor(67, 56, 202); // Main Theme Color (Indigo)
doc.text('Configuration Parameters', 15, 42);
doc.setDrawColor(67, 56, 202);
doc.line(15, 43, 65, 43); // Underline for the section header
doc.setFont('helvetica', 'normal');
doc.setFontSize(10);
doc.setTextColor(50);
const paramsText = `Job Title: ${jobTitle}\nExperience Level: ${experience}\nInterview Type: ${interviewType}`;
doc.text(paramsText, 15, 49);
// --- Table of Questions ---
const tableData = Array.from(outputContent.querySelectorAll('li')).map((li, index) => [index + 1, li.textContent]);
const startY = 65; // Start table lower to accommodate the new header
doc.autoTable({
startY: startY,
head: [['#', 'Generated Interview Question']],
body: tableData,
theme: 'striped', // A modern and clean theme
headStyles: {
fillColor: [67, 56, 202], // Indigo-700
textColor: 255,
fontStyle: 'bold'
},
styles: {
cellPadding: 2.5,
fontSize: 10,
valign: 'middle'
},
columnStyles: {
0: { cellWidth: 10, halign: 'center' },
// This next line is the critical fix for text wrapping
1: { cellWidth: 170 }
},
// --- Footer with Page Numbers ---
didDrawPage: function(data) {
let pageCount = doc.internal.getNumberOfPages();
doc.setFontSize(9);
doc.setTextColor(150);
doc.text(
'Page ' + doc.internal.getCurrentPageInfo().pageNumber + ' of ' + pageCount,
data.settings.margin.left,
doc.internal.pageSize.getHeight() - 10
);
doc.text(
'Generated by Interview Question Generator',
doc.internal.pageSize.getWidth() - data.settings.margin.right,
doc.internal.pageSize.getHeight() - 10,
{ align: 'right' }
);
}
});
doc.save(`Interview-Report-${jobTitle.replace(/\s+/g, '-')}.pdf`);
};
// --- IV. C. Event Handling ---
tabButtons.forEach(button => {
button.addEventListener('click', () => {
const tabNum = parseInt(button.dataset.tab);
if (tabNum === 2 && currentTab === 1) {
// Only generate if moving from config to results for the first time via tab click
generateQuestions();
}
showTab(tabNum);
});
});
prevBtn.addEventListener('click', () => {
if (currentTab > 1) {
showTab(currentTab - 1);
}
});
nextBtn.addEventListener('click', () => {
if (currentTab === 1) {
generateQuestions();
showTab(2);
} else if (currentTab === 2) {
// "Generate Again" functionality
generateQuestions();
}
});
downloadPdfBtn.addEventListener('click', downloadPdf);
// Initial setup
showTab(1);
});