import { jsx as e, jsxs as r, Fragment as N } from "react/jsx-runtime";
import { useState as n, useEffect as A, useMemo as x } from "react";
import { useTranslation as P } from "react-i18next";
import { useNavigate as $ } from "react-router-dom";
import { Loader2 as j, AlertTriangle as B, Search as z, BookOpen as R } from "lucide-react";
import { B as O, k as q } from "./index-CwSaRXXg.js";
const h = {
  blue: "bg-[var(--info-bg)] text-[var(--info-text)] border-[var(--info-border)]",
  green: "bg-[var(--success-bg)] text-[var(--success-text)] border-[var(--success-border)]",
  neutral: "bg-[var(--bg-secondary)] text-[var(--text-primary)] border-[var(--border-color)]"
};
function Q() {
  const { t: a } = P("admin"), w = $(), [s, C] = n([]), [L, g] = n(!0), [b, f] = n(null), [c, k] = n(""), [d, E] = n("all"), [o, F] = n("all"), [p, y] = n("all");
  A(() => {
    (async () => {
      try {
        g(!0);
        const l = await q.externalApps.getApiEndpoints();
        C(l), f(null);
      } catch (l) {
        f(l instanceof Error ? l.message : "Failed to load endpoints");
      } finally {
        g(!1);
      }
    })();
  }, []);
  const S = x(() => {
    const t = /* @__PURE__ */ new Map();
    return s.forEach((l) => t.set(l.applicationCode, l.applicationLabel)), [...t.entries()].sort((l, i) => l[1].localeCompare(i[1]));
  }, [s]), T = x(() => {
    const t = o === "all" ? s : s.filter((i) => i.applicationCode === o), l = /* @__PURE__ */ new Map();
    return t.forEach((i) => l.set(i.moduleCode, i.moduleLabel)), [...l.entries()].sort((i, u) => i[1].localeCompare(u[1]));
  }, [s, o]);
  A(() => {
    y("all");
  }, [o]);
  const m = x(() => s.filter((t) => {
    const l = !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, u = o === "all" || t.applicationCode === o, M = p === "all" || t.moduleCode === p;
    return l && i && u && M;
  }), [s, c, d, o, p]), v = x(() => ({
    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(j, { className: "h-8 w-8 animate-spin text-[var(--color-primary-600)]" }) }) : b ? /* @__PURE__ */ e("div", { className: "rounded-lg border border-[var(--error-border)] bg-[var(--error-bg)] p-4", children: /* @__PURE__ */ r("div", { className: "flex items-center gap-2", children: [
    /* @__PURE__ */ e(B, { className: "h-5 w-5 text-[var(--error-text)]" }),
    /* @__PURE__ */ e("p", { className: "text-[var(--error-text)]", children: b })
  ] }) }) : /* @__PURE__ */ r("div", { className: "space-y-6", children: [
    /* @__PURE__ */ e(
      O,
      {
        items: [
          { label: a("externalApps.navigation.api"), href: "/api" },
          { label: a("externalApps.apis.catalog.title") }
        ]
      }
    ),
    /* @__PURE__ */ r("div", { children: [
      /* @__PURE__ */ e("h1", { className: "text-3xl font-bold text-[var(--text-primary)]", children: a("externalApps.apis.catalog.title") }),
      /* @__PURE__ */ e("p", { className: "mt-2 text-[var(--text-secondary)]", children: a("externalApps.apis.catalog.description") })
    ] }),
    /* @__PURE__ */ r("div", { className: "grid grid-cols-3 gap-4", children: [
      /* @__PURE__ */ r("div", { className: `card p-4 text-center border ${h.blue}`, children: [
        /* @__PURE__ */ e("div", { className: "text-2xl font-bold", children: v.total }),
        /* @__PURE__ */ e("div", { className: "text-sm opacity-80", children: a("externalApps.apis.catalog.kpi.total") })
      ] }),
      /* @__PURE__ */ r("div", { className: `card p-4 text-center border ${h.green}`, children: [
        /* @__PURE__ */ e("div", { className: "text-2xl font-bold", children: v.active }),
        /* @__PURE__ */ e("div", { className: "text-sm opacity-80", children: a("externalApps.apis.catalog.kpi.active") })
      ] }),
      /* @__PURE__ */ r("div", { className: `card p-4 text-center border ${h.neutral}`, children: [
        /* @__PURE__ */ e("div", { className: "text-2xl font-bold", children: v.inactive }),
        /* @__PURE__ */ e("div", { className: "text-sm opacity-80", children: a("externalApps.apis.catalog.kpi.inactive") })
      ] })
    ] }),
    /* @__PURE__ */ r("div", { className: "space-y-4 rounded-[var(--radius-card)] border border-[var(--item-color-border)] bg-[var(--bg-card)] p-4", children: [
      /* @__PURE__ */ r("div", { className: "flex flex-col gap-4 md:flex-row md:items-center", children: [
        /* @__PURE__ */ r("div", { className: "flex-1 relative", children: [
          /* @__PURE__ */ e(z, { 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__ */ r(
          "select",
          {
            value: o,
            onChange: (t) => F(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") }),
              S.map(([t, l]) => /* @__PURE__ */ e("option", { value: t, children: l }, t))
            ]
          }
        ),
        /* @__PURE__ */ r(
          "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") }),
              T.map(([t, l]) => /* @__PURE__ */ e("option", { value: t, children: l }, t))
            ]
          }
        ),
        /* @__PURE__ */ r(
          "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__ */ r("span", { className: "text-sm text-[var(--text-tertiary)]", children: [
        m.length,
        " / ",
        s.length,
        " ",
        a("externalApps.apis.catalog.kpi.total").toLowerCase()
      ] })
    ] }),
    m.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__ */ r("table", { className: "w-full", children: [
      /* @__PURE__ */ e("thead", { children: /* @__PURE__ */ r("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: m.map((t) => /* @__PURE__ */ r("tr", { className: "hover:bg-[var(--bg-hover)] transition-colors cursor-pointer", onClick: () => w(`/api/apis/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__ */ r("div", { className: "flex items-center gap-3", children: [
          /* @__PURE__ */ e(R, { className: "h-4 w-4 text-[var(--color-accent-600)] flex-shrink-0" }),
          /* @__PURE__ */ r("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__ */ r("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__ */ r(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__ */ r(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 {
  Q as ApiCatalogPage
};
//# sourceMappingURL=ApiCatalogPage-BEqTDJz8.js.map
