import { objectMerge as d } from "@scalar/oas-utils/helpers";
import { availableTargets as C } from "httpsnippet-lite";
import { computed as c, ref as T, reactive as h, readonly as f } from "vue";
function v(n) {
  var t;
  return ((t = s.value.find((e) => e.key === n.targetKey)) == null ? void 0 : t.title) ?? n.targetKey;
}
function p(n) {
  var t, e;
  return ((e = (t = s.value.find((i) => i.key === n.targetKey)) == null ? void 0 : t.clients.find((i) => i.key === n.clientKey)) == null ? void 0 : e.title) ?? n.clientKey;
}
const b = c(() => v(l)), m = c(() => p(l));
function K(n, t) {
  return t.value === !0 ? [] : n.flatMap((e) => {
    var i;
    return typeof t.value != "object" ? [] : Array.isArray(t.value) ? (e.clients = e.clients.filter(
      // @ts-expect-error Typescript, chill. It’s all good. It has to be an array.
      (r) => !t.value.includes(r.key)
    ), [e]) : t.value[e.key] === !0 ? [] : (Array.isArray(t.value[e.key]) && (e.clients = e.clients.filter((r) => !// @ts-expect-error We checked whether it’s an Array already.
    t.value[e.key].includes(r.key))), (i = e == null ? void 0 : e.clients) != null && i.length ? [e] : []);
  });
}
const s = c(() => {
  var t;
  const n = C();
  return (t = n.find((e) => e.key === "node")) == null || t.clients.unshift({
    description: "An HTTP/1.1 client, written from scratch for Node.js.",
    key: "undici",
    link: "https://github.com/nodejs/undici",
    title: "undici"
  }), K(n, u);
}), y = {
  node: ["unirest"]
}, u = T({
  ...y === !0 ? {} : y
}), a = () => {
  var t, e, i, r;
  return s.value.find(
    (o) => o.key === "shell" && o.clients.find((k) => k.key === "curl")
  ) ? {
    targetKey: "shell",
    clientKey: "curl"
  } : {
    targetKey: (t = s.value[0]) == null ? void 0 : t.key,
    clientKey: (r = (i = (e = s.value[0]) == null ? void 0 : e.clients) == null ? void 0 : i[0]) == null ? void 0 : r.key
  };
}, l = h(a());
function A() {
  d(l, a());
}
const j = (n) => {
  Object.assign(l, {
    ...l,
    ...n
  });
}, g = () => ({
  httpClient: f(l),
  resetState: A,
  setHttpClient: j,
  excludedClients: f(u),
  setExcludedClients: (n) => {
    u.value = n, d(l, a());
  },
  availableTargets: s,
  getClientTitle: p,
  getTargetTitle: v,
  httpTargetTitle: b,
  httpClientTitle: m
});
export {
  K as filterHiddenClients,
  g as useHttpClientStore
};
