var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
import { EventEmitter } from "events";
import { addClass, removeClass, getAsValue } from "@matdata/yasgui-utils";
import TabSettingsModal from "./TabSettingsModal";
import { default as Yasqe } from "@matdata/yasqe";
import { default as Yasr } from "@matdata/yasr";
import { mapValues, eq, mergeWith, words, deburr, invert } from "lodash-es";
import * as shareLink from "./linkUtils";
import EndpointSelect from "./endpointSelect";
import "./tab.scss";
import { getRandomId, default as Yasgui } from "./";
export class Tab extends EventEmitter {
    constructor(yasgui, conf) {
        super();
        this.handleKeyDown = (event) => {
            var _a, _b, _c, _d, _e, _f, _g, _h, _j;
            if (event.key === "F11") {
                event.preventDefault();
                if (this.yasqe) {
                    this.yasqe.toggleFullscreen();
                    if ((_a = this.yasr) === null || _a === void 0 ? void 0 : _a.getIsFullscreen()) {
                        this.yasr.toggleFullscreen();
                    }
                }
            }
            else if (event.key === "F10") {
                event.preventDefault();
                if (this.yasr) {
                    this.yasr.toggleFullscreen();
                    if ((_b = this.yasqe) === null || _b === void 0 ? void 0 : _b.getIsFullscreen()) {
                        this.yasqe.toggleFullscreen();
                    }
                }
            }
            else if (event.ctrlKey && event.shiftKey && event.key === "F") {
                event.preventDefault();
                const yasqeFullscreen = (_c = this.yasqe) === null || _c === void 0 ? void 0 : _c.getIsFullscreen();
                const yasrFullscreen = (_d = this.yasr) === null || _d === void 0 ? void 0 : _d.getIsFullscreen();
                if (yasqeFullscreen) {
                    (_e = this.yasqe) === null || _e === void 0 ? void 0 : _e.toggleFullscreen();
                    (_f = this.yasr) === null || _f === void 0 ? void 0 : _f.toggleFullscreen();
                }
                else if (yasrFullscreen) {
                    (_g = this.yasr) === null || _g === void 0 ? void 0 : _g.toggleFullscreen();
                    (_h = this.yasqe) === null || _h === void 0 ? void 0 : _h.toggleFullscreen();
                }
                else {
                    (_j = this.yasqe) === null || _j === void 0 ? void 0 : _j.toggleFullscreen();
                }
            }
        };
        this.handleYasqeBlur = (yasqe) => {
            var _a;
            this.persistentJson.yasqe.value = yasqe.getValue();
            (_a = this.settingsModal) === null || _a === void 0 ? void 0 : _a.capturePrefixesFromQuery();
            this.emit("change", this, this.persistentJson);
        };
        this.handleYasqeQuery = (yasqe) => {
            if (yasqe.getValue() !== this.persistentJson.yasqe.value) {
                this.persistentJson.yasqe.value = yasqe.getValue();
                this.emit("change", this, this.persistentJson);
            }
            this.emit("query", this);
        };
        this.handleYasqeQueryAbort = () => {
            this.emit("queryAbort", this);
            if (this.yasr) {
                this.yasr.hideLoading();
            }
        };
        this.handleYasqeQueryBefore = () => {
            this.emit("queryBefore", this);
            if (this.yasr) {
                this.yasr.showLoading();
            }
        };
        this.handleYasqeResize = (_yasqe, newSize) => {
            this.persistentJson.yasqe.editorHeight = newSize;
            this.emit("change", this, this.persistentJson);
        };
        this.handleAutocompletionShown = (_yasqe, widget) => {
            this.emit("autocompletionShown", this, widget);
        };
        this.handleAutocompletionClose = (_yasqe) => {
            this.emit("autocompletionClose", this);
        };
        this.handleQueryResponse = (_yasqe, response, duration) => {
            this.emit("queryResponse", this);
            if (!this.yasr)
                throw new Error("Resultset visualizer not initialized. Cannot draw results");
            this.yasr.setResponse(response, duration);
            if (!this.yasr.results)
                return;
            if (!this.yasr.results.hasError()) {
                this.persistentJson.yasr.response = this.yasr.results.getAsStoreObject(this.yasgui.config.yasr.maxPersistentResponseSize);
            }
            else {
                this.persistentJson.yasr.response = undefined;
            }
            this.emit("change", this, this.persistentJson);
        };
        this.handleYasqeMouseDown = (event) => {
            if (!event.ctrlKey || !this.yasqe)
                return;
            const target = event.target;
            if (!target.closest(".CodeMirror"))
                return;
            const pos = this.yasqe.coordsChar({ left: event.clientX, top: event.clientY });
            const token = this.yasqe.getTokenAt(pos);
            const tokenString = token.string.trim();
            if (tokenString.startsWith("?") || tokenString.startsWith("$"))
                return;
            const isFullUri = tokenString.startsWith("<") && tokenString.endsWith(">");
            const isPrefixedName = /^[\w-]+:[\w-]+/.test(tokenString);
            if (!isFullUri && !isPrefixedName)
                return;
            event.preventDefault();
            event.stopPropagation();
            let uri = tokenString;
            if (isFullUri) {
                uri = tokenString.slice(1, -1);
            }
            else if (isPrefixedName) {
                const prefixes = this.yasqe.getPrefixesFromQuery();
                const [prefix, localName] = tokenString.split(":");
                const prefixUri = prefixes[prefix];
                if (prefixUri) {
                    uri = prefixUri + localName;
                }
            }
            const constructQuery = `CONSTRUCT {   
  ?s_left ?p_left ?target .
  ?target ?p_right ?o_right .
}
WHERE {
  BIND(<${uri}> as ?target)
  {
    ?s_left ?p_left ?target .
  }
  UNION
  {
    ?target ?p_right ?o_right .
  }  
} LIMIT 1000`;
            this.executeBackgroundQuery(constructQuery);
        };
        if (!conf || conf.id === undefined)
            throw new Error("Expected a valid configuration to initialize tab with");
        this.yasgui = yasgui;
        this.persistentJson = conf;
    }
    name() {
        return this.persistentJson.name;
    }
    getPersistedJson() {
        return this.persistentJson;
    }
    getId() {
        return this.persistentJson.id;
    }
    draw() {
        if (this.rootEl)
            return;
        this.rootEl = document.createElement("div");
        this.rootEl.className = "tabPanel";
        this.rootEl.id = this.persistentJson.id;
        this.rootEl.setAttribute("role", "tabpanel");
        this.rootEl.setAttribute("aria-labelledby", "tab-" + this.persistentJson.id);
        const editorWrapper = document.createElement("div");
        editorWrapper.className = "editorwrapper";
        const controlbarAndYasqeDiv = document.createElement("div");
        this.controlBarEl = document.createElement("div");
        this.controlBarEl.className = "controlbar";
        controlbarAndYasqeDiv.appendChild(this.controlBarEl);
        this.yasqeWrapperEl = document.createElement("div");
        controlbarAndYasqeDiv.appendChild(this.yasqeWrapperEl);
        editorWrapper.appendChild(controlbarAndYasqeDiv);
        this.yasrWrapperEl = document.createElement("div");
        this.initTabSettingsMenu();
        this.rootEl.appendChild(editorWrapper);
        this.rootEl.appendChild(this.yasrWrapperEl);
        this.initControlbar();
        this.initYasqe();
        this.initYasr();
        this.yasgui._setPanel(this.persistentJson.id, this.rootEl);
    }
    hide() {
        removeClass(this.rootEl, "active");
        this.detachKeyboardListeners();
    }
    show() {
        this.draw();
        addClass(this.rootEl, "active");
        this.yasgui.tabElements.selectTab(this.persistentJson.id);
        if (this.yasqe) {
            this.yasqe.refresh();
            if (this.yasgui.config.autofocus)
                this.yasqe.focus();
        }
        if (this.yasr) {
            this.yasr.refresh();
        }
        this.setEndpoint(this.getEndpoint(), this.yasgui.persistentConfig.getEndpointHistory());
        this.attachKeyboardListeners();
    }
    attachKeyboardListeners() {
        if (!this.rootEl)
            return;
        document.addEventListener("keydown", this.handleKeyDown);
    }
    detachKeyboardListeners() {
        document.removeEventListener("keydown", this.handleKeyDown);
    }
    select() {
        this.yasgui.selectTabId(this.persistentJson.id);
    }
    close() {
        this.detachKeyboardListeners();
        if (this.yasqe)
            this.yasqe.abortQuery();
        if (this.yasgui.getTab() === this) {
            const tabs = this.yasgui.persistentConfig.getTabs();
            const i = tabs.indexOf(this.persistentJson.id);
            if (i > -1) {
                this.yasgui.selectTabId(tabs[i === tabs.length - 1 ? i - 1 : i + 1]);
            }
        }
        this.yasgui._removePanel(this.rootEl);
        this.yasgui.persistentConfig.deleteTab(this.persistentJson.id);
        this.yasgui.emit("tabClose", this.yasgui, this);
        this.emit("close", this);
        this.yasgui.tabElements.get(this.persistentJson.id).delete();
        delete this.yasgui._tabs[this.persistentJson.id];
    }
    getQuery() {
        var _a;
        if (!this.yasqe) {
            throw new Error("Cannot get value from uninitialized editor");
        }
        return (_a = this.yasqe) === null || _a === void 0 ? void 0 : _a.getValue();
    }
    setQuery(query) {
        if (!this.yasqe) {
            throw new Error("Cannot set value for uninitialized editor");
        }
        this.yasqe.setValue(query);
        this.persistentJson.yasqe.value = query;
        this.emit("change", this, this.persistentJson);
        return this;
    }
    getRequestConfig() {
        return this.persistentJson.requestConfig;
    }
    initControlbar() {
        this.initEndpointSelectField();
        if (this.yasgui.config.endpointInfo && this.controlBarEl) {
            this.controlBarEl.appendChild(this.yasgui.config.endpointInfo());
        }
    }
    getYasqe() {
        return this.yasqe;
    }
    getYasr() {
        return this.yasr;
    }
    initTabSettingsMenu() {
        if (!this.controlBarEl)
            throw new Error("Need to initialize wrapper elements before drawing tab settings");
        this.settingsModal = new TabSettingsModal(this, this.controlBarEl);
    }
    initEndpointSelectField() {
        if (!this.controlBarEl)
            throw new Error("Need to initialize wrapper elements before drawing endpoint field");
        this.endpointSelect = new EndpointSelect(this.getEndpoint(), this.controlBarEl, this.yasgui.config.endpointCatalogueOptions, this.yasgui.persistentConfig.getEndpointHistory());
        this.endpointSelect.on("select", (endpoint, endpointHistory) => {
            this.setEndpoint(endpoint, endpointHistory);
        });
        this.endpointSelect.on("remove", (endpoint, endpointHistory) => {
            this.setEndpoint(endpoint, endpointHistory);
        });
    }
    checkEndpointForCors(endpoint) {
        if (this.yasgui.config.corsProxy && !(endpoint in Yasgui.corsEnabled)) {
            const askUrl = new URL(endpoint);
            askUrl.searchParams.append("query", "ASK {?x ?y ?z}");
            fetch(askUrl.toString())
                .then(() => {
                Yasgui.corsEnabled[endpoint] = true;
            })
                .catch((e) => {
                Yasgui.corsEnabled[endpoint] = e instanceof TypeError ? false : true;
            });
        }
    }
    setEndpoint(endpoint, endpointHistory) {
        if (endpoint)
            endpoint = endpoint.trim();
        if (endpointHistory && !eq(endpointHistory, this.yasgui.persistentConfig.getEndpointHistory())) {
            this.yasgui.emit("endpointHistoryChange", this.yasgui, endpointHistory);
        }
        this.checkEndpointForCors(endpoint);
        if (this.persistentJson.requestConfig.endpoint !== endpoint) {
            this.persistentJson.requestConfig.endpoint = endpoint;
            this.emit("change", this, this.persistentJson);
            this.emit("endpointChange", this, endpoint);
        }
        if (this.endpointSelect instanceof EndpointSelect) {
            this.endpointSelect.setEndpoint(endpoint, endpointHistory);
        }
        return this;
    }
    getEndpoint() {
        return getAsValue(this.persistentJson.requestConfig.endpoint, this.yasgui);
    }
    updateContextMenu() {
        this.getTabListEl().redrawContextMenu();
    }
    getShareableLink(baseURL) {
        return shareLink.createShareLink(baseURL || window.location.href, this);
    }
    getShareObject() {
        return shareLink.createShareConfig(this);
    }
    getTabListEl() {
        return this.yasgui.tabElements.get(this.persistentJson.id);
    }
    setName(newName) {
        this.getTabListEl().rename(newName);
        this.persistentJson.name = newName;
        this.emit("change", this, this.persistentJson);
        return this;
    }
    hasResults() {
        var _a;
        return !!((_a = this.yasr) === null || _a === void 0 ? void 0 : _a.results);
    }
    getName() {
        return this.persistentJson.name;
    }
    query() {
        if (!this.yasqe)
            return Promise.reject(new Error("No yasqe editor initialized"));
        return this.yasqe.query();
    }
    setRequestConfig(requestConfig) {
        this.persistentJson.requestConfig = Object.assign(Object.assign({}, this.persistentJson.requestConfig), requestConfig);
        this.emit("change", this, this.persistentJson);
    }
    getStaticRequestConfig() {
        const config = {};
        let key;
        for (key in this.yasgui.config.requestConfig) {
            if (key === "adjustQueryBeforeRequest")
                continue;
            const val = this.yasgui.config.requestConfig[key];
            if (typeof val === "function") {
                config[key] = val(this.yasgui);
            }
        }
        return config;
    }
    initYasqe() {
        const yasqeConf = Object.assign(Object.assign({}, this.yasgui.config.yasqe), { value: this.persistentJson.yasqe.value, editorHeight: this.persistentJson.yasqe.editorHeight ? this.persistentJson.yasqe.editorHeight : undefined, persistenceId: null, consumeShareLink: null, createShareableLink: () => this.getShareableLink(), requestConfig: () => {
                const processedReqConfig = Object.assign(Object.assign({ acceptHeaderGraph: "text/turtle", acceptHeaderSelect: "application/sparql-results+json" }, mergeWith({}, this.persistentJson.requestConfig, this.getStaticRequestConfig(), function customizer(objValue, srcValue) {
                    if (Array.isArray(objValue) || Array.isArray(srcValue)) {
                        return [...(objValue || []), ...(srcValue || [])];
                    }
                })), { adjustQueryBeforeRequest: this.yasgui.config.requestConfig.adjustQueryBeforeRequest });
                if (this.yasgui.config.corsProxy && !Yasgui.corsEnabled[this.getEndpoint()]) {
                    return Object.assign(Object.assign({}, processedReqConfig), { args: [
                            ...(Array.isArray(processedReqConfig.args) ? processedReqConfig.args : []),
                            { name: "endpoint", value: this.getEndpoint() },
                            { name: "method", value: this.persistentJson.requestConfig.method },
                        ], method: "POST", endpoint: this.yasgui.config.corsProxy });
                }
                return processedReqConfig;
            } });
        if (!yasqeConf.hintConfig) {
            yasqeConf.hintConfig = {};
        }
        if (!yasqeConf.hintConfig.container) {
            yasqeConf.hintConfig.container = this.yasgui.rootEl;
        }
        if (!this.yasqeWrapperEl) {
            throw new Error("Expected a wrapper element before instantiating yasqe");
        }
        this.yasqe = new Yasqe(this.yasqeWrapperEl, yasqeConf);
        this.yasqe.on("blur", this.handleYasqeBlur);
        this.yasqe.on("query", this.handleYasqeQuery);
        this.yasqe.on("queryBefore", this.handleYasqeQueryBefore);
        this.yasqe.on("queryAbort", this.handleYasqeQueryAbort);
        this.yasqe.on("resize", this.handleYasqeResize);
        this.yasqe.on("autocompletionShown", this.handleAutocompletionShown);
        this.yasqe.on("autocompletionClose", this.handleAutocompletionClose);
        this.yasqe.on("queryResponse", this.handleQueryResponse);
        this.attachYasqeMouseHandler();
    }
    destroyYasqe() {
        var _a, _b, _c, _d, _e, _f, _g, _h, _j;
        (_a = this.yasqe) === null || _a === void 0 ? void 0 : _a.off("blur", this.handleYasqeBlur);
        (_b = this.yasqe) === null || _b === void 0 ? void 0 : _b.off("query", this.handleYasqeQuery);
        (_c = this.yasqe) === null || _c === void 0 ? void 0 : _c.off("queryAbort", this.handleYasqeQueryAbort);
        (_d = this.yasqe) === null || _d === void 0 ? void 0 : _d.off("resize", this.handleYasqeResize);
        (_e = this.yasqe) === null || _e === void 0 ? void 0 : _e.off("autocompletionShown", this.handleAutocompletionShown);
        (_f = this.yasqe) === null || _f === void 0 ? void 0 : _f.off("autocompletionClose", this.handleAutocompletionClose);
        (_g = this.yasqe) === null || _g === void 0 ? void 0 : _g.off("queryBefore", this.handleYasqeQueryBefore);
        (_h = this.yasqe) === null || _h === void 0 ? void 0 : _h.off("queryResponse", this.handleQueryResponse);
        this.detachYasqeMouseHandler();
        (_j = this.yasqe) === null || _j === void 0 ? void 0 : _j.destroy();
        this.yasqe = undefined;
    }
    executeBackgroundQuery(query) {
        return __awaiter(this, void 0, void 0, function* () {
            if (!this.yasqe || !this.yasr)
                return;
            try {
                this.yasr.showLoading();
                this.emit("queryBefore", this);
                const requestConfig = this.yasqe.config.requestConfig;
                const config = typeof requestConfig === "function" ? requestConfig(this.yasqe) : requestConfig;
                if (!config.endpoint) {
                    throw new Error("No endpoint configured");
                }
                const endpoint = typeof config.endpoint === "function" ? config.endpoint(this.yasqe) : config.endpoint;
                const method = typeof config.method === "function" ? config.method(this.yasqe) : config.method || "POST";
                const headers = typeof config.headers === "function" ? config.headers(this.yasqe) : config.headers || {};
                const searchParams = new URLSearchParams();
                searchParams.append("query", query);
                if (config.args && Array.isArray(config.args)) {
                    config.args.forEach((arg) => {
                        if (arg.name && arg.value) {
                            searchParams.append(arg.name, arg.value);
                        }
                    });
                }
                const fetchOptions = {
                    method: method,
                    headers: Object.assign({ Accept: "text/turtle" }, headers),
                };
                let url = endpoint;
                if (method === "POST") {
                    fetchOptions.headers = Object.assign(Object.assign({}, fetchOptions.headers), { "Content-Type": "application/x-www-form-urlencoded" });
                    fetchOptions.body = searchParams.toString();
                }
                else {
                    const urlObj = new URL(endpoint);
                    searchParams.forEach((value, key) => {
                        urlObj.searchParams.append(key, value);
                    });
                    url = urlObj.toString();
                }
                const startTime = Date.now();
                const response = yield fetch(url, fetchOptions);
                const duration = Date.now() - startTime;
                if (!response.ok) {
                    throw new Error(`Query failed: ${response.statusText}`);
                }
                const result = yield response.text();
                const queryResponse = {
                    ok: response.ok,
                    status: response.status,
                    statusText: response.statusText,
                    headers: response.headers,
                    type: response.type,
                    content: result,
                };
                this.yasr.setResponse(queryResponse, duration);
                if (this.yasr.plugins["Graph"]) {
                    this.yasr.selectPlugin("Graph");
                }
                this.yasr.hideLoading();
                this.emit("queryResponse", this);
            }
            catch (error) {
                console.error("Background query failed:", error);
                if (this.yasr) {
                    this.yasr.hideLoading();
                    this.yasr.setResponse({
                        error: error instanceof Error ? error.message : "Unknown error",
                    }, 0);
                }
            }
        });
    }
    attachYasqeMouseHandler() {
        if (!this.yasqe)
            return;
        const wrapper = this.yasqe.getWrapperElement();
        if (wrapper) {
            wrapper.addEventListener("mousedown", this.handleYasqeMouseDown);
        }
    }
    detachYasqeMouseHandler() {
        if (!this.yasqe)
            return;
        const wrapper = this.yasqe.getWrapperElement();
        if (wrapper) {
            wrapper.removeEventListener("mousedown", this.handleYasqeMouseDown);
        }
    }
    initYasr() {
        if (!this.yasrWrapperEl)
            throw new Error("Wrapper for yasr does not exist");
        const yasrConf = {
            persistenceId: null,
            prefixes: (yasr) => {
                var _a;
                const prefixesFromYasrConf = typeof this.yasgui.config.yasr.prefixes === "function"
                    ? this.yasgui.config.yasr.prefixes(yasr)
                    : this.yasgui.config.yasr.prefixes;
                const prefixesFromYasqe = (_a = this.yasqe) === null || _a === void 0 ? void 0 : _a.getPrefixesFromQuery();
                return invert(invert(Object.assign(Object.assign({}, prefixesFromYasrConf), prefixesFromYasqe)));
            },
            defaultPlugin: this.persistentJson.yasr.settings.selectedPlugin,
            getPlainQueryLinkToEndpoint: () => {
                if (this.yasqe) {
                    return shareLink.appendArgsToUrl(this.getEndpoint(), Yasqe.Sparql.getUrlArguments(this.yasqe, this.persistentJson.requestConfig));
                }
            },
            plugins: mapValues(this.persistentJson.yasr.settings.pluginsConfig, (conf) => ({
                dynamicConfig: conf,
            })),
            errorRenderers: [
                getCorsErrorRenderer(this),
                ...(Yasr.defaults.errorRenderers || []),
            ],
        };
        if (yasrConf.getDownloadFileName === undefined) {
            yasrConf.getDownloadFileName = () => words(deburr(this.getName())).join("-");
        }
        this.yasr = new Yasr(this.yasrWrapperEl, yasrConf, this.persistentJson.yasr.response);
        this.persistentJson.yasr.settings = this.yasr.getPersistentConfig();
        this.yasr.on("change", () => {
            if (this.yasr) {
                this.persistentJson.yasr.settings = this.yasr.getPersistentConfig();
            }
            this.emit("change", this, this.persistentJson);
        });
    }
    destroy() {
        var _a, _b, _c;
        this.removeAllListeners();
        (_a = this.settingsModal) === null || _a === void 0 ? void 0 : _a.destroy();
        (_b = this.endpointSelect) === null || _b === void 0 ? void 0 : _b.destroy();
        this.endpointSelect = undefined;
        (_c = this.yasr) === null || _c === void 0 ? void 0 : _c.destroy();
        this.yasr = undefined;
        this.destroyYasqe();
    }
    static getDefaults(yasgui) {
        return {
            yasqe: {
                value: yasgui ? yasgui.config.yasqe.value : Yasgui.defaults.yasqe.value,
            },
            yasr: {
                response: undefined,
                settings: {
                    selectedPlugin: yasgui ? yasgui.config.yasr.defaultPlugin : "table",
                    pluginsConfig: {},
                },
            },
            requestConfig: yasgui ? yasgui.config.requestConfig : Object.assign({}, Yasgui.defaults.requestConfig),
            id: getRandomId(),
            name: yasgui ? yasgui.createTabName() : Yasgui.defaults.tabName,
        };
    }
}
export default Tab;
const safeEndpoint = (endpoint) => {
    const url = new URL(endpoint);
    return encodeURI(url.href);
};
function getCorsErrorRenderer(tab) {
    return (error) => __awaiter(this, void 0, void 0, function* () {
        if (!error.status) {
            const shouldReferToHttp = new URL(tab.getEndpoint()).protocol === "http:" && window.location.protocol === "https:";
            if (shouldReferToHttp) {
                const errorEl = document.createElement("div");
                const errorSpan = document.createElement("p");
                errorSpan.innerHTML = `You are trying to query an HTTP endpoint (<a href="${safeEndpoint(tab.getEndpoint())}" target="_blank" rel="noopener noreferrer">${safeEndpoint(tab.getEndpoint())}</a>) from an HTTP<strong>S</strong> website (<a href="${safeEndpoint(window.location.href)}">${safeEndpoint(window.location.href)}</a>).<br>This is not allowed in modern browsers, see <a target="_blank" rel="noopener noreferrer" href="https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy">https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy</a>.`;
                if (tab.yasgui.config.nonSslDomain) {
                    const errorLink = document.createElement("p");
                    errorLink.innerHTML = `As a workaround, you can use the HTTP version of Yasgui instead: <a href="${tab.getShareableLink(tab.yasgui.config.nonSslDomain)}" target="_blank">${tab.yasgui.config.nonSslDomain}</a>`;
                    errorSpan.appendChild(errorLink);
                }
                errorEl.appendChild(errorSpan);
                return errorEl;
            }
        }
    });
}
//# sourceMappingURL=Tab.js.map