import { jsxs as r, jsx as e } from "react/jsx-runtime";
import { useState as o, useEffect as N, useMemo as y } from "react";
import { Link as m } from "react-router-dom";
import { useTranslation as u } from "react-i18next";
import { BarChart3 as p, AlertCircle as w, FileText as C, ArrowRight as x, Clock as k } from "lucide-react";
import { b as A } from "./businessAnalysisApi-hLIodI9W.js";
function g({ status: i }) {
  const { t: d } = u("ba"), n = {
    draft: "bg-gray-100 text-gray-700 dark:bg-gray-800 dark:text-gray-300",
    analysed: "bg-blue-100 text-blue-700 dark:bg-blue-900 dark:text-blue-300",
    specified: "bg-indigo-100 text-indigo-700 dark:bg-indigo-900 dark:text-indigo-300",
    consolidated: "bg-purple-100 text-purple-700 dark:bg-purple-900 dark:text-purple-300",
    "handed-off": "bg-green-100 text-green-700 dark:bg-green-900 dark:text-green-300"
  };
  return /* @__PURE__ */ e("span", { className: `px-2 py-0.5 rounded-full text-xs font-medium ${n[i] || n.draft}`, children: d(`status.${i}`, i) });
}
function B() {
  const { t: i } = u("ba"), [d, n] = o(null), [h, f] = o(!0), [b, v] = o(null);
  N(() => {
    A.getManifest().then(n).catch(() => v("manifest")).finally(() => f(!1)).catch(() => {
    });
  }, []);
  const c = y(() => {
    if (!d?.analyses) return [];
    const a = /* @__PURE__ */ new Map();
    for (const t of d.analyses) {
      const l = a.get(t.appCode);
      l ? (l.entries.push(t), t.updatedAt > l.latestUpdate && (l.latestUpdate = t.updatedAt)) : a.set(t.appCode, {
        appCode: t.appCode,
        appName: t.appName,
        entries: [t],
        latestUpdate: t.updatedAt
      });
    }
    return Array.from(a.values()).sort((t, l) => l.latestUpdate.localeCompare(t.latestUpdate));
  }, [d]);
  return h ? /* @__PURE__ */ r("div", { className: "space-y-4 animate-pulse", children: [
    /* @__PURE__ */ e("div", { className: "h-8 bg-[var(--bg-tertiary)] rounded w-64" }),
    /* @__PURE__ */ e("div", { className: "h-4 bg-[var(--bg-tertiary)] rounded w-96" }),
    /* @__PURE__ */ e("div", { className: "grid grid-cols-1 lg:grid-cols-2 gap-6 mt-8", children: [1, 2].map((a) => /* @__PURE__ */ e("div", { className: "h-48 bg-[var(--bg-tertiary)] rounded-xl" }, `card-${a}`)) })
  ] }) : /* @__PURE__ */ r("div", { className: "space-y-8", children: [
    /* @__PURE__ */ r("div", { children: [
      /* @__PURE__ */ r("h1", { className: "text-3xl font-bold mb-4 flex items-center gap-3", children: [
        /* @__PURE__ */ e(p, { className: "w-8 h-8 text-[var(--color-primary-600)]" }),
        i("index.title")
      ] }),
      /* @__PURE__ */ e("p", { className: "text-lg text-[var(--text-secondary)]", children: i("index.subtitle") })
    ] }),
    b || c.length === 0 ? /* @__PURE__ */ r("div", { className: "text-center py-16", children: [
      /* @__PURE__ */ e(w, { className: "w-12 h-12 text-[var(--text-tertiary)] mx-auto mb-4" }),
      /* @__PURE__ */ e("p", { className: "text-lg text-[var(--text-secondary)] mb-2", children: i("index.noData") }),
      /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-tertiary)]", children: i("index.noDataHint") })
    ] }) : /* @__PURE__ */ e("div", { className: "grid grid-cols-1 lg:grid-cols-2 gap-6", children: c.map((a) => {
      const t = a.entries.find((s) => !s.moduleCode), l = a.entries.filter((s) => s.moduleCode);
      return /* @__PURE__ */ r("div", { className: "card p-6 hover:shadow-lg transition-shadow", children: [
        /* @__PURE__ */ r("div", { className: "flex items-start gap-4 mb-4", children: [
          /* @__PURE__ */ e("div", { className: "w-12 h-12 rounded-xl bg-gradient-to-br from-violet-500 to-purple-600 flex items-center justify-center", children: /* @__PURE__ */ e(p, { className: "w-6 h-6 text-white" }) }),
          /* @__PURE__ */ r("div", { className: "flex-1 min-w-0", children: [
            /* @__PURE__ */ e("h3", { className: "text-lg font-semibold text-[var(--text-primary)] truncate", children: a.appName }),
            /* @__PURE__ */ e("p", { className: "text-sm text-[var(--text-secondary)]", children: t?.featureDescription })
          ] }),
          t && /* @__PURE__ */ e(g, { status: t.status })
        ] }),
        l.length > 0 && /* @__PURE__ */ e("div", { className: "space-y-2 mb-4", children: l.map((s) => /* @__PURE__ */ r(
          m,
          {
            to: `/system/docs/ba/${s.appCode}/${s.moduleCode}`,
            className: "flex items-center gap-2 px-3 py-2 rounded-lg hover:bg-[var(--bg-hover)] transition-colors group",
            children: [
              /* @__PURE__ */ e(C, { className: "w-4 h-4 text-[var(--text-tertiary)]" }),
              /* @__PURE__ */ e("span", { className: "text-sm text-[var(--text-primary)] flex-1", children: s.moduleName || s.moduleCode }),
              /* @__PURE__ */ e(g, { status: s.status }),
              /* @__PURE__ */ e(x, { className: "w-3 h-3 text-[var(--text-tertiary)] opacity-0 group-hover:opacity-100 transition-opacity" })
            ]
          },
          `${s.appCode}-${s.moduleCode}`
        )) }),
        /* @__PURE__ */ r("div", { className: "flex items-center justify-between pt-3 border-t border-[var(--border-color)]", children: [
          /* @__PURE__ */ r("div", { className: "flex items-center gap-2 text-xs text-[var(--text-tertiary)]", children: [
            /* @__PURE__ */ e(k, { className: "w-3 h-3" }),
            new Date(a.latestUpdate).toLocaleDateString()
          ] }),
          t && /* @__PURE__ */ r(
            m,
            {
              to: `/system/docs/ba/${a.appCode}`,
              className: "text-sm text-[var(--color-primary-600)] hover:underline flex items-center gap-1",
              children: [
                i("index.version"),
                " ",
                t.version,
                /* @__PURE__ */ e(x, { className: "w-3 h-3" })
              ]
            }
          )
        ] })
      ] }, a.appCode);
    }) })
  ] });
}
export {
  B as BaIndexPage
};
//# sourceMappingURL=BaIndexPage-B5scAEin.js.map
