import "react";

import "react-i18next";

import { A as e, U as t, q as s, n as i, r as a, s as n, t as o, v as r, w as p, x as l, y as c, H as d, z as h, S as u, B as f, C as g, D as m, E as b, F as A, G as v, I as y, J as w, K as M, N as S, Q as T, V as F, W as I } from "./chunk1.mjs";

export { X as SUBSCRIBE_ALL } from "./chunk1.mjs";

import "i18next";

import { b as L } from "./i18n/nova_i18n.mjs";

import "react-dom/client";

import "tslib";

import "rxjs";

import "rxjs/operators";

import "zod";

import "polished";

import "reselect";

import "framer-motion";

import "react/jsx-runtime";

import "react-dom";

import "classnames";

import "react-focus-lock";

import "react-popper";

import "@popperjs/core";

import "axios";

import "@tanstack/react-virtual";

import "cldr-core/supplemental/weekData.json";

import "use-memo-one";

import "memoize-one";

import "@tanstack/react-query";

import "react-cropper";

import "redux-observable";

import "redux";

import "@redux-devtools/extension";

import "react-redux";

const C = "broadcastMessage";

const E = "_sendMessageToApp";

const U = "gotoApp";

const N = "logoff";

const D = "doNovaLogoff";

const H = "removeSplash";

const k = "sendMessageToApp";

const x = "setDirtyMessageEnabled";

const O = "setLogoffUrl";

const j = "timeout";

const P = "updateAppName";

const z = "updateDirtyFlag";

const q = "updateCleanupFn";

const B = window.location.origin;

const R = e => e.children !== void 0;

var $ = class {
    constructor(o) {
        this.observable = new e;
        this.model = {
            availableApplications: [],
            publicTypeSupportingApplications: new Map
        };
        this.messageQueue = [];
        this.readyForMessages = false;
        this.appId = "";
        this.dirtyAppNames = "\n";
        window.addEventListener("message", this.onMessage.bind(this));
        this.observable.subscribe(t, (() => this.updateModel()));
        this.observable.subscribe(s, ((e, t) => {
            this.dirtyAppNames = t.dirtyAppNames;
        }));
        this.config = o;
        this.updateModel();
        i.subscribe(a, ((e, t) => {
            if (t?.data.handled) return;
            if (t) t.data.handled = true;
            if (this.dirtyAppNames !== "\n") i.publish(n, {
                data: {
                    dirtyAppNames: this.dirtyAppNames,
                    onDiscardAndExit: () => this.doNovaLogoff()
                }
            }); else this.logoff();
        }));
        if (!window.onpopstate) window.onpopstate = this.onPopState.bind(this);
    }
    onPopState() {
        if (!this.appId) return;
        this.gotoApp(this.appId, window.location.href, true);
    }
    onMessage(e) {
        if (window.location.origin !== e.origin) return;
        let t;
        if (typeof e.data === "string") try {
            t = JSON.parse(e.data);
        } catch (e) {
            return;
        } else t = e.data;
        if (t === null || t.version === void 0) return;
        switch (t.command) {
          case E:
            this.processMessage(t);
            break;
        }
    }
    processMessage(e) {
        if (this.readyForMessages) this.observable.fire(e.type, e.data); else this.messageQueue.push(e);
    }
    async updateModel() {
        this.model.availableApplications = await this.config.applicationService.getAvailableApps();
        this.model.publicTypeSupportingApplications = await this.config.applicationService.getPublicTypeSupportingApps();
        this.observable.fire(o);
    }
    gotoApp(e, t, s, i = {}) {
        const a = {
            version: "5.0",
            command: U,
            appId: e,
            url: t,
            isCompliant: s,
            options: i
        };
        this.sendCommandToMain(a);
    }
    updateAppName(e, t) {
        const s = {
            version: "5.0",
            command: P,
            appId: e,
            appName: t
        };
        this.sendCommandToMain(s);
    }
    sendCommandToMain(e) {
        top?.window.postMessage(JSON.stringify(e), B);
    }
    sendMessageToApp(e, t, s) {
        const i = {
            version: "5.0",
            command: k,
            appId: e,
            type: t,
            data: s
        };
        this.sendCommandToMain(i);
    }
    subscribe(e, t, s) {
        this.observable.subscribe(e, t, s);
    }
    unsubscribe(e, t, s) {
        this.observable.unsubscribe(e, t, s);
    }
    broadcastMessage(e, t = {}) {
        const s = {
            version: "5.0",
            command: C,
            type: e,
            data: t
        };
        this.sendCommandToMain(s);
    }
    setLogoffUrl(e) {
        const t = {
            version: "5.0",
            command: O,
            logoffUrl: e
        };
        this.sendCommandToMain(t);
    }
    logoff() {
        const e = {
            version: "5.0",
            command: N
        };
        this.sendCommandToMain(e);
    }
    doNovaLogoff(e) {
        const t = {
            version: "5.0",
            command: D,
            alreadyInitiated: e
        };
        this.sendCommandToMain(t);
    }
    setDirtyMessageEnabled(e) {
        const t = {
            version: "5.0",
            command: x,
            allowDirtyMessage: e
        };
        this.sendCommandToMain(t);
    }
    timeout(e) {
        const t = {
            version: "5.0",
            command: j,
            url: e
        };
        this.sendCommandToMain(t);
    }
    updateDirtyFlag(e, t) {
        const s = {
            version: "5.0",
            command: z,
            appId: e,
            dirtyFlag: t
        };
        this.sendCommandToMain(s);
    }
    updateCleanupFnHandler(e) {
        this.cleanupFnHandler = async () => {
            i.publish(r);
            await e();
            this.doNovaLogoff(true);
        };
        this.observable.subscribe(p, this.cleanupFnHandler);
    }
    updateCleanupFn(e) {
        if (this.cleanupFnHandler) this.observable.unsubscribe(p, this.cleanupFnHandler);
        this.updateCleanupFnHandler(e);
        const t = {
            version: "5.0",
            command: q,
            appId: this.appId,
            hasCleanupFn: true
        };
        this.sendCommandToMain(t);
    }
    removeCleanupFn() {
        if (this.cleanupFnHandler) {
            this.observable.unsubscribe(p, this.cleanupFnHandler);
            this.cleanupFnHandler = void 0;
            const e = {
                version: "5.0",
                command: q,
                appId: this.appId,
                hasCleanupFn: false
            };
            this.sendCommandToMain(e);
        }
    }
    registerApp(e, t, s) {
        this.appId = e;
        this.gotoApp(e, t, true);
        this.updateAppName(e, s);
        this.readyForMessages = true;
        this.flushMessageQueue();
    }
    getModel() {
        return this.model;
    }
    openObject(e, t, s, i) {
        const a = this.getAppIdForType(e, i);
        if (!a) return;
        const n = this.getAvailableApp(a);
        if (!n) return;
        this.gotoApp(n.appId, n.uri, n.appSwitcherCompliance);
        this.sendMessageToApp(n.appId, s, {
            ...t,
            directive: n.directiveId,
            targetPublicType: e
        });
    }
    getAppIdForType(e, t) {
        const s = this.model.publicTypeSupportingApplications.get(e);
        if (!s) return null;
        let i = null;
        if (t) {
            if (s.filter((e => e.appId === t)).length > 0) i = t;
        }
        if (!i && s.length > 0) i = s[0].appId;
        return i;
    }
    getAvailableApp(e) {
        let t = null;
        const s = this.model.availableApplications;
        for (const i of s) if (R(i)) {
            for (const s of i.children) if (s.appId === e) t = s;
        } else if (i.appId === e) t = i;
        return t;
    }
    flushMessageQueue() {
        for (const e of this.messageQueue) this.observable.fire(e.type, e.data);
        this.messageQueue = [];
    }
};

var W = class {
    constructor(e, t = false) {
        this.app = e;
        this.loaded = t;
    }
    getHTMLElement(e) {
        let t;
        if (!e) t = document.querySelector("body");
        if (!t) t = this.createIFrame(this.app.appId);
        return t;
    }
    createIFrame(e) {
        const t = document.createElement("iframe");
        t.setAttribute("id", `${e}_iframe`);
        t.setAttribute("allowfullscreen", "true");
        t.setAttribute("title", "SAS");
        t.style.top = "0";
        t.style.left = "0";
        t.style.height = "100%";
        t.style.width = "100%";
        t.style.border = "0";
        t.style.position = "absolute";
        return t;
    }
    initHTMLElement(e, t) {
        const s = this.app.getHTMLElement();
        if (s instanceof HTMLIFrameElement) {
            const i = s;
            let a = this.addUrlParameter(e, "launchedFromAppSwitcher=true");
            if (t) a = this.addUrlParameter(a, "useTransitionSplash=true");
            i.src = a;
            i.addEventListener("load", (() => {
                this.loaded = true;
            }));
        } else this.loaded = true;
    }
    addUrlParameter(e, t) {
        let s = "?";
        if (e.includes("?")) s = "&";
        return e + s + t;
    }
    getWindow() {
        const e = this.app.getHTMLElement();
        if (e instanceof HTMLIFrameElement) return e.contentWindow;
        return window;
    }
    isLoaded() {
        return this.loaded;
    }
    queueMessage(e, t) {
        const s = this.app.getHTMLElement();
        if (!(s instanceof HTMLIFrameElement)) return;
        const i = s;
        const a = this.getWindow();
        i.addEventListener("load", (() => {
            t(e, a);
        }));
    }
    hideHTMLElement() {
        const e = this.app.getHTMLElement();
        if (e instanceof HTMLIFrameElement) this.doHideElement(e); else {
            const e = document.querySelector("body")?.childNodes;
            for (const t of e) if (!(t instanceof HTMLIFrameElement) && t instanceof HTMLElement) this.doHideElement(t);
        }
    }
    doHideElement(e) {
        e.setAttribute("active", "false");
        e.style.display = "none";
    }
    showHTMLElement() {
        const e = this.app.getHTMLElement();
        if (e instanceof HTMLIFrameElement) this.doShowElement(e); else {
            const e = document.querySelector("body")?.childNodes;
            for (const t of e) if (!(t instanceof HTMLIFrameElement) && t instanceof HTMLElement && t.id !== "sas-nc-splashscreen") this.doShowElement(t);
        }
    }
    doShowElement(e) {
        e.setAttribute("active", "true");
        e.focus();
        e.style.removeProperty("display");
    }
};

var Q = class {
    constructor(e, t, s) {
        this.appId = e;
        this.url = t;
        this.appName = "";
        this.dirty = false;
        this.initialized = false;
        this.title = "";
        this.stashedUrl = "";
        this.cleanupFn = false;
        this.appName = e;
        this.elementManager = new W(this);
        this.htmlElement = this.elementManager.getHTMLElement(s);
    }
    hide() {
        this.elementManager.hideHTMLElement();
    }
    show() {
        this.elementManager.showHTMLElement();
    }
    init(e) {
        this.elementManager.initHTMLElement(this.url, e);
        this.initialized = true;
    }
    isInitialized() {
        return this.initialized;
    }
    isLoaded() {
        return this.elementManager.isLoaded();
    }
    getHTMLElement() {
        return this.htmlElement;
    }
    getWindow() {
        return this.elementManager.getWindow();
    }
    getStashedUrl() {
        return this.stashedUrl;
    }
    setStashedUrl(e) {
        this.stashedUrl = e;
    }
    hasCleanupFn() {
        return this.cleanupFn;
    }
    setCleanupFn(e) {
        this.cleanupFn = e;
    }
    queueMessage(e, t) {
        this.elementManager.queueMessage(e, t);
    }
};

const G = (e, t) => {
    const s = e.split("#");
    const i = s[0].split("?");
    if (i.length >= 2) {
        const e = `${encodeURIComponent(t)}=`;
        const a = i[1].split(/[&;]/g);
        for (let t = a.length; t-- > 0; ) if (a[t].lastIndexOf(e, 0) !== -1) a.splice(t, 1);
        const n = i[0] + (a.length > 0 ? `?${a.join("&")}` : "");
        if (s.length >= 2) {
            s[0] = n;
            return s.join("#");
        }
        return n;
    }
    return e;
};

const J = l("ApplicationSwitcherMain");

var _ = class {
    constructor(e) {
        this.config = e;
        this.alreadyShownDirtyMessage = false;
        this.applications = new Map;
        this.logoffUrl = "";
        this.dirtyMessageEnabled = true;
        this.dirtyAppNames = "\n";
        this.cleanupFns = 0;
        this.LOGOFF_TIMEOUT = 2e3;
        J.info("Creating ApplicationSwitcherMain instance");
        window.addEventListener("message", this.onMessage.bind(this));
        this.getLogoffUrl = this.config.getLogoffUrl ? this.config.getLogoffUrl : () => this.logoffUrl;
        this.currentApp = void 0;
        window.addEventListener("beforeunload", this.showUnsavedChangesDialog.bind(this));
        if (!window.onpopstate) window.onpopstate = this.onPopState.bind(this);
        this.setupPWAInstallability();
    }
    setupPWAInstallability() {
        const e = c();
        if (e !== void 0 && "serviceWorker" in navigator) {
            navigator.serviceWorker.register(`${e}pwa/root-service-worker.js`, {
                scope: "/"
            }).then((function(e) {
                J.info(`SAS root service worker registration successful with scope: ${e.scope}`);
            }), (function(e) {
                J.error(`SAS root service worker registration failed: ${e}`);
            }));
            const t = window.document;
            const s = t.createElement("link");
            s.setAttribute("rel", "manifest");
            s.setAttribute("id", "sas-manifest");
            s.setAttribute("crossOrigin", "use-credentials");
            s.setAttribute("href", `${e}pwa/sas-manifest.json`);
            t.querySelector("head")?.prepend(s);
        }
    }
    showUnsavedChangesDialog(e) {
        if (this.getShowDirtyMessage(this.alreadyShownDirtyMessage)) {
            e.preventDefault();
            e.returnValue = this.config.getUnsavedChangesLocalizedString(this.dirtyAppNames);
        }
    }
    onPopState(e) {
        if (e && e.state && e.state.appId) {
            const t = e.state;
            this.gotoApp(t.appId, t.url, t.isCompliant, true);
        } else {
            const e = this.getCurrentApp()?.appId;
            if (e) window.history.replaceState({
                appId: e,
                url: window.location.href,
                isCompliant: true
            }, document.title, window.location.href);
        }
    }
    getShowDirtyMessage(e) {
        if (this.dirtyAppNames !== "\n" && (e === void 0 || e === false) && this.dirtyMessageEnabled) return true;
        return false;
    }
    getAppAddedData() {
        const e = [];
        this.applications.forEach(((t, s) => {
            e.push({
                appId: s,
                title: t.title,
                url: t.url,
                isDirty: t.dirty
            });
        }));
        return e;
    }
    gotoApp(e, t, i, a, n, o) {
        let r = false;
        if (this.appExists(e) && n) return;
        if (this.isCurrentApp(e)) {
            this.currentApp.setStashedUrl(window.location.href);
            this.updateHistory(e, t, true, false, o);
            return;
        }
        if (!i) {
            this.gotoUrl(t);
            return;
        }
        let p = this.getApp(e);
        if (!p) {
            r = true;
            p = this.addApplication(e, t);
        }
        const l = {
            appId: e,
            previousAppId: ""
        };
        const c = this.createAppShowMessageData(e, t);
        if (!n) {
            if (this.currentApp) {
                if (!a) this.currentApp.setStashedUrl(window.location.href);
                this.currentApp.hide();
                l.previousAppId = this.currentApp.appId;
                this.sendMessageToApp(this.currentApp.appId, d, {});
            }
            this.currentApp = p;
        }
        if (!p.isInitialized()) {
            const t = this.applications.size > 1 ? true : false;
            p.init(t);
            this.broadcastMessage(h, {
                appId: e,
                availableApps: this.getAppAddedData()
            });
            if (!n) {
                this.sendMessageToApp(e, u, c);
                this.broadcastMessage(f, l);
            }
            if (this.applications.size === 1) {
                const t = new URLSearchParams(window.location.search).get("appSwitcherMessage");
                if (t) try {
                    const s = JSON.parse(t);
                    this.sendMessageToApp(e, s.type, s.data);
                } catch {
                    J.error("Failed to send ApplicationSwitcher message via URL parameter");
                }
            } else if (this.dirtyAppNames !== "\n") this.sendMessageToApp(e, s, {
                dirtyAppNames: this.dirtyAppNames
            });
        } else {
            this.sendMessageToApp(e, g, c);
            this.sendMessageToApp(e, u, c);
            this.broadcastMessage(f, l);
        }
        if (!n) {
            p.show();
            if (p.appName && !r) this.updateBrowserTabTitle(p.appName);
            if (!a) this.updateHistory(e, t, i, this.applications.size !== 1, o);
        } else {
            p.hide();
            this.sendMessageToApp(e, d, {});
        }
    }
    isCurrentApp(e) {
        if (this.currentApp && this.appExists(e) === true && this.currentApp.appId === e) return true;
        return false;
    }
    gotoUrl(e) {
        window.location.assign(e);
    }
    appExists(e) {
        return this.applications.has(e);
    }
    addApplication(e, t) {
        let s = true;
        if (this.applications.size === 0 && !this.config.renderFirstAppInIFrame) s = false;
        const i = new Q(e, t, s);
        const a = document.querySelector("body");
        const n = i.getHTMLElement();
        if (n.tagName !== "BODY") a.appendChild(n);
        this.applications.set(e, i);
        return i;
    }
    createAppShowMessageData(e, t) {
        return {
            appId: e,
            url: t
        };
    }
    getApp(e) {
        if (this.appExists(e)) return this.applications.get(e);
    }
    updateBrowserTabTitle(e) {
        document.title = e;
    }
    onMessage(e) {
        if (window.location.origin !== e.origin) return;
        let t = null;
        if (typeof e.data === "string") try {
            t = JSON.parse(e.data);
        } catch (e) {
            return;
        } else t = e.data;
        if (t === null || t.version === void 0) return;
        switch (t.command) {
          case C:
            this.broadcastMessage(t.type, t.data);
            break;

          case U:
            this.gotoApp(t.appId, t.url, t.isCompliant, t.options?.suppressUpdateHistory, t.options?.loadInBackground, t.options?.useStashedUrl);
            break;

          case N:
            this.logoff();
            break;

          case D:
            this.alreadyShownDirtyMessage = true;
            this.doLogoff(t?.alreadyInitiated);
            break;

          case H:
            this.removeSplash();
            break;

          case k:
            this.sendMessageToApp(t.appId, t.type, t.data);
            break;

          case O:
            this.setLogoffUrl(t.logoffUrl);
            break;

          case j:
            this.timeout(t.url);
            break;

          case P:
            this.updateAppName(t.appId, t.appName);
            break;

          case z:
            this.updateDirtyFlag(t.appId, t.dirtyFlag);
            break;

          case q:
            const e = this.getApp(t.appId);
            if (t.hasCleanupFn && !e?.hasCleanupFn()) this.cleanupFns++; else if (!t.hasCleanupFn && e?.hasCleanupFn()) this.cleanupFns--;
            e?.setCleanupFn(t.hasCleanupFn);
            break;
        }
    }
    removeSplash() {
        const e = document.querySelector("#sas-hc-splash");
        if (e) e.remove();
    }
    updateAppName(e, t) {
        const s = this.getApp(e);
        if (s) {
            s.appName = t;
            if (this.currentApp === s) this.updateBrowserTabTitle(s.appName);
        }
    }
    sendMessageToApp(e, t, s = {}) {
        const i = this.getApp(e);
        if (!i) return;
        const a = {
            version: "5.0",
            command: E,
            appId: e,
            type: t,
            data: s
        };
        const n = i.getWindow();
        if (n) if (i.isLoaded()) this.executePostMessage(a, n); else i.queueMessage(a, this.executePostMessage);
    }
    executePostMessage(e, t) {
        const s = JSON.stringify(e);
        t && t.postMessage(s, B);
    }
    updateHistory(e, t, s, i, a) {
        let n = t;
        if (a && this.currentApp?.getStashedUrl()) n = this.currentApp?.getStashedUrl();
        n = G(n, "launchedFromAppSwitcher");
        n = G(n, "useTransitionSplash");
        const o = [ {
            appId: e,
            url: t,
            isCompliant: s
        }, "", n ];
        if (i) window.history.pushState(...o); else window.history.replaceState(...o);
    }
    broadcastMessage(e, t = {}) {
        this.doBroadcast(e, t);
    }
    doBroadcast(e, t) {
        for (const [s] of this.applications) this.sendMessageToApp(s, e, t);
    }
    setLogoffUrl(e) {
        this.logoffUrl = e;
    }
    getCurrentApp() {
        return this.currentApp;
    }
    logoff() {
        if (!this.getShowDirtyMessage()) this.doLogoff(); else if (confirm(this.config.getUnsavedChangesLocalizedString(this.dirtyAppNames))) {
            this.alreadyShownDirtyMessage = true;
            this.doLogoff();
        } else return;
    }
    getDirtyApps() {
        const e = [];
        this.dirtyAppNames = "\n";
        this.applications.forEach((t => {
            if (t.dirty) {
                e.push(t);
                this.dirtyAppNames += `${t.appName}\n`;
            }
        }));
        return e;
    }
    doLogoff(e) {
        const t = this.logoffUrl ? this.logoffUrl : this.getLogoffUrl();
        if (e) {
            this.cleanupFns--;
            if (this.cleanupFns > 0) return; else window.location.assign(t);
        } else {
            this.broadcastMessage(p);
            setTimeout((() => window.location.assign(t)), this.cleanupFns ? this.LOGOFF_TIMEOUT : 0);
        }
    }
    updateDirtyFlag(e, t) {
        const i = this.getApp(e);
        if (i) {
            i.dirty = t;
            this.broadcastMessage(m, {
                appId: e,
                dirtyFlag: t
            });
            this.getDirtyApps();
            this.broadcastMessage(s, {
                dirtyAppNames: this.dirtyAppNames
            });
        }
    }
    timeout(e) {
        this.dirtyMessageEnabled = false;
        window.location.assign(e);
    }
};

const V = l("AppRegistryService");

var K = class {
    constructor() {
        this.favoritesUrl = "/appRegistry/applications/favorites";
    }
    async getAvailableApps() {
        let e = [];
        try {
            const t = await this.fetchApps();
            if (t && t.items) e = this.createAppTreeModel(t.items);
        } catch (e) {}
        return e;
    }
    async fetchApps() {
        return (await this.doGet("/appRegistry/applications/applicationTree")).data;
    }
    async doGet(e) {
        return await b.get(e);
    }
    createAppTreeModel(e) {
        const t = [];
        for (const s of e) t.push(this.createNode(s));
        return t;
    }
    createNode(e) {
        if (e.branch === true) return this.createBranchNode(e);
        return this.createLeaf(e);
    }
    createBranchNode(e) {
        const t = [];
        for (const s of e.children) t.push(this.createLeaf(s));
        return {
            children: t,
            id: e.id,
            label: e.label
        };
    }
    createLeaf(e) {
        return {
            appId: e.appId,
            appName: e.appName,
            appSwitcherCompliance: e.appSwitcherCompliance,
            cdcDocId: e.cdcDocId,
            createDefaultShortcut: e.createDefaultShortcut,
            directiveId: e.id,
            hidden: e.hidden,
            label: e.label,
            shortcutLabel: e.shortcutLabel,
            specialRole: e.specialRole,
            uri: e.uri,
            favoriteUri: e.links?.find((e => e.rel === "addFavorite" || e.rel === "removeFavorite"))?.uri,
            appIcon: e.icon
        };
    }
    async getPublicTypeSupportingApps() {
        let e = new Map;
        try {
            const t = await this.fetchTypes();
            if (t && t.items) e = this.createTypesModel(t.items);
        } catch (e) {}
        return e;
    }
    async fetchTypes() {
        return (await this.doGet("/appRegistry/types")).data;
    }
    createTypesModel(e) {
        const t = new Map;
        for (const s of e) t.set(s.id, this.createTypeApps(s.apps));
        return t;
    }
    createTypeApps(e) {
        const t = [];
        for (const s of e) {
            const e = {
                appId: s.appId,
                directiveId: s.directive,
                verbLabel: s.targetVerbLabel,
                verbCode: s.targetVerbCode
            };
            t.push(e);
        }
        return t;
    }
    async updateFavorites(e) {
        try {
            await b.put(this.favoritesUrl, e, {
                headers: {
                    Accept: "application/vnd.sas.collection+json",
                    "Content-Type": "application/vnd.sas.collection+json"
                }
            });
        } catch (e) {
            V.error("Unable to update favorited applications");
        }
    }
    async addFavorite(e) {
        try {
            await b.put(e, {
                headers: {
                    Accept: "application/vnd.sas.app.registry.favorite+json"
                }
            });
        } catch (e) {
            V.error("Unable to add to favorited applications");
        }
    }
    async removeFavorite(e) {
        try {
            await b.delete(e);
        } catch (e) {
            V.error("Unable to remove from favorited applications");
        }
    }
};

var Y = class {
    constructor(e) {
        this.config = e;
        if (window === top?.window) new _(e);
        if (new URLSearchParams(window.location.search).get("launchedFromAppSwitcher") !== "false") this.client = new $(e);
    }
    broadcastMessage(e, t = {}) {
        if (!this.client) return;
        this.client.broadcastMessage(e, t);
    }
    getAvailableApps() {
        if (!this.client) return [];
        return this.client?.getModel().availableApplications;
    }
    async updateFavorites(e) {
        if (!this.client) return;
        await this.config.applicationService.updateFavorites(e);
        await this.client.updateModel();
        this.client.broadcastMessage(t);
    }
    async addFavorite(e) {
        if (!this.client) return;
        await this.config.applicationService.addFavorite(e);
        await this.client.updateModel();
        this.client.broadcastMessage(t);
    }
    async removeFavorite(e) {
        if (!this.client) return;
        await this.config.applicationService.removeFavorite(e);
        await this.client.updateModel();
        this.client.broadcastMessage(t);
    }
    getPublicTypes() {
        if (!this.client) return new Map;
        return this.client.getModel().publicTypeSupportingApplications;
    }
    gotoApp(e, t, s, i) {
        if (!this.client) return;
        this.client.gotoApp(e, t, s, i);
    }
    logoff() {
        if (!this.client) return;
        this.client.logoff();
    }
    sendMessageToApp(e, t, s) {
        if (!this.client) return;
        this.client.sendMessageToApp(e, t, s);
    }
    setDirtyMessageEnabled(e) {
        if (!this.client) return;
        this.client.setDirtyMessageEnabled(e);
    }
    setLogoffUrl(e) {
        if (!this.client) return;
        this.client.setLogoffUrl(e);
    }
    subscribe(e, t, s) {
        if (!this.client) return;
        this.client.subscribe(e, t, s);
    }
    timeout(e) {
        if (!this.client) return;
        this.client.timeout(e);
    }
    unsubscribe(e, t, s) {
        if (!this.client) return;
        this.client.unsubscribe(e, t, s);
    }
    updateAppName(e, t) {
        if (!this.client) return;
        this.client.updateAppName(e, t);
    }
    updateDirtyFlag(e, t) {
        if (!this.client) return;
        this.client.updateDirtyFlag(e, t);
    }
    updateCleanupFn(e) {
        if (!this.client) return;
        this.client.updateCleanupFn(e);
    }
    removeCleanupFn() {
        if (!this.client) return;
        this.client.removeCleanupFn();
    }
    registerApp(e, t, s) {
        if (!this.client) return;
        this.client.registerApp(e, t, s);
    }
    openObject(e, t, s) {
        if (!this.client) return;
        this.client.openObject(e, t, M, s);
    }
    createObject(e, t, s) {
        if (!this.client) return;
        this.client.openObject(e, t, S, s);
    }
    updateModel() {
        if (!this.client) return;
        this.client.updateModel();
    }
    setUnsavedChangesLocalizedFn(e) {
        this.config.getUnsavedChangesLocalizedString = e;
    }
    getAvailableApp(e) {
        if (!this.client) return null;
        return this.client.getAvailableApp(e);
    }
};

function Z(e) {
    return e && typeof e === "object" && "appId" in e;
}

function ee(e) {
    T([ {
        id: "sas.drive.logon.lastAppDirective",
        value: e
    } ]).catch((t => l("appSwitcher").error(`set preference sas.drive.logon.lastAppDirective to ${e} failed.`)));
}

const te = e => {
    const t = new Y(e);
    let s;
    let a;
    A();
    t.subscribe(v, ((e, t) => {
        if (t?.settings) for (const {id: e, newValue: i} of t.settings) {
            const n = e === "sas.drive.logon.action";
            const o = e === "sas.drive.logon.specificAppDirective";
            if (n || o) {
                a = n && i === "lastAppDirective" || o && i === "lastAppDirective";
                const e = t.broadcaster?.appId && t.broadcaster.appId === s;
                if (a && s && e) ee(s);
                break;
            }
        }
    }));
    t.subscribe(u, ((e, t) => {
        i.publish(u, {
            data: t
        });
        if (Z(t) && typeof t.appId === "string") {
            s = t.appId;
            if (a === true) ee(s); else if (a === void 0) y("sas.drive.logon.action").then((e => {
                if (a === void 0) if (e.value === "lastAppDirective" && s) {
                    a = true;
                    ee(s);
                } else a = false;
            })).catch((e => {}));
        }
    }));
    t.subscribe(d, ((e, t) => {
        s = void 0;
        i.publish("Cache.Reload", {
            data: t
        });
    }));
    i.subscribe(w, (() => {
        t.setDirtyMessageEnabled(false);
    }));
    return t;
};

const se = () => {
    const e = window.location.origin;
    const t = window.location.pathname;
    const s = t.indexOf("/", 1);
    return e + t.substring(0, s) + "/logout";
};

let ie;

const ae = () => {
    if (!ie) ie = te({
        applicationService: new K,
        getLogoffUrl: se,
        getUnsavedChangesLocalizedString: () => ""
    });
    return ie;
};

F(L);

let ne;

I("NovaComponents-NovaApplicationSwitcher-gui-icu").then((e => {
    ne = e;
}));

const oe = e => `${ne("dirtySignOutMessageDialog.followingApplications.msg")}\n${e}\n${ne("dirtySignOutMessageDialog.exitApplications.msg")}`;

const re = ae();

re.setUnsavedChangesLocalizedFn(oe);

export { h as APP_ADDED, o as APP_DATA_LOADED, S as CREATE, m as DIRTY_FLAG_CHANGED, d as HIDE, p as LOGOFF_IMMINENT, M as OPEN, v as PREFERENCE_CHANGED, g as RETURN, u as SHOW, f as SWITCH, t as UPDATE_MODEL, s as USE_NOVA_APPSWITCHER, re as applicationSwitcher };
