// Scroll Listener
if (document.body.classList.contains("hero")) {
    window.addEventListener("scroll", function () {
        if (window.scrollY > 10)
            document.body.classList.add("scroll");
        else
            document.body.classList.remove("scroll");
    });
}
// function testFoodRelatedInputs() {
//     const freitagElement = document.getElementById('abendFreitag');
//     const freitagChecked = (<HTMLInputElement><any>freitagElement).checked
//     const samstagElement = document.getElementById('abendSamstag');
//     const samstagChecked = (<HTMLInputElement><any>samstagElement).checked
//     const ernaehrungElement = document.getElementById('ernaehrung');
//     const allergien = document.getElementById('allergien');
//     (<HTMLInputElement><any>ernaehrungElement).disabled = !freitagChecked && !samstagChecked;
//     (<HTMLInputElement><any>allergien).disabled = !freitagChecked && !samstagChecked;
// }
window.onload = function () {
    // Sidebar toggle
    var sidebarToggleElement = document.querySelector('[data-action="toggle-sidebar"]');
    if (sidebarToggleElement) {
        sidebarToggleElement.addEventListener("click", function () {
            document.body.classList.toggle("sidebar");
        });
    }
    // DDMember Form Elements
    var ddMemberCheckbox = document.querySelector('#ddmember');
    if (ddMemberCheckbox) {
        ddMemberCheckbox.addEventListener("click", function () {
            var isMember = ddMemberCheckbox.checked;
            var elements = document.querySelectorAll(".ddmember");
            elements.forEach(function (item) {
                if (isMember) {
                    item.classList.remove("hidden");
                }
                else {
                    item.classList.add("hidden");
                }
            });
        });
    }
    // const freitagAbendElement = document.getElementById('abendFreitag');
    // if(freitagAbendElement) {
    //     freitagAbendElement.addEventListener('change', (event) => {testFoodRelatedInputs();});
    // }
    // const samstagAbendElement = document.getElementById('abendSamstag');
    // if(samstagAbendElement) {
    //     samstagAbendElement.addEventListener('change', (event) => {testFoodRelatedInputs();});
    // }
    // Form silent submit
    var formElement = document.querySelector('form');
    if (formElement) {
        formElement.addEventListener('submit', function (e) {
            var targetUrl = e.target.action;
            // Load form data
            var formParameter = GetFormParameter(e.target);
            // Build url
            var queryString = Object.keys(formParameter).map(function (k) { return encodeURIComponent(k) + "=" + encodeURIComponent(formParameter[k]); }).join("&");
            var getUrl = targetUrl + "?" + queryString;
            // Perform get request
            var xmlHttp = new XMLHttpRequest();
            xmlHttp.open("GET", getUrl);
            xmlHttp.send();
            // Cleanup
            e.target.reset();
            e.target.classList.add("success");
            var submitButton = e.target.querySelectorAll("input, select, textarea");
            for (var i = 0; i < submitButton.length; i++) {
                submitButton[i].setAttribute("disabled", "disabled");
            }
            alert("Erfolgreich abgeschickt!");
            e.preventDefault();
        });
    }
};
function GetFormParameter(form) {
    var params = new Array();
    var length = form.elements.length;
    for (var i = 0; i < length; i++) {
        var element = form.elements[i];
        if (element.tagName == 'TEXTAREA' || element.tagName == 'SELECT') {
            params[element.name] = element.value;
        }
        else if (element.tagName == 'INPUT') {
            if (element.type == 'text' || element.type == 'email' || element.type == 'hidden' || element.type == 'password') {
                params[element.name] = element.value;
            }
            else if (element.type == 'radio' && element.checked) {
                if (!element.value)
                    params[element.name] = "on";
                else
                    params[element.name] = element.value;
            }
            else if (element.type == 'checkbox' && element.checked) {
                if (!element.value)
                    params[element.name] = "on";
                else
                    params[element.name] = element.value;
            }
        }
    }
    return params;
}
