import { defineComponent as C, useId as M, computed as d, ref as h, toValue as E, createBlock as p, createCommentVNode as u, openBlock as o, unref as t, withCtx as r, createVNode as x, createElementBlock as k, Fragment as N, renderList as F, createTextVNode as g, toDisplayString as I, withDirectives as K, createElementVNode as _, vModelCheckbox as A } from "vue";
import { ScalarCard as D, 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 Q from "../../components/ScreenReader.vue.js";
import W from "./ExampleResponse.vue.js";
import X from "./ExampleResponseTab.vue.js";
import Y from "./ExampleResponseTabList.vue.js";
import Z from "../../v2/blocks/scalar-request-example-block/components/ExamplePicker.vue2.js";
const z = {
  key: 1,
  class: "scalar-card-checkbox"
}, ee = ["aria-controls"], se = {
  key: 0,
  class: "response-description"
}, ie = /* @__PURE__ */ C({
  __name: "ExampleResponses",
  props: {
    responses: {}
  },
  setup(R) {
    var j;
    const v = M(), { copyToClipboard: w } = P(), y = d(
      () => Object.keys(R.responses ?? {}).sort()
    ), V = h(0), f = d(() => {
      var s;
      const e = E(y)[E(V)];
      return (s = R.responses) == null ? void 0 : s[e];
    }), l = d(() => {
      var c;
      const e = H(
        (c = f.value) == null ? void 0 : c.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 = l.value) != null && e.examples) && Object.keys(((s = l.value) == null ? void 0 : s.examples) ?? {}).length > 1;
      }
    ), i = h(
      Object.keys(((j = l.value) == null ? void 0 : j.examples) ?? {})[0] ?? ""
    ), O = () => {
      var a;
      const e = E(l);
      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 = l.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(), p(t(D), {
      key: 0,
      "aria-label": "Example Responses",
      role: "region",
      class: "response-card"
    }, {
      default: r(() => {
        var c;
        return [
          x(Y, { onChange: B }, {
            actions: r(() => {
              var a, m;
              return [
                (a = l.value) != null && a.example ? (o(), k("button", {
                  key: 0,
                  class: "code-copy",
                  type: "button",
                  onClick: s[0] || (s[0] = () => {
                    var n;
                    return t(w)((n = l.value) == null ? void 0 : n.example);
                  })
                }, [
                  x(t(L), {
                    icon: "Clipboard",
                    width: "12px"
                  })
                ])) : u("", !0),
                (m = l.value) != null && m.schema ? (o(), k("label", z, [
                  s[4] || (s[4] = g(" Show Schema ")),
                  K(_("input", {
                    "onUpdate:modelValue": s[1] || (s[1] = (n) => S.value = n),
                    "aria-controls": t(v),
                    class: "scalar-card-checkbox-input",
                    type: "checkbox"
                  }, null, 8, ee), [
                    [A, S.value]
                  ]),
                  s[5] || (s[5] = _("span", { class: "scalar-card-checkbox-checkmark" }, null, -1))
                ])) : u("", !0)
              ];
            }),
            default: r(() => [
              (o(!0), k(N, null, F(y.value, (a) => (o(), p(X, {
                key: a,
                "aria-controls": t(v)
              }, {
                default: r(() => [
                  x(Q, null, {
                    default: r(() => s[3] || (s[3] = [
                      g("Status:")
                    ])),
                    _: 1,
                    __: [3]
                  }),
                  g(" " + I(a), 1)
                ]),
                _: 2
              }, 1032, ["aria-controls"]))), 128))
            ]),
            _: 1
          }),
          x(t(U), { class: "grid flex-1" }, {
            default: r(() => {
              var a;
              return [
                S.value && ((a = l.value) != null && a.schema) ? (o(), p(t($), {
                  key: 0,
                  id: t(v),
                  class: "-outline-offset-2",
                  content: l.value.schema,
                  lang: "json"
                }, null, 8, ["id", "content"])) : (o(), p(W, {
                  key: 1,
                  id: t(v),
                  response: l.value,
                  example: T.value
                }, null, 8, ["id", "response", "example"]))
              ];
            }),
            _: 1
          }),
          (c = f.value) != null && c.description || b.value ? (o(), p(t(q), {
            key: 0,
            class: "response-card-footer"
          }, {
            default: r(() => {
              var a, m;
              return [
                (a = f.value) != null && a.description ? (o(), k("div", se, [
                  x(t(G), {
                    class: "markdown",
                    value: f.value.description
                  }, null, 8, ["value"])
                ])) : u("", !0),
                b.value ? (o(), p(t(Z), {
                  key: 1,
                  class: "response-example-selector",
                  examples: (m = l.value) == null ? void 0 : m.examples,
                  modelValue: i.value,
                  "onUpdate:modelValue": s[2] || (s[2] = (n) => i.value = n)
                }, null, 8, ["examples", "modelValue"])) : u("", !0)
              ];
            }),
            _: 1
          })) : u("", !0)
        ];
      }),
      _: 1
    })) : u("", !0);
  }
});
export {
  ie as default
};
