"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExternalScripts = void 0;
const react_1 = require("react");
const jsx_runtime_1 = require("react/jsx-runtime");
const react_2 = require("@remix-run/react");
function ExternalScripts() {
    let location = (0, react_2.useLocation)();
    let scripts = (0, react_2.useMatches)().flatMap((match, index, matches) => {
        var _a;
        let scripts = (_a = match.handle) === null || _a === void 0 ? void 0 : _a.scripts;
        if (typeof scripts !== "function")
            return [];
        let result = scripts({
            id: match.id,
            data: match.data,
            params: match.params,
            location,
            parentsData: matches.slice(0, index).map((match) => match.data),
        });
        if (Array.isArray(result))
            return result;
        return [];
    });
    return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [scripts.map((props) => {
                let rel = props.noModule ? "modulepreload" : "preload";
                let as = !props.noModule ? "script" : undefined;
                return ((0, jsx_runtime_1.jsx)("link", { rel: rel, href: props.src, as: as, crossOrigin: props.crossOrigin, integrity: props.integrity, referrerPolicy: props.referrerPolicy }, props.src));
            }), scripts.map((props) => {
                return (0, react_1.createElement)("script", { ...props, key: props.src });
            })] }));
}
exports.ExternalScripts = ExternalScripts;
