`;
}).join('');
}
function renderSetupUI() {
setupSections.innerHTML = Object.keys(state.categories).map(key => `
`).join('');
}
// --- Core Logic & Event Handlers ---
function handleChecklistClick(e) {
if (e.target.type === 'checkbox') {
const taskId = Number(e.target.dataset.id);
for (const category in state.tasks) {
const task = state.tasks[category].find(t => t.id === taskId);
if (task) {
task.completed = e.target.checked;
break;
}
}
renderChecklists(); // Re-render to apply 'completed' class
renderDashboard();
}
}
function handleSetupClick(e) {
const btn = e.target.closest('button');
if (!btn) return;
const category = btn.dataset.category;
if (btn.textContent === 'Add Task') {
const input = container.querySelector(`#add-task-${category}`);
const text = input.value.trim();
if (text) {
state.tasks[category].push({ id: Date.now(), text, completed: false });
input.value = '';
renderAll();
}
} else if (btn.textContent === 'Remove') {
const id = Number(btn.dataset.id);
state.tasks[category] = state.tasks[category].filter(t => t.id !== id);
renderAll();
}
}
// --- PDF Generation ---
async function downloadPDF() {
try {
const { jsPDF } = window.jspdf;
const doc = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' });
let yPos = 20;
doc.setFontSize(22);
doc.setTextColor(primaryColor);
doc.text('Post-Merger Integration Plan', doc.internal.pageSize.getWidth() / 2, yPos, { align: 'center' });
yPos += 15;
for (const category in state.categories) {
const tasks = state.tasks[category];
if (tasks.length === 0) continue;
if (yPos > 250) { // Add new page if not enough space
doc.addPage();
yPos = 20;
}
const completedTasks = tasks.filter(t => t.completed).length;
const totalTasks = tasks.length;
doc.setFontSize(16);
doc.setTextColor(primaryColor);
doc.text(`${state.categories[category]} (${completedTasks}/${totalTasks})`, 14, yPos);
yPos += 8;
const body = tasks.map(task => [task.completed ? '✅' : '🔲', task.text]);
doc.autoTable({
startY: yPos,
head: [['Status', 'Task Description']],
body: body,
theme: 'grid',
headStyles: { fillColor: primaryColor, textColor: textLightColor },
didDrawPage: data => { yPos = data.cursor.y; }
});
yPos += 5;
}
doc.save('Post_Merger_Integration_Plan.pdf');
} catch (e) {
console.error("PDF Generation Failed:", e);
alert("An error occurred generating the PDF.");
}
}
// --- Event Listeners ---
tabs.forEach((tab, index) => tab.addEventListener('click', () => showTab(index)));
nextBtn.addEventListener('click', () => showTab(currentTabIndex + 1));
prevBtn.addEventListener('click', () => showTab(currentTabIndex - 1));
container.querySelector('.pmip-tab-content-wrapper').addEventListener('click', handleChecklistClick);
setupSections.addEventListener('click', handleSetupClick);
// --- PDF Dependency Loader & Listener ---
(function loadPdfDependencies() {
const scripts = [
"https://cdnjs.cloudflare.com/ajax/libs/jspdf/2.5.1/jspdf.umd.min.js",
"https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/3.8.2/jspdf.plugin.autotable.min.js",
];
let scriptsLoaded = 0;
downloadPdfBtn.disabled = true;
downloadPdfBtn.title = "Loading PDF libraries...";
scripts.forEach(url => {
const script = document.createElement('script');
script.src = url;
script.async = true;
script.onload = () => {
scriptsLoaded++;
if (scriptsLoaded === scripts.length) {
downloadPdfBtn.disabled = false;
downloadPdfBtn.title = "Download Plan as PDF";
downloadPdfBtn.addEventListener('click', downloadPDF);
}
};
script.onerror = () => {
console.error(`Error loading script: ${url}`);
downloadPdfBtn.title = "PDF download disabled due to network error.";
};
document.head.appendChild(script);
});
})();
// --- Initial Setup ---
renderAll();
showTab(0);
}
initializeGenerator();
})();
${state.categories[key]}
${state.tasks[key].map(task => `
${task.text}
`).join('')}
