import { defineComponent as C, useId as M, computed as d, ref as h, toValue as E, createBlock as u, createCommentVNode as m, openBlock as o, unref as l, withCtx as c, createVNode as x, createElementBlock as k, Fragment as N, renderList as D, createTextVNode as R, toDisplayString as F, withDirectives as I, createElementVNode as _, vModelCheckbox as K } from "vue";
import { ScalarCard as A, ScalarIcon as L, ScalarCardSection as U, ScalarCodeBlock as $, ScalarCardFooter as q, ScalarMarkdown as G } from "@scalar/components";
import { normalizeMimeTypeObject as H, getObjectKeys as J } from "@scalar/oas-utils/helpers";
import { useClipboard as P } from "@scalar/use-hooks/useClipboard";
import { getResolvedRef as Q } from "@scalar/workspace-store/helpers/get-resolved-ref";
import W from "../../components/ScreenReader.vue.js";
import X from "./ExampleResponse.vue.js";
import Y from "./ExampleResponseTab.vue.js";
import Z from "./ExampleResponseTabList.vue.js";
import { getResolvedRefDeep as z } from "./helpers/get-resolved-ref-deep.js";
import ee from "../../v2/blocks/scalar-request-example-block/components/ExamplePicker.vue2.js";
const se = {
  key: 1,
  class: "scalar-card-checkbox"
}, ae = ["aria-controls"], le = {
  key: 0,
  class: "response-description"
}, ve = /* @__PURE__ */ C({
  __name: "ExampleResponses",
  props: {
    responses: {}
  },
  setup(g) {
    var j;
    const v = M(), { copyToClipboard: w } = P(), y = d(
      () => Object.keys(g.responses ?? {}).sort()
    ), V = h(0), f = d(() => {
      var s;
      const e = E(y)[E(V)];
      return Q((s = g.responses) == null ? void 0 : s[e]);
    }), t = d(() => {
      var p;
      const e = H(
        (p = f.value) == null ? void 0 : p.content
      ), s = J(e ?? {});
      return (
        // OpenAPI 3.x
        (e == null ? void 0 : e["application/json"]) ?? (e == null ? void 0 : e["application/xml"]) ?? (e == null ? void 0 : e["text/plain"]) ?? (e == null ? void 0 : e["text/html"]) ?? (e == null ? void 0 : e["*/*"]) ?? // Take the first key - in the future we may want to use the selected content type
        (e == null ? void 0 : e[s[0]]) ?? void 0
      );
    }), b = d(
      () => {
        var e, s;
        return !!((e = t.value) != null && e.examples) && Object.keys(((s = t.value) == null ? void 0 : s.examples) ?? {}).length > 1;
      }
    ), i = h(
      Object.keys(((j = t.value) == null ? void 0 : j.examples) ?? {})[0] ?? ""
    ), O = () => {
      var a;
      const e = E(t);
      if (!e)
        return;
      if (Array.isArray(e.examples))
        return e.examples[0];
      const s = Object.keys(e.examples ?? {})[0];
      return (a = e.examples) == null ? void 0 : a[s];
    }, T = d(
      () => {
        var e, s;
        return b.value && i.value ? (s = (e = t.value) == null ? void 0 : e.examples) == null ? void 0 : s[i.value] : O();
      }
    ), B = (e) => {
      V.value = e, i.value = "";
    }, S = h(!1);
    return (e, s) => y.value.length ? (o(), u(l(A), {
      key: 0,
      "aria-label": "Example Responses",
      role: "region",
      class: "response-card"
    }, {
      default: c(() => {
        var p;
        return [
          x(Z, { onChange: B }, {
            actions: c(() => {
              var a, r;
              return [
                (a = t.value) != null && a.example ? (o(), k("button", {
                  key: 0,
                  class: "code-copy",
                  type: "button",
                  onClick: s[0] || (s[0] = () => {
                    var n;
                    return l(w)((n = t.value) == null ? void 0 : n.example);
                  })
                }, [
                  x(l(L), {
                    icon: "Clipboard",
                    width: "12px"
                  })
                ])) : m("", !0),
                (r = t.value) != null && r.schema ? (o(), k("label", se, [
                  s[4] || (s[4] = R(" Show Schema ")),
                  I(_("input", {
                    "onUpdate:modelValue": s[1] || (s[1] = (n) => S.value = n),
                    "aria-controls": l(v),
                    class: "scalar-card-checkbox-input",
                    type: "checkbox"
                  }, null, 8, ae), [
                    [K, S.value]
                  ]),
                  s[5] || (s[5] = _("span", { class: "scalar-card-checkbox-checkmark" }, null, -1))
                ])) : m("", !0)
              ];
            }),
            default: c(() => [
              (o(!0), k(N, null, D(y.value, (a) => (o(), u(Y, {
                key: a,
                "aria-controls": l(v)
              }, {
                default: c(() => [
                  x(W, null, {
                    default: c(() => s[3] || (s[3] = [
                      R("Status:")
                    ])),
                    _: 1,
                    __: [3]
                  }),
                  R(" " + F(a), 1)
                ]),
                _: 2
              }, 1032, ["aria-controls"]))), 128))
            ]),
            _: 1
          }),
          x(l(U), { class: "grid flex-1" }, {
            default: c(() => {
              var a, r;
              return [
                S.value && ((a = t.value) != null && a.schema) ? (o(), u(l($), {
                  key: 0,
                  id: l(v),
                  class: "-outline-offset-2",
                  content: l(z)((r = t.value) == null ? void 0 : r.schema),
                  lang: "json"
                }, null, 8, ["id", "content"])) : (o(), u(X, {
                  key: 1,
                  id: l(v),
                  response: t.value,
                  example: T.value
                }, null, 8, ["id", "response", "example"]))
              ];
            }),
            _: 1
          }),
          (p = f.value) != null && p.description || b.value ? (o(), u(l(q), {
            key: 0,
            class: "response-card-footer"
          }, {
            default: c(() => {
              var a, r;
              return [
                (a = f.value) != null && a.description ? (o(), k("div", le, [
                  x(l(G), {
                    class: "markdown",
                    value: f.value.description
                  }, null, 8, ["value"])
                ])) : m("", !0),
                b.value ? (o(), u(l(ee), {
                  key: 1,
                  class: "response-example-selector",
                  examples: (r = t.value) == null ? void 0 : r.examples,
                  modelValue: i.value,
                  "onUpdate:modelValue": s[2] || (s[2] = (n) => i.value = n)
                }, null, 8, ["examples", "modelValue"])) : m("", !0)
              ];
            }),
            _: 1
          })) : m("", !0)
        ];
      }),
      _: 1
    })) : m("", !0);
  }
});
export {
  ve as default
};
