import { defineComponent as j, ref as $, computed as d, inject as w, onServerPrefetch as A, useSSRContext as F, openBlock as f, createBlock as k, unref as o, withCtx as p, createVNode as i, createTextVNode as P, toDisplayString as K, createElementVNode as y, renderSlot as b, createElementBlock as U, createCommentVNode as x } from "vue";
import { useServerStore as I, useAuthenticationStore as J, HttpMethod as L, getSecretCredentialsFromAuthentication as M, getRequestFromAuthentication as Y, getUrlFromServerState as z } from "@scalar/api-client";
import { ScalarIcon as D, ScalarCodeBlock as Q } from "@scalar/components";
import { createHash as W, ssrState as X } from "@scalar/oas-utils/helpers";
import { getRequestFromOperation as Z } from "@scalar/oas-utils/spec-getters";
import { snippetz as V } from "@scalar/snippetz";
import { asyncComputed as G } from "@vueuse/core";
import { HTTPSnippet as ee } from "httpsnippet-lite";
import te from "./ExamplePicker.vue.js";
import oe from "./TextSelect.vue.js";
/* empty css                */
import { GLOBAL_SECURITY_SYMBOL as re } from "../../../helpers/provideSymbols.js";
import ne from "../../Card/Card.vue.js";
import ae from "../../Card/CardHeader.vue.js";
import se from "../../Card/CardContent.vue.js";
import ie from "../../Card/CardFooter.vue.js";
import { useClipboard as le } from "../../../hooks/useClipboard.js";
import { useHttpClientStore as pe } from "../../../stores/useHttpClientStore.js";
import { getApiClientRequest as ce } from "../../../helpers/getApiClientRequest.js";
import { getHarRequest as ue } from "../../../helpers/getHarRequest.js";
const me = { class: "request-header" }, de = { class: "code-snippet" }, fe = {
  key: 0,
  class: "request-card-footer-addon"
}, $e = /* @__PURE__ */ j({
  __name: "ExampleRequest",
  props: {
    operation: {}
  },
  setup(_) {
    const s = _, h = `components-Content-Operation-Example-Request${W(
      s.operation.path + s.operation.httpVerb + s.operation.operationId
    )}`, C = $(), { copyToClipboard: E } = le(), {
      httpClient: a,
      setHttpClient: H,
      availableTargets: R,
      httpTargetTitle: T,
      httpClientTitle: B
    } = pe(), { server: S } = I(), { authentication: u } = J(), v = d(
      () => {
        var e, r, t, n;
        return Object.keys(
          ((n = (t = (r = (e = s.operation.information) == null ? void 0 : e.requestBody) == null ? void 0 : r.content) == null ? void 0 : t["application/json"]) == null ? void 0 : n.examples) ?? {}
        ).length > 1;
      }
    ), l = w(re);
    async function g() {
      var n;
      const e = ue(
        {
          url: z(S)
        },
        Z(
          s.operation,
          {
            replaceVariables: !0
          },
          C.value
        ),
        Y(
          u,
          ((n = s.operation.information) == null ? void 0 : n.security) ?? (l == null ? void 0 : l())
        )
      ), r = a.clientKey === "undici" || a.clientKey === "fetch" || a.clientKey === "ofetch" ? a.clientKey : null, t = a.targetKey.replace("javascript", "js");
      if (r && V().hasPlugin(t, r) && (t === "node" || t === "js"))
        return V().print(t, r, e) ?? "";
      try {
        return await new ee(e).convert(
          a.targetKey,
          a.clientKey
        );
      } catch (c) {
        return console.error("[ExampleRequest]", c), "";
      }
    }
    const m = G(
      g,
      X[h] ?? ""
    );
    A(async () => {
      const e = F();
      e.payload.data[h] = await g();
    }), d(() => ce({
      serverState: S,
      authenticationState: u,
      operation: s.operation,
      globalSecurity: l == null ? void 0 : l()
    }));
    const N = d(() => {
      const e = a.targetKey;
      return e === "shell" && m.value.includes("curl") ? "curl" : e === "c" || e === "csharp" ? "cpp" : e;
    });
    return (e, r) => (f(), k(o(ne), { class: "dark-mode" }, {
      default: p(() => [
        i(o(ae), { muted: "" }, {
          actions: p(() => [
            i(oe, {
              class: "request-client-picker",
              modelValue: JSON.stringify(o(a)),
              options: o(R).map((t) => ({
                value: t.key,
                label: t.title,
                options: t.clients.map((n) => ({
                  value: JSON.stringify({
                    targetKey: t.key,
                    clientKey: n.key
                  }),
                  label: n.title
                }))
              })),
              "onUpdate:modelValue": r[0] || (r[0] = (t) => o(H)(JSON.parse(t)))
            }, {
              default: p(() => [
                P(K(o(T)) + " " + K(o(B)), 1)
              ]),
              _: 1
            }, 8, ["modelValue", "options"]),
            y("button", {
              class: "copy-button",
              type: "button",
              onClick: r[1] || (r[1] = (t) => o(E)(o(m)))
            }, [
              i(o(D), {
                icon: "Clipboard",
                width: "10px"
              })
            ])
          ]),
          default: p(() => [
            y("div", me, [
              i(o(L), {
                as: "span",
                class: "request-method",
                method: e.operation.httpVerb
              }, null, 8, ["method"]),
              b(e.$slots, "header", {}, void 0, !0)
            ])
          ]),
          _: 3
        }),
        i(o(se), {
          borderless: "",
          class: "request-editor-section custom-scroll",
          frameless: ""
        }, {
          default: p(() => [
            y("div", de, [
              i(o(Q), {
                content: o(m),
                hideCredentials: o(M)(o(u)),
                lang: N.value,
                lineNumbers: ""
              }, null, 8, ["content", "hideCredentials", "lang"])
            ])
          ]),
          _: 1
        }),
        v.value || e.$slots.footer ? (f(), k(o(ie), {
          key: 0,
          class: "request-card-footer",
          contrast: ""
        }, {
          default: p(() => {
            var t, n, c, q;
            return [
              v.value ? (f(), U("div", fe, [
                i(te, {
                  class: "request-example-selector",
                  examples: ((q = (c = (n = (t = e.operation.information) == null ? void 0 : t.requestBody) == null ? void 0 : n.content) == null ? void 0 : c["application/json"]) == null ? void 0 : q.examples) ?? [],
                  "onUpdate:modelValue": r[2] || (r[2] = (O) => C.value = O)
                }, null, 8, ["examples"])
              ])) : x("", !0),
              b(e.$slots, "footer", {}, void 0, !0)
            ];
          }),
          _: 3
        })) : x("", !0)
      ]),
      _: 3
    }));
  }
});
export {
  $e as default
};
