import { defineComponent as T, computed as c, toValue as g, createBlock as p, openBlock as u, unref as t, withCtx as d, createElementVNode as i, createVNode as n, createElementBlock as v, renderSlot as k, createCommentVNode as W, normalizeProps as x, guardReactiveProps as B } from "vue";
import { useModal as C, ScalarTeleportRoot as M } from "@scalar/components";
import { ScalarToasts as D } from "@scalar/use-toasts";
import { extensions as O } from "@scalar/workspace-store/schemas/extensions";
import { RouterView as E } from "vue-router";
import _ from "./components/CreateWorkspaceModal.vue.js";
import A from "./components/SplashScreen.vue.js";
import { useDocumentWatcher as U } from "./hooks/use-document-watcher.js";
import V from "../command-palette/TheCommandPalette.vue.js";
import { useColorMode as I } from "../../hooks/use-color-mode.js";
import { useGlobalHotKeys as N } from "../../hooks/use-global-hot-keys.js";
import P from "./components/AppSidebar.vue.js";
import R from "./components/DesktopTabs.vue.js";
import { useMonacoEditorConfiguration as $ } from "../editor/config.js";
import { mergeSecurity as F } from "../../blocks/scalar-auth-selector-block/helpers/merge-security.js";
import H from "../../components/sidebar/SidebarToggle.vue.js";
const L = ["innerHTML"], z = { key: 0 }, G = { class: "relative flex h-dvh w-dvw flex-1 flex-col" }, K = { class: "flex min-h-0 flex-1 flex-row" }, j = { class: "flex flex-1 flex-col" }, q = { class: "bg-b-1 min-h-0 flex-1" }, J = { key: 1 }, Q = {}, ve = /* @__PURE__ */ T({
  ...Q,
  __name: "App",
  props: {
    layout: {},
    plugins: { default: () => [] },
    getAppState: { type: Function },
    getCommandPaletteState: { type: Function },
    fetchRegistryDocument: { type: Function }
  },
  setup(s, { expose: f }) {
    f({
      openCreateWorkspace: () => l.show()
    });
    const e = s.getAppState(), h = s.getCommandPaletteState();
    typeof window < "u" && (window.dataDumpWorkspace = () => e.store.value, window.dumpAppState = () => e), N(e.eventBus, s.layout), U({
      documentName: () => e.store.value?.workspace[O.workspace.activeDocument],
      store: e.store,
      initialTimeout: 5e3
    }), I({ workspaceStore: e.store });
    const w = c(() => e.theme.styles.value.themeStyles), S = c(() => e.isDarkMode.value);
    $({
      theme: w,
      darkMode: S
    });
    const m = (o, a) => {
      e.eventBus.emit("ui:navigate", {
        page: "workspace",
        path: "environment",
        namespace: o,
        workspaceSlug: a
      });
    }, b = (o) => {
      if (!o)
        return;
      const a = e.workspace.workspaceList.value?.find(
        (r) => r.id === o
      );
      a && m(a.namespace, a.slug);
    }, l = C(), y = c(() => {
      const o = e.store.value?.auth ? F(
        e.document.value?.components?.securitySchemes ?? {},
        {},
        e.store.value.auth,
        e.activeEntities.documentSlug.value ?? ""
      ) : {};
      return {
        documentSlug: e.activeEntities.documentSlug.value ?? "",
        document: e.store.value?.workspace.activeDocument ?? null,
        environment: e.environment.value,
        eventBus: e.eventBus,
        exampleName: e.activeEntities.exampleName.value,
        fetchRegistryDocument: s.fetchRegistryDocument,
        layout: s.layout,
        method: e.activeEntities.method.value,
        path: e.activeEntities.path.value,
        workspaceStore: e.store.value,
        activeWorkspace: e.workspace.activeWorkspace.value,
        plugins: s.plugins,
        securitySchemes: o,
        isDarkMode: e.isDarkMode.value,
        currentTheme: e.theme.styles.value.themeStyles,
        customThemes: g(e.theme.customThemes)
      };
    });
    return (o, a) => (u(), p(t(M), null, {
      default: d(() => [
        i("div", {
          innerHTML: t(e).theme.themeStyleTag.value
        }, null, 8, L),
        n(t(D)),
        t(e).store.value !== null && t(e).workspace.activeWorkspace.value !== null && !t(e).loading.value ? (u(), v("main", z, [
          i("div", G, [
            n(t(H), {
              modelValue: t(e).sidebar.isOpen.value,
              "onUpdate:modelValue": a[0] || (a[0] = (r) => t(e).sidebar.isOpen.value = r),
              class: "absolute top-4 left-3 z-[60] md:hidden"
            }, null, 8, ["modelValue"]),
            i("div", K, [
              n(P, {
                isSidebarOpen: t(e).sidebar.isOpen.value,
                "onUpdate:isSidebarOpen": a[1] || (a[1] = (r) => t(e).sidebar.isOpen.value = r),
                activeWorkspace: t(e).workspace.activeWorkspace.value,
                eventBus: t(e).eventBus,
                isWorkspaceOpen: t(e).workspace.isOpen.value,
                layout: s.layout,
                sidebarState: t(e).sidebar.state,
                sidebarWidth: t(e).sidebar.width.value,
                store: t(e).store.value,
                workspaces: t(e).workspace.workspaceGroups.value,
                "onClick:workspace": m,
                "onCreate:workspace": a[2] || (a[2] = (r) => t(l).show()),
                "onSelect:workspace": b,
                onSelectItem: t(e).sidebar.handleSelectItem,
                "onUpdate:sidebarWidth": t(e).sidebar.handleSidebarWidthUpdate
              }, {
                sidebarMenuActions: d(() => [
                  k(o.$slots, "sidebar-menu-actions")
                ]),
                _: 3
              }, 8, ["isSidebarOpen", "activeWorkspace", "eventBus", "isWorkspaceOpen", "layout", "sidebarState", "sidebarWidth", "store", "workspaces", "onSelectItem", "onUpdate:sidebarWidth"]),
              i("div", j, [
                s.layout === "desktop" ? (u(), p(R, {
                  key: 0,
                  activeTabIndex: t(e).tabs.activeTabIndex.value,
                  eventBus: t(e).eventBus,
                  tabs: t(e).tabs.state.value
                }, null, 8, ["activeTabIndex", "eventBus", "tabs"])) : W("", !0),
                i("div", q, [
                  n(t(E), x(B(y.value)), null, 16)
                ])
              ])
            ])
          ]),
          k(o.$slots, "create-workspace", { state: t(l) }, () => [
            n(_, {
              state: t(l),
              "onCreate:workspace": a[3] || (a[3] = (r) => t(e).workspace.create(r))
            }, null, 8, ["state"])
          ]),
          n(V, {
            eventBus: t(e).eventBus,
            paletteState: t(h),
            workspaceStore: t(e).store.value
          }, null, 8, ["eventBus", "paletteState", "workspaceStore"])
        ])) : (u(), v("main", J, [
          n(A)
        ]))
      ]),
      _: 3
    }));
  }
});
export {
  ve as default
};
