import { defineComponent as g, computed as s, ref as S, watch as x, withDirectives as b, createBlock as y, openBlock as w, unref as l, withCtx as a, createVNode as n, createElementVNode as m, createTextVNode as u, toDisplayString as k, normalizeClass as B, vShow as V } from "vue";
import { ScalarErrorBoundary as D, ScalarCodeBlock as T, ScalarCombobox as E, ScalarButton as N } from "@scalar/components";
import { ScalarIconCaretDown as O } from "@scalar/icons";
import { generateCodeSnippet as z } from "../../operation-code-sample/helpers/generate-code-snippet.js";
import { getClients as I } from "../../operation-code-sample/helpers/get-clients.js";
import { getCustomCodeSamples as R } from "../../operation-code-sample/helpers/get-custom-code-samples.js";
import { getSecrets as W } from "../../operation-code-sample/helpers/get-secrets.js";
import { findClient as f } from "../../operation-code-sample/helpers/find-client.js";
import $ from "../../../components/layout/CollapsibleSection.vue.js";
import q from "../../../components/data-table/DataTable.vue.js";
import F from "../../../components/data-table/DataTableRow.vue.js";
const H = { class: "flex flex-1" }, L = { class: "overflow-hidden" }, Z = /* @__PURE__ */ g({
  __name: "RequestCodeSnippet",
  props: {
    integration: {},
    clientOptions: {},
    selectedClient: {},
    selectedServer: { default: null },
    selectedContentType: {},
    selectedExample: {},
    eventBus: {},
    securitySchemes: {},
    method: {},
    path: {},
    operation: {},
    fallback: { type: Boolean },
    generateLabel: { type: Function },
    isWebhook: { type: Boolean },
    globalCookies: {}
  },
  setup(e) {
    const d = s(() => R(e.operation)), c = s(
      () => I(d.value, e.clientOptions)
    ), i = S(
      f(c.value, e.selectedClient)
    );
    x(
      () => e.selectedClient,
      (t) => {
        const o = f(c.value, t);
        o && (i.value = o);
      }
    );
    const p = s(() => W(e.securitySchemes ?? [])), C = (t) => {
      i.value = t, t && !t.id.startsWith("custom") && e.eventBus.emit("workspace:update:selected-client", t.id);
    }, v = s(
      () => z({
        clientId: i.value?.id,
        customCodeSamples: d.value,
        operation: e.operation,
        method: e.method,
        path: e.path,
        contentType: e.selectedContentType,
        server: e.selectedServer,
        securitySchemes: e.securitySchemes,
        example: e.selectedExample,
        globalCookies: e.globalCookies,
        includeDefaultHeaders: e.integration === "client"
      })
    ), h = s(
      () => c.value.some((t) => t.options.length > 0)
    );
    return (t, o) => b((w(), y(l($), {
      class: "group/preview w-full border-t",
      defaultOpen: !1
    }, {
      title: a(() => [...o[1] || (o[1] = [
        u("Code Snippet", -1)
      ])]),
      actions: a(() => [
        m("div", H, [
          n(l(E), {
            modelValue: i.value,
            options: c.value,
            placement: "bottom-end",
            "onUpdate:modelValue": o[0] || (o[0] = (r) => C(r))
          }, {
            default: a(({ open: r }) => [
              n(l(N), {
                class: "text-c-2 hover:text-c-1 flex h-full w-fit gap-1.5 px-0.5 py-0 text-base font-normal",
                "data-testid": "client-picker",
                variant: "ghost"
              }, {
                default: a(() => [
                  u(k(i.value?.title) + " ", 1),
                  n(l(O), {
                    class: B(["mt-0.25 size-3 transition-transform duration-100", r && "rotate-180"]),
                    weight: "bold"
                  }, null, 8, ["class"])
                ]),
                _: 2
              }, 1024)
            ]),
            _: 1
          }, 8, ["modelValue", "options"])
        ])
      ]),
      default: a(() => [
        n(l(D), null, {
          default: a(() => [
            n(l(q), {
              columns: [""],
              presentational: ""
            }, {
              default: a(() => [
                n(l(F), null, {
                  default: a(() => [
                    m("div", L, [
                      n(l(T), {
                        class: "text-base",
                        content: v.value,
                        hideCredentials: p.value,
                        lang: i.value?.lang ?? "plaintext",
                        lineNumbers: ""
                      }, null, 8, ["content", "hideCredentials", "lang"])
                    ])
                  ]),
                  _: 1
                })
              ]),
              _: 1
            })
          ]),
          _: 1
        })
      ]),
      _: 1
    }, 512)), [
      [V, h.value]
    ]);
  }
});
export {
  Z as default
};
