import { jsx as e, jsxs as l, Fragment as N } from "react/jsx-runtime";
import { useState as o, useEffect as w, useMemo as m } from "react";
import { useTranslation as P } from "react-i18next";
import { useNavigate as j } from "react-router-dom";
import { Loader2 as z, AlertTriangle as K, Layers as R, CheckCircle as B, XCircle as O, Search as X, BookOpen as $, Code as q } from "lucide-react";
import { P as D, K as h, v as G } from "./index-CeEMms9z.js";
function W() {
  const { t: a } = P("admin"), A = j(), [s, C] = o([]), [L, g] = o(!0), [b, f] = o(null), [c, k] = o(""), [d, E] = o("all"), [n, T] = o("all"), [p, y] = o("all");
  w(() => {
    (async () => {
      try {
        g(!0);
        const r = await G.externalApps.getApiEndpoints();
        C(r), f(null);
      } catch (r) {
        f(r instanceof Error ? r.message : "Failed to load endpoints");
      } finally {
        g(!1);
      }
    })();
  }, []);
  const F = m(() => {
    const t = /* @__PURE__ */ new Map();
    return s.forEach((r) => t.set(r.applicationCode, r.applicationLabel)), [...t.entries()].sort((r, i) => r[1].localeCompare(i[1]));
  }, [s]), S = m(() => {
    const t = n === "all" ? s : s.filter((i) => i.applicationCode === n), r = /* @__PURE__ */ new Map();
    return t.forEach((i) => r.set(i.moduleCode, i.moduleLabel)), [...r.entries()].sort((i, v) => i[1].localeCompare(v[1]));
  }, [s, n]);
  w(() => {
    y("all");
  }, [n]);
  const x = m(() => s.filter((t) => {
    const r = !c || t.name.toLowerCase().includes(c.toLowerCase()) || t.code.toLowerCase().includes(c.toLowerCase()) || t.routeTemplate.toLowerCase().includes(c.toLowerCase()) || t.applicationLabel.toLowerCase().includes(c.toLowerCase()) || t.moduleLabel.toLowerCase().includes(c.toLowerCase()), i = d === "all" || d === "active" && t.isActive || d === "inactive" && !t.isActive, v = n === "all" || t.applicationCode === n, M = p === "all" || t.moduleCode === p;
    return r && i && v && M;
  }), [s, c, d, n, p]), u = m(() => ({
    total: s.length,
    active: s.filter((t) => t.isActive).length,
    inactive: s.filter((t) => !t.isActive).length
  }), [s]);
  return L ? /* @__PURE__ */ e("div", { className: "flex h-96 items-center justify-center", children: /* @__PURE__ */ e(z, { className: "h-8 w-8 animate-spin text-[var(--color-accent-600)]" }) }) : b ? /* @__PURE__ */ e("div", { className: "rounded-lg border border-[var(--error-border)] bg-[var(--error-bg)] p-4", children: /* @__PURE__ */ l("div", { className: "flex items-center gap-2", children: [
    /* @__PURE__ */ e(K, { className: "h-5 w-5 text-[var(--error-text)]" }),
    /* @__PURE__ */ e("p", { className: "text-[var(--error-text)]", children: b })
  ] }) }) : /* @__PURE__ */ l(
    D,
    {
      title: a("externalApps.apis.catalog.title"),
      subtitle: a("externalApps.apis.catalog.description"),
      icon: /* @__PURE__ */ e(q, { className: "w-6 h-6" }),
      breadcrumbs: [
        { label: a("externalApps.navigation.api"), href: "/api" },
        { label: a("externalApps.apis.catalog.title") }
      ],
      children: [
        /* @__PURE__ */ l("div", { className: "grid grid-cols-3 gap-4", children: [
          /* @__PURE__ */ e(
            h,
            {
              title: a("externalApps.apis.catalog.kpi.total"),
              value: u.total,
              icon: /* @__PURE__ */ e(R, { className: "w-5 h-5" }),
              accent: "primary"
            }
          ),
          /* @__PURE__ */ e(
            h,
            {
              title: a("externalApps.apis.catalog.kpi.active"),
              value: u.active,
              icon: /* @__PURE__ */ e(B, { className: "w-5 h-5" }),
              accent: 5
            }
          ),
          /* @__PURE__ */ e(
            h,
            {
              title: a("externalApps.apis.catalog.kpi.inactive"),
              value: u.inactive,
              icon: /* @__PURE__ */ e(O, { className: "w-5 h-5" }),
              accent: 1
            }
          )
        ] }),
        /* @__PURE__ */ l("div", { className: "space-y-4 rounded-[var(--radius-card)] border border-[var(--item-color-border)] bg-[var(--bg-card)] p-4", children: [
          /* @__PURE__ */ l("div", { className: "flex flex-col gap-4 md:flex-row md:items-center", children: [
            /* @__PURE__ */ l("div", { className: "flex-1 relative", children: [
              /* @__PURE__ */ e(X, { className: "absolute left-3 top-1/2 h-5 w-5 -translate-y-1/2 text-[var(--text-tertiary)]" }),
              /* @__PURE__ */ e(
                "input",
                {
                  type: "text",
                  placeholder: a("externalApps.apis.catalog.search"),
                  value: c,
                  onChange: (t) => k(t.target.value),
                  className: "w-full rounded-[var(--radius-input)] border border-[var(--item-color-border)] bg-[var(--bg-secondary)] py-2 pl-10 pr-4 text-[var(--text-primary)] placeholder-[var(--text-tertiary)] focus:border-[var(--color-primary-600)] focus:outline-none"
                }
              )
            ] }),
            /* @__PURE__ */ l(
              "select",
              {
                value: n,
                onChange: (t) => T(t.target.value),
                className: "rounded-[var(--radius-input)] border border-[var(--item-color-border)] bg-[var(--bg-secondary)] px-4 py-2 text-[var(--text-primary)] focus:border-[var(--color-primary-600)] focus:outline-none",
                children: [
                  /* @__PURE__ */ e("option", { value: "all", children: a("externalApps.apis.catalog.columns.application") }),
                  F.map(([t, r]) => /* @__PURE__ */ e("option", { value: t, children: r }, t))
                ]
              }
            ),
            /* @__PURE__ */ l(
              "select",
              {
                value: p,
                onChange: (t) => y(t.target.value),
                className: "rounded-[var(--radius-input)] border border-[var(--item-color-border)] bg-[var(--bg-secondary)] px-4 py-2 text-[var(--text-primary)] focus:border-[var(--color-primary-600)] focus:outline-none",
                children: [
                  /* @__PURE__ */ e("option", { value: "all", children: a("externalApps.apis.catalog.columns.module") }),
                  S.map(([t, r]) => /* @__PURE__ */ e("option", { value: t, children: r }, t))
                ]
              }
            ),
            /* @__PURE__ */ l(
              "select",
              {
                value: d,
                onChange: (t) => E(t.target.value),
                className: "rounded-[var(--radius-input)] border border-[var(--item-color-border)] bg-[var(--bg-secondary)] px-4 py-2 text-[var(--text-primary)] focus:border-[var(--color-primary-600)] focus:outline-none",
                children: [
                  /* @__PURE__ */ e("option", { value: "all", children: a("admin:common.all") }),
                  /* @__PURE__ */ e("option", { value: "active", children: a("externalApps.apis.catalog.active") }),
                  /* @__PURE__ */ e("option", { value: "inactive", children: a("externalApps.apis.catalog.inactive") })
                ]
              }
            )
          ] }),
          /* @__PURE__ */ l("span", { className: "text-sm text-[var(--text-tertiary)]", children: [
            x.length,
            " / ",
            s.length,
            " ",
            a("externalApps.apis.catalog.kpi.total").toLowerCase()
          ] })
        ] }),
        x.length === 0 ? /* @__PURE__ */ e("div", { className: "rounded-[var(--radius-card)] border border-[var(--item-color-border)] bg-[var(--bg-card)] p-12 text-center", children: /* @__PURE__ */ e("p", { className: "text-[var(--text-secondary)]", children: a("externalApps.apis.catalog.noResults") }) }) : /* @__PURE__ */ e("div", { className: "card overflow-hidden", children: /* @__PURE__ */ l("table", { className: "w-full", children: [
          /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ l("tr", { className: "bg-[var(--bg-secondary)]", children: [
            /* @__PURE__ */ e("th", { className: "text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider", children: a("externalApps.apis.catalog.columns.application") }),
            /* @__PURE__ */ e("th", { className: "text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider", children: a("externalApps.apis.catalog.columns.module") }),
            /* @__PURE__ */ e("th", { className: "text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider", children: a("externalApps.apis.catalog.columns.name") }),
            /* @__PURE__ */ e("th", { className: "text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden lg:table-cell", children: a("externalApps.apis.catalog.columns.route") }),
            /* @__PURE__ */ e("th", { className: "text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden lg:table-cell", children: a("externalApps.apis.catalog.columns.entityType") }),
            /* @__PURE__ */ e("th", { className: "text-right px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden lg:table-cell", children: a("externalApps.apis.catalog.columns.rateLimit") }),
            /* @__PURE__ */ e("th", { className: "text-right px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider hidden lg:table-cell", children: a("externalApps.apis.catalog.columns.maxPageSize") }),
            /* @__PURE__ */ e("th", { className: "text-left px-4 py-3 text-xs font-semibold text-[var(--text-tertiary)] uppercase tracking-wider", children: a("externalApps.apis.catalog.columns.status") })
          ] }) }),
          /* @__PURE__ */ e("tbody", { className: "divide-y divide-[var(--border-color)]", children: x.map((t) => /* @__PURE__ */ l("tr", { className: "hover:bg-[var(--bg-hover)] transition-colors cursor-pointer", onClick: () => A(`/api/accounts/catalog/${t.code}`), children: [
            /* @__PURE__ */ e("td", { className: "px-4 py-3", children: /* @__PURE__ */ e("span", { className: "inline-flex items-center gap-1.5 rounded-full bg-[var(--info-bg)] px-2.5 py-0.5 text-xs font-medium text-[var(--info-text)]", children: t.applicationLabel }) }),
            /* @__PURE__ */ e("td", { className: "px-4 py-3", children: /* @__PURE__ */ e("span", { className: "text-sm text-[var(--text-primary)]", children: t.moduleLabel }) }),
            /* @__PURE__ */ e("td", { className: "px-4 py-3", children: /* @__PURE__ */ l("div", { className: "flex items-center gap-3", children: [
              /* @__PURE__ */ e($, { className: "h-4 w-4 text-[var(--color-accent-600)] flex-shrink-0" }),
              /* @__PURE__ */ l("div", { children: [
                /* @__PURE__ */ e("p", { className: "font-medium text-[var(--text-primary)]", children: t.name }),
                t.description && /* @__PURE__ */ e("p", { className: "mt-0.5 text-xs text-[var(--text-tertiary)] line-clamp-1", children: t.description })
              ] })
            ] }) }),
            /* @__PURE__ */ e("td", { className: "px-4 py-3 text-sm text-[var(--text-secondary)] font-mono hidden lg:table-cell", children: t.routeTemplate }),
            /* @__PURE__ */ e("td", { className: "px-4 py-3 text-sm text-[var(--text-secondary)] hidden lg:table-cell", children: t.entityType }),
            /* @__PURE__ */ l("td", { className: "px-4 py-3 text-sm text-right text-[var(--text-secondary)] hidden lg:table-cell", children: [
              t.defaultRateLimitPerMinute,
              "/min"
            ] }),
            /* @__PURE__ */ e("td", { className: "px-4 py-3 text-sm text-right text-[var(--text-secondary)] hidden lg:table-cell", children: t.defaultMaxPageSize }),
            /* @__PURE__ */ e("td", { className: "px-4 py-3", children: /* @__PURE__ */ e("div", { className: "inline-flex items-center gap-2 rounded-full px-2.5 py-0.5 text-xs font-medium", children: t.isActive ? /* @__PURE__ */ l(N, { children: [
              /* @__PURE__ */ e("div", { className: "h-2 w-2 rounded-full bg-[var(--success-text)]" }),
              /* @__PURE__ */ e("span", { className: "text-[var(--success-text)]", children: a("externalApps.apis.catalog.active") })
            ] }) : /* @__PURE__ */ l(N, { children: [
              /* @__PURE__ */ e("div", { className: "h-2 w-2 rounded-full bg-[var(--warning-text)]" }),
              /* @__PURE__ */ e("span", { className: "text-[var(--warning-text)]", children: a("externalApps.apis.catalog.inactive") })
            ] }) }) })
          ] }, t.id)) })
        ] }) })
      ]
    }
  );
}
export {
  W as ApiCatalogPage
};
//# sourceMappingURL=ApiCatalogPage-D2BgeKYk.js.map
