// /public/assets/js/fakecheck.js
// Loader für alle Fakecheck-Module

(function () {
    const cfg = window.usbConfig || {};
    const assetsBase = cfg.assetsBase || "/assets";

    // Version aus PHP-Config (ASSET_VERSION) → app_config.php
    const assetVersion = cfg.assetVersion;
    const versionQuery = assetVersion
        ? ("?v=" + encodeURIComponent(assetVersion))
        : "";

    // Basis-Pfad für die Teil-Skripte
    const base = assetsBase.replace(/\/+$/, "") + "/js/fakecheck/";

    const scripts = [
        base + "fakecheck.core.js" + versionQuery,
        base + "fakecheck.browser.js" + versionQuery,
        base + "fakecheck.serial.js" + versionQuery
    ];

    function loadScript(src) {
        return new Promise((resolve, reject) => {
            const s = document.createElement("script");
            s.src = src;
            s.async = false; // Reihenfolge sicherstellen
            s.onload = resolve;
            s.onerror = () => reject(new Error("Konnte " + src + " nicht laden"));
            document.head.appendChild(s);
        });
    }

    scripts
        .reduce((p, src) => p.then(() => loadScript(src)), Promise.resolve())
        .catch(err => console.error("Fakecheck Loader Fehler:", err));
})();
