import { defineComponent as K, ref as w, useId as y, watch as P, onMounted as B, computed as F, createElementBlock as l, createCommentVNode as b, unref as e, openBlock as n, createVNode as i, withCtx as m, createElementVNode as V, Fragment as h, normalizeClass as H, renderList as A, createBlock as D, createTextVNode as M, toDisplayString as p } from "vue";
import { TabGroup as O, TabList as R, TabPanels as j, TabPanel as z } from "@headlessui/vue";
import { useWorkspace as G } from "@scalar/api-client/store";
import { ScalarMarkdown as J, ScalarCodeBlock as W } from "@scalar/components";
import { REFERENCE_LS_KEYS as Y } from "@scalar/helpers/object/local-storage";
import { useHttpClientStore as q } from "../../../stores/useHttpClientStore.js";
import Q from "./ClientSelector.vue.js";
import { useFeaturedHttpClients as U } from "./useFeaturedHttpClients.js";
const Z = { key: 0 }, $ = ["id"], X = {
  key: 1,
  class: "selected-client card-footer border-t-0 p-0",
  role: "tabpanel",
  tabindex: "1"
}, ee = ["id"], de = /* @__PURE__ */ K({
  __name: "ClientLibraries",
  setup(te) {
    const {
      availableTargets: T,
      httpTargetTitle: k,
      httpClientTitle: x,
      getClientTitle: E,
      getTargetTitle: L,
      httpClient: a,
      setHttpClient: _
    } = q(), { featuredClients: d, isFeatured: S } = U(), I = G(), g = w(0), v = y(), C = y();
    P(
      a,
      (t) => {
        t && (g.value = d.findIndex(
          (o) => o.targetKey === t.targetKey && o.clientKey === t.clientKey
        ));
      },
      { immediate: !0 }
    );
    function N(t) {
      const o = d[t];
      o && _(o);
    }
    B(() => {
      const t = localStorage.getItem(Y.SELECTED_CLIENT);
      t && _(JSON.parse(t));
    });
    const r = F(() => {
      var c;
      const t = Object.values(I.collections)[0], o = (c = t == null ? void 0 : t.info) == null ? void 0 : c["x-scalar-sdk-installation"];
      if (!Array.isArray(o) || !(o != null && o.length))
        return;
      const s = o.find(
        (u) => {
          var f;
          return u.lang.toLowerCase() === ((f = a == null ? void 0 : a.targetKey) == null ? void 0 : f.toLowerCase());
        }
      );
      if (s)
        return s;
    });
    return (t, o) => e(T).length ? (n(), l("div", Z, [
      i(e(O), {
        manual: "",
        selectedIndex: g.value,
        onChange: N
      }, {
        default: m(() => [
          V("div", {
            id: e(v),
            class: "client-libraries-heading"
          }, " Client Libraries ", 8, $),
          i(e(R), {
            "aria-labelledby": e(v),
            class: "client-libraries-list"
          }, {
            default: m(() => [
              i(Q, {
                featured: e(d),
                morePanel: e(C)
              }, null, 8, ["featured", "morePanel"])
            ]),
            _: 1
          }, 8, ["aria-labelledby"]),
          i(e(j), null, {
            default: m(() => {
              var s, c;
              return [
                (s = r.value) != null && s.source || (c = r.value) != null && c.description ? (n(), l(h, { key: 0 }, [
                  r.value.description ? (n(), l("div", {
                    key: 0,
                    class: H(["selected-client card-footer -outline-offset-2", r.value.source && "rounded-b-none"]),
                    role: "tabpanel",
                    tabindex: "0"
                  }, [
                    i(e(J), {
                      value: r.value.description
                    }, null, 8, ["value"])
                  ], 2)) : b("", !0),
                  r.value.source ? (n(), l("div", X, [
                    i(e(W), {
                      lang: "shell",
                      content: r.value.source,
                      copy: !0,
                      class: "rounded-t-none rounded-b-lg px-3 py-2 -outline-offset-1 has-focus:outline"
                    }, null, 8, ["content"])
                  ])) : b("", !0)
                ], 64)) : e(a) && e(S)(e(a)) ? (n(!0), l(h, { key: 1 }, A(e(d), (u, f) => (n(), D(e(z), {
                  key: f,
                  class: "selected-client card-footer -outline-offset-2"
                }, {
                  default: m(() => [
                    M(p(e(E)(u)) + " " + p(e(L)(u)), 1)
                  ]),
                  _: 2
                }, 1024))), 128)) : (n(), l("div", {
                  key: 2,
                  id: e(C),
                  class: "selected-client card-footer -outline-offset-2",
                  role: "tabpanel",
                  tabindex: "0"
                }, p(e(x)) + " " + p(e(k)), 9, ee))
              ];
            }),
            _: 1
          })
        ]),
        _: 1
      }, 8, ["selectedIndex"])
    ])) : b("", !0);
  }
});
export {
  de as default
};
