import { defineComponent as C, computed as i, ref as H, useId as V, createBlock as t, openBlock as n, withCtx as m, createElementVNode as u, normalizeClass as k, createElementBlock as f, createVNode as h, Fragment as v, createCommentVNode as c, renderList as j, unref as x, withDirectives as w, resolveDynamicComponent as T, mergeProps as I, vShow as S } from "vue";
import { ScalarErrorBoundary as $ } from "@scalar/components";
import E from "../../../components/SectionFilter.vue.js";
import z from "../../../components/ViewLayout/ViewLayoutSection.vue.js";
import O from "./RequestHeaders.vue.js";
import L from "./ResponseBody.vue.js";
import M from "./ResponseBodyStreaming.vue.js";
import N from "./ResponseBodyVirtual.vue.js";
/* empty css                         */
import W from "./ResponseCookies.vue.js";
import D from "./ResponseEmpty.vue.js";
import F from "./ResponseHeaders.vue.js";
import P from "./ResponseLoadingOverlay.vue.js";
import U from "./ResponseMetaInformation.vue.js";
import { usePluginManager as K } from "../../../plugins/hooks/usePluginManager.js";
const Z = { class: "flex h-8 flex-1 items-center" }, G = ["id", "role"], b = 2e5, pe = /* @__PURE__ */ C({
  __name: "ResponseSection",
  props: {
    collection: {},
    operation: {},
    workspace: {},
    numWorkspaceRequests: {},
    response: {},
    requestResult: {}
  },
  setup(e) {
    const A = K().getViewComponents("response.section"), p = i(() => {
      const a = e.response?.headers;
      return a ? Object.keys(a).map((o) => ({
        name: o,
        value: a[o] ?? "",
        required: !1
      })) : [];
    }), B = i(
      () => e.response?.cookieHeaderKeys.flatMap((a) => {
        const o = e.response?.headers?.[a];
        return o ? {
          name: a,
          value: o,
          required: !1
        } : [];
      }) ?? []
    ), g = ["Cookies", "Headers", "Body"], s = H("All"), y = i(() => ["All", ...g]), l = i(
      () => Object.fromEntries(
        y.value.map((a) => [a, V()])
      )
    ), R = i(() => {
      if (!e.response || !("size" in e.response))
        return !1;
      const a = e.response.headers?.["content-type"] || e.response.headers?.["Content-Type"];
      return !a || (e.response.size ?? 0) <= b || a.includes("text/html") ? !1 : [
        // Text types
        "text/",
        // JSON types
        "application/json",
        "application/ld+json",
        "application/problem+json",
        "application/vnd.api+json",
        // XML types
        "application/xml",
        "application/atom+xml",
        "application/rss+xml",
        "application/problem+xml",
        // Other structured text
        "application/javascript",
        "application/ecmascript",
        "application/x-yaml",
        "application/yaml",
        // Source code
        "application/x-httpd-php",
        "application/x-sh",
        "application/x-perl",
        "application/x-python",
        "application/x-ruby",
        "application/x-java-source",
        // Form data
        "application/x-www-form-urlencoded"
      ].some((d) => a.includes(d)) && (e.response.size ?? 0) > b;
    }), q = i(
      () => e.requestResult?.request.parameters.headers.filter((a) => a.enabled).map((a) => ({
        name: a.key,
        value: a.value,
        required: !0
      })) ?? []
    );
    return (a, o) => (n(), t(z, { "aria-label": "Response" }, {
      title: m(() => [
        u("div", Z, [
          u("div", {
            "aria-live": "polite",
            class: k(["flex items-center", { "animate-response-heading": e.response }])
          }, [
            o[1] || (o[1] = u("span", { class: "response-heading pointer-events-none absolute" }, " Response ", -1)),
            e.response ? (n(), t(U, {
              key: 0,
              class: "animate-response-children",
              response: e.response
            }, null, 8, ["response"])) : c("", !0)
          ], 2),
          h(E, {
            modelValue: s.value,
            "onUpdate:modelValue": o[0] || (o[0] = (r) => s.value = r),
            filterIds: l.value,
            filters: y.value
          }, null, 8, ["modelValue", "filterIds", "filters"])
        ])
      ]),
      default: m(() => [
        u("div", {
          id: l.value.All,
          class: k(["custom-scroll response-section-content relative grid h-full justify-stretch", {
            "content-start": e.response
          }]),
          role: s.value === "All" && e.response ? "tabpanel" : "none"
        }, [
          e.response ? (n(), f(v, { key: 1 }, [
            s.value === "All" || s.value === "Cookies" ? (n(), t(W, {
              key: 0,
              class: "response-section-content-cookies",
              id: l.value.Cookies,
              cookies: B.value,
              role: s.value === "All" ? "none" : "tabpanel"
            }, null, 8, ["id", "cookies", "role"])) : c("", !0),
            s.value === "All" || s.value === "Headers" ? (n(), t(O, {
              key: 1,
              class: "response-section-content-headers",
              id: l.value.Headers,
              headers: q.value,
              role: s.value === "All" ? "none" : "tabpanel"
            }, null, 8, ["id", "headers", "role"])) : c("", !0),
            s.value === "All" || s.value === "Headers" ? (n(), t(F, {
              key: 2,
              class: "response-section-content-headers",
              id: l.value.Headers,
              headers: p.value,
              role: s.value === "All" ? "none" : "tabpanel"
            }, null, 8, ["id", "headers", "role"])) : c("", !0),
            (n(!0), f(v, null, j(x(A), (r, d) => (n(), t(x($), {
              key: r.title ?? d
            }, {
              default: m(() => [
                w((n(), t(T(r.component), I({ ref_for: !0 }, r.props ?? {}), null, 16)), [
                  [S, s.value === "All" || s.value === r.title]
                ])
              ]),
              _: 2
            }, 1024))), 128)),
            s.value === "All" || s.value === "Body" ? (n(), f(v, { key: 3 }, [
              "reader" in e.response ? (n(), t(M, {
                key: 0,
                class: "response-section-content-body",
                id: l.value.Body,
                reader: e.response.reader
              }, null, 8, ["id", "reader"])) : R.value && typeof e.response?.data == "string" ? (n(), t(N, {
                key: 1,
                id: l.value.Body,
                content: e.response.data,
                data: e.response?.data,
                headers: p.value,
                role: s.value === "All" ? "none" : "tabpanel"
              }, null, 8, ["id", "content", "data", "headers", "role"])) : (n(), t(L, {
                key: 2,
                class: "response-section-content-body",
                id: l.value.Body,
                layout: "client",
                active: !0,
                data: e.response?.data,
                headers: p.value,
                role: s.value === "All" ? "none" : "tabpanel",
                title: "Body"
              }, null, 8, ["id", "data", "headers", "role"]))
            ], 64)) : c("", !0)
          ], 64)) : (n(), t(D, {
            key: 0,
            collection: e.collection,
            operation: e.operation,
            workspace: e.workspace,
            numWorkspaceRequests: e.numWorkspaceRequests
          }, null, 8, ["collection", "operation", "workspace", "numWorkspaceRequests"])),
          h(P)
        ], 10, G)
      ]),
      _: 1
    }));
  }
});
export {
  pe as default
};
