import { defineComponent as b, computed as k, createElementBlock as W, createCommentVNode as y, openBlock as c, Fragment as U, createBlock as f, unref as m } from "vue";
import { useWorkspace as q } from "@scalar/api-client/store";
import { getPointer as B } from "../../blocks/helpers/getPointer.js";
import { useBlockProps as V } from "../../blocks/hooks/useBlockProps.js";
import { useOperationDiscriminator as C } from "../../hooks/useOperationDiscriminator.js";
import S from "./layouts/ClassicLayout.vue.js";
import g from "./layouts/ModernLayout.vue.js";
const M = /* @__PURE__ */ b({
  __name: "Operation",
  props: {
    document: {},
    path: {},
    method: {},
    isWebhook: { type: Boolean },
    layout: { default: "modern" },
    id: {},
    collection: {},
    server: {}
  },
  setup(o) {
    var v, p;
    const u = q(), s = k(
      () => {
        var e, t, n, r, i, l;
        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] : (l = (i = (r = o.document) == null ? void 0 : r.paths) == null ? void 0 : i[o.path]) == null ? void 0 : l[o.method];
      }
    ), { handleDiscriminatorChange: d } = C(
      s.value,
      (p = (v = o.document) == null ? void 0 : v.components) == null ? void 0 : p.schemas
    ), { operation: a } = V({
      store: u,
      collection: o.collection,
      location: B([o.isWebhook ? "webhooks" : "paths", o.path, o.method])
    }), h = k(() => {
      var e;
      if (!a.value)
        return o.server;
      if ((e = a.value) != null && e.selectedServerUid) {
        const t = u.servers[a.value.selectedServerUid];
        if (t)
          return t;
      }
      return o.server;
    });
    return (e, t) => {
      var n, r, i, l;
      return e.collection && s.value ? (c(), W(U, { key: 0 }, [
        e.layout === "classic" ? (c(), f(S, {
          key: 0,
          id: e.id,
          operation: s.value,
          collection: e.collection,
          isWebhook: e.isWebhook,
          method: e.method,
          path: e.path,
          request: m(a),
          schemas: (r = (n = e.document) == null ? void 0 : n.components) == null ? void 0 : r.schemas,
          server: h.value,
          "onUpdate:modelValue": m(d)
        }, null, 8, ["id", "operation", "collection", "isWebhook", "method", "path", "request", "schemas", "server", "onUpdate:modelValue"])) : (c(), f(g, {
          key: 1,
          id: e.id,
          collection: e.collection,
          isWebhook: e.isWebhook,
          method: e.method,
          path: e.path,
          request: m(a),
          operation: s.value,
          schemas: (l = (i = e.document) == null ? void 0 : i.components) == null ? void 0 : l.schemas,
          server: h.value,
          "onUpdate:modelValue": m(d)
        }, null, 8, ["id", "collection", "isWebhook", "method", "path", "request", "operation", "schemas", "server", "onUpdate:modelValue"]))
      ], 64)) : y("", !0);
    };
  }
});
export {
  M as default
};
