document.addEventListener("DOMContentLoaded", () => {
    // Header laden
    const headerTarget = document.getElementById("header-placeholder");
    if (headerTarget) {
        fetch("/header")
            .then(response => {
                if (!response.ok) throw new Error("Header nicht gefunden");
                return response.text();
            })
            .then(data => {
                headerTarget.innerHTML = data;
            })
            .catch(error => {
                headerTarget.innerHTML = `
                    <div style="background: #ffdede; color: #a00; padding: 10px; text-align: center;">
                        Fehler beim Laden des Headers.
                    </div>`;
                console.error(error);
            });
    }

    // Footer laden
    const footerTarget = document.getElementById("footer");
    if (footerTarget) {
        fetch("/footer")
            .then(response => {
                if (!response.ok) throw new Error("Footer nicht gefunden");
                return response.text();
            })
            .then(data => {
                footerTarget.innerHTML = data;
            })
            .catch(error => {
                footerTarget.innerHTML = `
                    <div style="background: #ffdede; color: #a00; padding: 10px; text-align: center;">
                        Fehler beim Laden der Fußzeile.
                    </div>`;
                console.error(error);
            });
    }
});
