import berater from "../../shared/berater-daten.json";
import "./berater.css";
const container = document.querySelector("#advisor-profiles");
function escapeHtml(value) {
return String(value).replace(
/[&<>"']/g,
(character) =>
({
"&": "&",
"<": "<",
">": ">",
'"': """,
"'": "'",
})[character],
);
}
function contactName(person) {
return (
(typeof person.spitzname === "string" && person.spitzname.trim()) ||
person.vorname ||
person.name.trim().split(/\s+/)[0]
);
}
if (container) {
if (!Array.isArray(berater) || berater.length === 0) {
container.innerHTML =
'
Aktuell sind keine Beraterprofile verfügbar.
';
} else {
container.innerHTML = berater
.map(
(person) => `
${(person.bilder || [])
.map(
(bild, index) => `
`,
)
.join("")}
${escapeHtml(person.name)}
${escapeHtml(person.titel || "Ernährungsberatung")}
Kurzbiografie
${escapeHtml(person.biographie)}
Qualifikationen
${(person.qualifikationen || []).map((qualification) => `- ${escapeHtml(qualification)}
`).join("")}
Schwerpunkte
${(person.schwerpunkte || []).map((focus) => `- ${escapeHtml(focus)}
`).join("")}
`,
)
.join("");
}
}
document.addEventListener("click", async (event) => {
const galleryControl = event.target.closest(
"button[data-gallery-direction], button[data-gallery-index]",
);
if (galleryControl) {
const gallery = galleryControl.closest(".advisor-gallery");
const slides = [...gallery.querySelectorAll(".advisor-gallery__slide")];
const currentIndex = Number(gallery.dataset.currentIndex || 0);
const requestedIndex = galleryControl.hasAttribute(
"data-gallery-direction",
)
? currentIndex +
(galleryControl.dataset.galleryDirection === "next" ? 1 : -1)
: Number(galleryControl.dataset.galleryIndex);
const nextIndex = (requestedIndex + slides.length) % slides.length;
gallery.dataset.currentIndex = String(nextIndex);
gallery.querySelector(".advisor-gallery__track").style.transform =
`translateX(-${nextIndex * 100}%)`;
slides.forEach((slide, index) => {
slide.setAttribute("aria-hidden", String(index !== nextIndex));
});
gallery.querySelectorAll("[data-gallery-index]").forEach((button) => {
button.setAttribute(
"aria-current",
String(Number(button.dataset.galleryIndex) === nextIndex),
);
});
return;
}
const button = event.target.closest("button[data-berater-id]");
if (!button) return;
try {
const { openContactDialog } = await import(
/* @vite-ignore */ "../contact/contact-dialog.js"
);
openContactDialog({ advisorId: button.dataset.beraterId });
} catch (error) {
console.error(
"Das Kontaktformular ist derzeit nicht verfügbar.",
error,
);
button.insertAdjacentHTML(
"afterend",
'Das Kontaktformular ist momentan nicht verfügbar.
',
);
button.disabled = true;
}
});