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