import { defineComponent as k, ref as x, watch as B, onBeforeUnmount as y, computed as u, toValue as g, createBlock as N, openBlock as i, withCtx as W, createVNode as l, createElementBlock as v, unref as d, withDirectives as E, vShow as U, createElementVNode as V } from "vue";
import { ScalarToasts as D } from "@scalar/use-toasts";
import { mergeSecurity as I } from "../../blocks/scalar-auth-selector-block/helpers/merge-security.js";
import C from "../../components/modals/ModalClientContainer.vue.js";
import { initializeModalEvents as A } from "./modal-events.js";
import L from "../operation/Operation.vue.js";
import { getActiveEnvironment as M } from "../../helpers/get-active-environment.js";
import { useGlobalHotKeys as T } from "../../hooks/use-global-hot-keys.js";
import { useScrollLock as $ } from "../../hooks/use-scroll-lock.js";
import z from "../../components/sidebar/SidebarToggle.vue.js";
import H from "../../components/sidebar/Sidebar.vue.js";
const j = {
  key: 0,
  class: "relative flex h-full min-h-0 w-full flex-1"
}, q = {
  key: 1,
  class: "flex h-full w-full items-center justify-center"
}, F = {}, _ = /* @__PURE__ */ k({
  ...F,
  __name: "Modal",
  props: {
    workspaceStore: {},
    document: {},
    path: {},
    eventBus: {},
    method: {},
    exampleName: {},
    modalState: {},
    sidebarState: {},
    plugins: {},
    options: {}
  },
  setup(e, { expose: f }) {
    const s = {
      label: "default",
      id: "default"
    }, o = x(!1);
    A({
      eventBus: e.eventBus,
      isSidebarOpen: o,
      sidebarState: e.sidebarState,
      modalState: e.modalState,
      store: e.workspaceStore
    }), T(e.eventBus, "modal", () => !e.modalState.open);
    const c = () => {
      e.eventBus.emit("operation:cancel:request");
    }, S = $(() => typeof window < "u" ? window.document.body : null);
    B(
      () => e.modalState.open,
      (a) => {
        S.value = a, a || c();
      }
    ), y(() => c());
    const h = 288, n = u(
      () => e.workspaceStore?.workspace?.["x-scalar-sidebar-width"] ?? h
    ), w = (a) => e.workspaceStore?.update("x-scalar-sidebar-width", a), r = u(
      () => M(e.workspaceStore, e.document.value)
    ), b = u(
      () => I(
        e.document.value?.components?.securitySchemes,
        g(e.options)?.authentication?.securitySchemes,
        e.workspaceStore.auth,
        e.document.value?.["x-scalar-navigation"]?.name ?? ""
      )
    );
    return f({
      sidebarWidth: n,
      environment: r
    }), (a, t) => (i(), N(C, { modalState: e.modalState }, {
      default: W(() => [
        l(d(D)),
        e.document.value && e.path?.value && e.method?.value ? (i(), v("main", j, [
          l(d(z), {
            modelValue: o.value,
            "onUpdate:modelValue": t[0] || (t[0] = (m) => o.value = m),
            class: "absolute top-2 left-3 z-2"
          }, null, 8, ["modelValue"]),
          E(l(d(H), {
            sidebarWidth: n.value,
            "onUpdate:sidebarWidth": [
              t[1] || (t[1] = (m) => n.value = m),
              w
            ],
            activeWorkspace: s,
            class: "h-full max-md:absolute! max-md:w-full!",
            documents: [e.document.value],
            eventBus: e.eventBus,
            isDroppable: () => !1,
            layout: "modal",
            sidebarState: e.sidebarState.state,
            workspaces: [],
            onSelectItem: e.sidebarState.handleSelectItem
          }, null, 8, ["sidebarWidth", "documents", "eventBus", "sidebarState", "onSelectItem"]), [
            [U, o.value]
          ]),
          l(L, {
            activeWorkspace: s,
            class: "flex-1",
            document: e.document.value,
            documentSlug: e.document.value["x-scalar-navigation"]?.id ?? "",
            environment: r.value,
            eventBus: e.eventBus,
            exampleName: e.exampleName?.value,
            layout: "modal",
            method: e.method?.value,
            options: e.options,
            path: e.path?.value,
            plugins: e.plugins,
            securitySchemes: b.value,
            workspaceStore: e.workspaceStore
          }, null, 8, ["document", "documentSlug", "environment", "eventBus", "exampleName", "method", "options", "path", "plugins", "securitySchemes", "workspaceStore"])
        ])) : (i(), v("div", q, [...t[2] || (t[2] = [
          V("span", { class: "text-c-3" }, "No document selected", -1)
        ])]))
      ]),
      _: 1
    }, 8, ["modalState"]));
  }
});
export {
  _ as default
};
