﻿function SWTemplate() { }

SWTemplate.loadTemplate = function () {
    SWTemplate.getCompanyName();
    SWPortalData.saveToLocalStorage();
}

SWTemplate.getCompanyName = function () {
    if (SWPortalData.data.company == undefined) {
        setTimeout(SWTemplate.getCompanyName, 500)
    } else {
        let comp_name = document.getElementById("company_naam");
        if (comp_name != undefined) {
            comp_name.innerHTML = SWPortalData.data.company.rows[0].bedrijfsnaam;
        }

        for (element of document.getElementsByClassName("company_naam")) {
            element.innerHTML = SWPortalData.data.company.rows[0].bedrijfsnaam
        }

        let comp_adres = document.getElementById("company_address");
        if (comp_adres != undefined) {
            comp_adres.innerHTML = SWPortalData.data.company.rows[0].adres;
        }
        let comp_city = document.getElementById("company_city");
        if (comp_city != undefined) {
            comp_city.innerHTML = SWPortalData.data.company.rows[0].plaats;
        }
    }
}

SWTemplate.showAlert = function (alert_id, text) {
    if (document.getElementById(alert_id)) {
        //alert bestaat al
        document.getElementById(alert_id).innerText = text;
        return;
    }
    
    let elem_alert = document.createElement('div');
    elem_alert.classList.add("alert", "alert-info");
    elem_alert.id = alert_id;
    elem_alert.innerHTML = text;
    document.getElementById("alert_content").appendChild(elem_alert);
}

SWTemplate.showSpinner = function (show = true) {
    if (show) {
        document.getElementById('form_spinner').style.display = 'block';
    } else {
        document.getElementById('form_spinner').style.display = 'none';
    }
}