import { defineComponent as O, computed as c, createElementBlock as b, createCommentVNode as S, openBlock as l, Fragment as g, createBlock as v, unref as y } from "vue";
import { useWorkspace as W } from "@scalar/api-client/store";
import { filterSecurityRequirements as U } from "@scalar/api-client/views/Request/RequestSection";
import { getResolvedRef as V } from "@scalar/workspace-store/helpers/get-resolved-ref";
import { combineParams as B } from "./helpers/combine-params.js";
import { convertSecurityScheme as C } from "../../helpers/convert-security-scheme.js";
import { useOperationDiscriminator as w } from "../../hooks/useOperationDiscriminator.js";
import D from "./layouts/ClassicLayout.vue.js";
import R from "./layouts/ModernLayout.vue.js";
const j = /* @__PURE__ */ O({
  __name: "Operation",
  props: {
    path: {},
    method: {},
    clientOptions: {},
    isWebhook: { type: Boolean },
    id: {},
    config: {},
    server: {},
    store: {},
    collection: {},
    document: {}
  },
  setup(o) {
    var p, f;
    const u = c(() => {
      var t, n;
      const e = o.isWebhook ? "webhooks" : "paths";
      return (n = (t = o.store.workspace.activeDocument) == null ? void 0 : t[e]) == null ? void 0 : n[o.path];
    }), a = c(() => {
      var n, i;
      const e = V((n = u.value) == null ? void 0 : n[o.method]);
      if (!e)
        return null;
      const t = B(
        (i = u.value) == null ? void 0 : i.parameters,
        e.parameters
      );
      return { ...e, parameters: t };
    }), m = c(
      () => {
        var e, t, n, i, r, s;
        return o.isWebhook ? (n = (t = (e = o.document) == null ? void 0 : e.webhooks) == null ? void 0 : t[o.path]) == null ? void 0 : n[o.method] : (s = (r = (i = o.document) == null ? void 0 : i.paths) == null ? void 0 : r[o.path]) == null ? void 0 : s[o.method];
      }
    ), { handleDiscriminatorChange: h } = w(
      m.value,
      (f = (p = o.document) == null ? void 0 : p.components) == null ? void 0 : f.schemas
    ), { securitySchemes: k } = W(), d = c(
      () => {
        var e, t;
        return U(
          ((e = a.value) == null ? void 0 : e.security) || ((t = o.document) == null ? void 0 : t.security),
          o.collection.selectedSecuritySchemeUids,
          k
        ).map(C);
      }
    );
    return (e, t) => {
      var n, i, r, s;
      return a.value && m.value ? (l(), b(g, { key: 0 }, [
        e.config.layout === "classic" ? (l(), v(D, {
          key: 0,
          id: e.id,
          isWebhook: e.isWebhook,
          method: e.method,
          operation: a.value,
          oldOperation: m.value,
          config: e.config,
          clientOptions: e.clientOptions,
          securitySchemes: d.value,
          store: e.store,
          path: e.path,
          schemas: (i = (n = e.document) == null ? void 0 : n.components) == null ? void 0 : i.schemas,
          server: e.server,
          "onUpdate:modelValue": y(h)
        }, null, 8, ["id", "isWebhook", "method", "operation", "oldOperation", "config", "clientOptions", "securitySchemes", "store", "path", "schemas", "server", "onUpdate:modelValue"])) : (l(), v(R, {
          key: 1,
          id: e.id,
          isWebhook: e.isWebhook,
          method: e.method,
          config: e.config,
          clientOptions: e.clientOptions,
          oldOperation: m.value,
          securitySchemes: d.value,
          path: e.path,
          store: e.store,
          operation: a.value,
          schemas: (s = (r = e.document) == null ? void 0 : r.components) == null ? void 0 : s.schemas,
          server: e.server,
          "onUpdate:modelValue": y(h)
        }, null, 8, ["id", "isWebhook", "method", "config", "clientOptions", "oldOperation", "securitySchemes", "path", "store", "operation", "schemas", "server", "onUpdate:modelValue"]))
      ], 64)) : S("", !0);
    };
  }
});
export {
  j as default
};
