No points were added in the configuration.
";
}
}
configItems.forEach((item, index) => {
const code = item.querySelector(".apg-config-code")?.value || "";
const meridian =
item.querySelector(".apg-config-meridian")?.value || "";
const location =
item.querySelector(".apg-config-location")?.value || "";
const notes = item.querySelector(".apg-config-notes")?.value || "";
const dashId = index + 1;
const newDashItem = document.createElement("div");
newDashItem.className = "apg-dynamic-item apg-dash-item";
// Create *editable* fields for the dashboard
newDashItem.innerHTML = `
`;
// Add listener to update dash title
const dashCodeInput = newDashItem.querySelector(".apg-dash-code");
const dashTitleH3 = newDashItem.querySelector(
".apg-point-title-dash"
);
if (dashCodeInput && dashTitleH3) {
dashCodeInput.addEventListener("input", () => {
dashTitleH3.textContent = dashCodeInput.value || "Point";
});
}
if (dashboardList) {
dashboardList.appendChild(newDashItem);
}
});
// 4. Switch to Dashboard
showTab("apg-tab-dashboard");
});
}
// --- PDF Download Logic ---
if (pdfBtn) {
pdfBtn.addEventListener("click", function () {
// Check for jsPDF and jsPDF-AutoTable
if (
typeof window.jspdf === "undefined" ||
typeof window.jspdf.jsPDF.autoTable === "undefined"
) {
alert(
"Error: PDF libraries (jsPDF, jsPDF-AutoTable) could not be loaded. Please check your internet connection and try again."
);
console.error("jsPDF or jsPDF.autoTable is not defined.");
return;
}
try {
const { jsPDF } = window.jspdf;
const doc = new jsPDF("p", "pt", "a4");
const margin = 40;
let yPos = margin;
// 1. Get Title from EDITABLE DASHBOARD
const title = dashTitleInput?.value || "Acupuncture Points Sheet";
// 2. Add Title to PDF
doc.setFontSize(18);
doc.setFont("helvetica", "bold");
const splitTitle = doc.splitTextToSize(
title,
doc.internal.pageSize.getWidth() - margin * 2
);
doc.text(splitTitle, margin, yPos);
yPos += doc.getTextDimensions(splitTitle).h + 20;
// 3. Prepare Table Data from DASHBOARD
const tableHead = [["Point", "Meridian", "Location", "Indications"]];
const tableBody = [];
const dashItems = dashboardList.querySelectorAll(".apg-dash-item");
dashItems.forEach((item) => {
const code = item.querySelector(".apg-dash-code")?.value || "";
const meridian =
item.querySelector(".apg-dash-meridian")?.value || "";
const location =
item.querySelector(".apg-dash-location")?.value || "";
const notes = item.querySelector(".apg-dash-notes")?.value || "";
tableBody.push([code, meridian, location, notes]);
});
// 4. Create Table
doc.autoTable({
startY: yPos,
head: tableHead,
body: tableBody,
theme: "striped",
headStyles: {
fillColor: [0, 115, 230], // Blue
textColor: [255, 255, 255],
fontSize: 10,
},
bodyStyles: {
fontSize: 9,
cellPadding: 3,
},
columnStyles: {
0: { cellWidth: 80 }, // Point
1: { cellWidth: 80 }, // Meridian
2: { cellWidth: "auto" }, // Location
3: { cellWidth: "auto" }, // Indications
},
});
// 5. Save PDF
doc.save("Acupuncture-Points-Sheet.pdf");
} catch (e) {
console.error("Error generating PDF:", e);
alert("An error occurred while generating the PDF.");
}
});
}
// --- Initialization ---
// Pre-populate with sample data
addPoint({
code: "LI4 (Hegu)",
meridian: "Large Intestine",
location:
"On the dorsum of the hand, between the 1st and 2nd metacarpal bones, at the midpoint of the 2nd metacarpal bone.",
notes:
"Headache, toothache, sore throat, facial pain, nasal congestion, general pain relief. *Contraindicated in pregnancy.*",
});
addPoint({
code: "ST36 (Zusanli)",
meridian: "Stomach",
location:
"3 cun below ST35, one finger-breadth from the anterior crest of the tibia, in the tibialis anterior muscle.",
notes:
"Gastric pain, vomiting, nausea, digestive issues, boosts energy and immune system, general wellness.",
});
// Ensure the default tab is active
showTab("apg-tab-dashboard");
});