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