import { jsx as a, jsxs as o, Fragment as _ } from "react/jsx-runtime";
import { useMemo as p, useState as b, useCallback as ua, useEffect as va } from "react";
import { useNavigate as ga } from "react-router-dom";
import { useTranslation as f } from "react-i18next";
import * as pa from "lucide-react";
import { LineChart as ya, AlertTriangle as S, MapPin as Q, Globe as I, Monitor as k, Clock as Z, CalendarDays as xa, LayoutGrid as ba, Loader2 as q, Star as E, Building2 as fa, Settings as Na, Activity as wa, TrendingUp as Ca, BarChart3 as Sa, LayoutDashboard as ka } from "lucide-react";
import { q as N, L as V, av as Da, aK as $a, x as Aa, a as Ma, u as La, aL as Ea, i as Ia, P as Ua, K as L } from "./index-CeEMms9z.js";
import { ResponsiveContainer as $, LineChart as Ha, CartesianGrid as U, XAxis as H, YAxis as D, Tooltip as R, Line as X, BarChart as aa, ReferenceLine as Ra, Bar as ea, Cell as ta, PieChart as za, Pie as Ta } from "recharts";
import { C as A, a as ra } from "./ChartLegend-BdZxV6Ho.js";
import { C as z, a as T, P as Y } from "./chartConstants-Ds00dPgh.js";
import { c as Pa } from "./renderActiveShape-Cwe7yij0.js";
function Ka({
  data: e,
  title: t,
  subtitle: i,
  connectionsLabel: n,
  avgDurationLabel: r,
  minutesSuffix: u
}) {
  const { t: m, i18n: g } = f("common"), d = p(() => N(0), []), l = p(() => N(1), []), y = !e || e.length === 0, c = p(
    () => (e ?? []).map((v) => ({
      date: new Date(v.date).toLocaleDateString(g.language, { day: "2-digit", month: "2-digit" }),
      [n]: v.loginCount,
      [r]: Math.round(v.avgDuration)
    })),
    [e, g.language, n, r]
  ), s = [
    { id: "connections", label: n, color: d },
    { id: "avgDuration", label: r, color: l }
  ];
  return /* @__PURE__ */ a(
    A,
    {
      title: t,
      subtitle: i,
      icon: /* @__PURE__ */ a(ya, { className: "w-5 h-5" }),
      height: "md",
      empty: y,
      emptyMessage: m("dashboard.noChartData"),
      emptyHint: m("dashboard.noDataHint"),
      footer: !y && /* @__PURE__ */ a(ra, { items: s, ariaLabel: t }),
      children: /* @__PURE__ */ a($, { width: "100%", height: "100%", children: /* @__PURE__ */ o(Ha, { data: c, margin: z, children: [
        /* @__PURE__ */ a(U, { strokeDasharray: "3 3", stroke: "var(--border-color)" }),
        /* @__PURE__ */ a(
          H,
          {
            dataKey: "date",
            stroke: "var(--text-secondary)",
            tick: { fill: "var(--text-secondary)", fontSize: 12 }
          }
        ),
        /* @__PURE__ */ a(
          D,
          {
            yAxisId: "left",
            stroke: d,
            tick: { fill: "var(--text-secondary)", fontSize: 12 },
            label: {
              value: n,
              angle: -90,
              position: "insideLeft",
              fill: "var(--text-secondary)"
            }
          }
        ),
        /* @__PURE__ */ a(
          D,
          {
            yAxisId: "right",
            orientation: "right",
            stroke: l,
            tick: { fill: "var(--text-secondary)", fontSize: 12 },
            label: {
              value: r,
              angle: 90,
              position: "insideRight",
              fill: "var(--text-secondary)"
            }
          }
        ),
        /* @__PURE__ */ a(
          R,
          {
            content: /* @__PURE__ */ a(
              T,
              {
                valueFormatter: (v, x) => x === r ? `${v} ${u}` : String(v)
              }
            )
          }
        ),
        /* @__PURE__ */ a(
          X,
          {
            yAxisId: "left",
            type: "monotone",
            dataKey: n,
            stroke: d,
            strokeWidth: 2,
            dot: { fill: d, r: 4 },
            activeDot: { r: 6 }
          }
        ),
        /* @__PURE__ */ a(
          X,
          {
            yAxisId: "right",
            type: "monotone",
            dataKey: r,
            stroke: l,
            strokeWidth: 2,
            dot: { fill: l, r: 4 },
            activeDot: { r: 6 }
          }
        )
      ] }) })
    }
  );
}
function ja({ errors: e }) {
  const { t } = f("navigation");
  if (!Array.isArray(e) || e.length === 0)
    return /* @__PURE__ */ o("div", { className: "flex flex-col items-center justify-center py-8 text-[var(--text-secondary)]", children: [
      /* @__PURE__ */ a(
        S,
        {
          className: "w-12 h-12 mb-3",
          style: { color: "var(--success-text)" },
          "aria-hidden": "true"
        }
      ),
      /* @__PURE__ */ a("p", { className: "font-medium", children: t("dashboard.loginErrors.noErrors") }),
      /* @__PURE__ */ a("p", { className: "text-sm mt-1", children: t("dashboard.loginErrors.accountSecure") })
    ] });
  const i = (n) => {
    const r = new Date(n);
    return ((/* @__PURE__ */ new Date()).getTime() - r.getTime()) / (1e3 * 60 * 60) < 24;
  };
  return /* @__PURE__ */ a("div", { className: "overflow-x-auto", children: /* @__PURE__ */ o("table", { className: "w-full", children: [
    /* @__PURE__ */ a("thead", { children: /* @__PURE__ */ o("tr", { className: "border-b border-[var(--border-color)]", children: [
      /* @__PURE__ */ a("th", { className: "text-left p-3 font-medium text-[var(--text-secondary)] text-sm", children: t("dashboard.loginErrors.columns.datetime") }),
      /* @__PURE__ */ a("th", { className: "text-left p-3 font-medium text-[var(--text-secondary)] text-sm", children: t("dashboard.loginErrors.columns.reason") }),
      /* @__PURE__ */ a("th", { className: "text-left p-3 font-medium text-[var(--text-secondary)] text-sm", children: t("dashboard.loginErrors.columns.ipAddress") }),
      /* @__PURE__ */ a("th", { className: "text-left p-3 font-medium text-[var(--text-secondary)] text-sm", children: t("dashboard.loginErrors.columns.location") })
    ] }) }),
    /* @__PURE__ */ a("tbody", { children: e.map((n) => {
      const r = i(n.loginAt);
      return /* @__PURE__ */ o(
        "tr",
        {
          className: "border-b border-[var(--border-color)] hover:bg-[var(--bg-secondary)]",
          style: r ? { backgroundColor: "var(--error-bg)" } : void 0,
          children: [
            /* @__PURE__ */ a("td", { className: "p-3", children: /* @__PURE__ */ o("div", { className: "flex items-center gap-2", children: [
              r && /* @__PURE__ */ a(
                "span",
                {
                  className: "w-2 h-2 rounded-full animate-pulse",
                  style: { backgroundColor: "var(--error-dot)" },
                  title: t("dashboard.loginErrors.recentLabel")
                }
              ),
              /* @__PURE__ */ a("span", { className: "text-sm", children: new Date(n.loginAt).toLocaleDateString("fr-FR", {
                day: "2-digit",
                month: "2-digit",
                year: "numeric",
                hour: "2-digit",
                minute: "2-digit"
              }) })
            ] }) }),
            /* @__PURE__ */ a("td", { className: "p-3", children: /* @__PURE__ */ o(
              "span",
              {
                className: "inline-flex items-center gap-1 px-2 py-1 text-xs font-medium rounded-[var(--radius-badge)] border",
                style: {
                  backgroundColor: "var(--error-bg)",
                  color: "var(--error-text)",
                  borderColor: "var(--error-border)"
                },
                children: [
                  /* @__PURE__ */ a(S, { className: "w-3 h-3", "aria-hidden": "true" }),
                  n.failureReason
                ]
              }
            ) }),
            /* @__PURE__ */ a("td", { className: "p-3", children: /* @__PURE__ */ a("span", { className: "text-sm font-mono text-[var(--text-secondary)]", children: n.ipAddress || "N/A" }) }),
            /* @__PURE__ */ a("td", { className: "p-3", children: n.city || n.country ? /* @__PURE__ */ o("div", { className: "flex items-center gap-1 text-sm text-[var(--text-secondary)]", children: [
              n.city && /* @__PURE__ */ o(_, { children: [
                /* @__PURE__ */ a(Q, { className: "w-3 h-3" }),
                /* @__PURE__ */ a("span", { children: n.city })
              ] }),
              n.country && /* @__PURE__ */ o(_, { children: [
                /* @__PURE__ */ a(I, { className: "w-3 h-3" }),
                /* @__PURE__ */ a("span", { children: n.country })
              ] })
            ] }) : /* @__PURE__ */ a("span", { className: "text-sm text-[var(--text-tertiary)]", children: t("dashboard.loginErrors.notAvailable") }) })
          ]
        },
        n.loginAt
      );
    }) })
  ] }) });
}
function Fa({ session: e }) {
  const { t } = f("navigation");
  if (!e)
    return /* @__PURE__ */ o("div", { className: "flex flex-col items-center justify-center py-8 text-[var(--text-secondary)]", children: [
      /* @__PURE__ */ a(k, { className: "w-12 h-12 mb-3 opacity-50" }),
      /* @__PURE__ */ a("p", { className: "font-medium", children: t("dashboard.currentSession.noActiveSession") }),
      /* @__PURE__ */ a("p", { className: "text-sm mt-1", children: t("dashboard.currentSession.pleaseReconnect") })
    ] });
  const i = (r) => {
    if (r < 1) return "< 1 minute";
    if (r < 60) return `${Math.round(r)} minutes`;
    const u = Math.floor(r / 60), m = Math.round(r % 60);
    return m === 0 ? `${u}h` : `${u}h ${m}min`;
  }, n = (r) => r ? r.includes("Edg/") ? t("dashboard.browsers.edge") : r.includes("Chrome/") ? t("dashboard.browsers.chrome") : r.includes("Firefox/") ? t("dashboard.browsers.firefox") : r.includes("Safari/") && !r.includes("Chrome") ? t("dashboard.browsers.safari") : r.includes("OPR/") || r.includes("Opera/") ? t("dashboard.browsers.opera") : t("dashboard.browsers.other") : t("dashboard.browsers.unknown");
  return /* @__PURE__ */ o("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-4", children: [
    /* @__PURE__ */ o("div", { className: "flex items-start gap-3 p-4 bg-[var(--bg-secondary)] rounded-[var(--radius-card)]", children: [
      /* @__PURE__ */ a(
        "div",
        {
          className: "p-2 rounded-[var(--radius-button)]",
          style: {
            backgroundColor: "var(--dataviz-surface-elevated)",
            color: "var(--dataviz-accent)"
          },
          children: /* @__PURE__ */ a(Z, { className: "w-5 h-5" })
        }
      ),
      /* @__PURE__ */ o("div", { className: "flex-1", children: [
        /* @__PURE__ */ a("p", { className: "text-xs text-[var(--text-tertiary)] uppercase tracking-wide", children: t("dashboard.currentSession.duration") }),
        /* @__PURE__ */ a("p", { className: "text-lg font-bold text-[var(--text-primary)] mt-1", children: i(e.durationMinutes) }),
        /* @__PURE__ */ o("p", { className: "text-xs text-[var(--text-secondary)] mt-1", children: [
          t("dashboard.currentSession.since"),
          " ",
          new Date(e.loginAt).toLocaleTimeString("fr-FR", { hour: "2-digit", minute: "2-digit" })
        ] })
      ] })
    ] }),
    /* @__PURE__ */ o("div", { className: "flex items-start gap-3 p-4 bg-[var(--bg-secondary)] rounded-[var(--radius-card)]", children: [
      /* @__PURE__ */ a(
        "div",
        {
          className: "p-2 rounded-[var(--radius-button)]",
          style: {
            backgroundColor: "var(--dataviz-surface-elevated)",
            color: "var(--dataviz-cat-2)"
          },
          children: /* @__PURE__ */ a(k, { className: "w-5 h-5" })
        }
      ),
      /* @__PURE__ */ o("div", { className: "flex-1", children: [
        /* @__PURE__ */ a("p", { className: "text-xs text-[var(--text-tertiary)] uppercase tracking-wide", children: t("dashboard.currentSession.device") }),
        /* @__PURE__ */ a("p", { className: "text-lg font-bold text-[var(--text-primary)] mt-1", children: n(e.userAgent) }),
        /* @__PURE__ */ a("p", { className: "text-xs text-[var(--text-secondary)] mt-1 font-mono", children: e.ipAddress || t("dashboard.currentSession.ipNotAvailable") })
      ] })
    ] }),
    (e.city || e.country) && /* @__PURE__ */ o("div", { className: "md:col-span-2 flex items-start gap-3 p-4 bg-[var(--bg-secondary)] rounded-[var(--radius-card)]", children: [
      /* @__PURE__ */ a(
        "div",
        {
          className: "p-2 rounded-[var(--radius-button)]",
          style: {
            backgroundColor: "var(--dataviz-surface-elevated)",
            color: "var(--dataviz-cat-6)"
          },
          children: /* @__PURE__ */ a(I, { className: "w-5 h-5" })
        }
      ),
      /* @__PURE__ */ o("div", { className: "flex-1", children: [
        /* @__PURE__ */ a("p", { className: "text-xs text-[var(--text-tertiary)] uppercase tracking-wide", children: t("dashboard.currentSession.location") }),
        /* @__PURE__ */ o("div", { className: "flex items-center gap-3 mt-1", children: [
          e.city && /* @__PURE__ */ o("div", { className: "flex items-center gap-1", children: [
            /* @__PURE__ */ a(Q, { className: "w-4 h-4 text-[var(--text-secondary)]" }),
            /* @__PURE__ */ a("span", { className: "text-sm font-medium text-[var(--text-primary)]", children: e.city })
          ] }),
          e.country && /* @__PURE__ */ a("span", { className: "text-sm text-[var(--text-secondary)]", children: e.country })
        ] })
      ] })
    ] })
  ] });
}
function Ba({ stats: e }) {
  const { t } = f("navigation"), i = p(() => V(5), []), n = p(() => V(5), []);
  return e ? /* @__PURE__ */ o("div", { className: "grid grid-cols-1 md:grid-cols-2 gap-6", children: [
    /* @__PURE__ */ o("div", { children: [
      /* @__PURE__ */ o("h4", { className: "text-sm font-medium text-[var(--text-secondary)] mb-3 flex items-center gap-2", children: [
        /* @__PURE__ */ a(k, { className: "w-4 h-4" }),
        t("dashboard.deviceStats.browsersUsed")
      ] }),
      e.byBrowser?.length ? /* @__PURE__ */ a("div", { className: "space-y-3", children: e.byBrowser.map((r, u) => {
        const m = Math.max(...e.byBrowser.map((d) => d.count), 1), g = r.count / m * 100;
        return /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
          /* @__PURE__ */ a("div", { className: "w-24 text-sm text-[var(--text-primary)] truncate", title: r.browser, children: r.browser }),
          /* @__PURE__ */ a("div", { className: "flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden", children: /* @__PURE__ */ a(
            "div",
            {
              className: "h-full rounded-full transition-all duration-500",
              style: {
                width: `${g}%`,
                backgroundColor: i[u % i.length]
              }
            }
          ) }),
          /* @__PURE__ */ a("div", { className: "w-12 text-right font-medium text-[var(--text-primary)]", children: r.count })
        ] }, r.browser);
      }) }) : /* @__PURE__ */ a("p", { className: "text-sm text-[var(--text-secondary)]", children: t("dashboard.deviceStats.noData") })
    ] }),
    /* @__PURE__ */ o("div", { children: [
      /* @__PURE__ */ o("h4", { className: "text-sm font-medium text-[var(--text-secondary)] mb-3 flex items-center gap-2", children: [
        /* @__PURE__ */ a(I, { className: "w-4 h-4" }),
        t("dashboard.deviceStats.connectionCountries")
      ] }),
      e.byCountry?.length ? /* @__PURE__ */ a("div", { className: "space-y-3", children: e.byCountry.map((r, u) => {
        const m = Math.max(...e.byCountry.map((d) => d.count), 1), g = r.count / m * 100;
        return /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
          /* @__PURE__ */ a("div", { className: "w-24 text-sm text-[var(--text-primary)] truncate", title: r.country, children: r.country }),
          /* @__PURE__ */ a("div", { className: "flex-1 h-6 bg-[var(--bg-secondary)] rounded-full overflow-hidden", children: /* @__PURE__ */ a(
            "div",
            {
              className: "h-full rounded-full transition-all duration-500",
              style: {
                width: `${g}%`,
                backgroundColor: n[u % n.length]
              }
            }
          ) }),
          /* @__PURE__ */ a("div", { className: "w-12 text-right font-medium text-[var(--text-primary)]", children: r.count })
        ] }, r.country);
      }) }) : /* @__PURE__ */ a("p", { className: "text-sm text-[var(--text-secondary)]", children: t("dashboard.deviceStats.locationNotAvailable") })
    ] })
  ] }) : /* @__PURE__ */ a("div", { className: "flex items-center justify-center py-8 text-[var(--text-secondary)]", children: /* @__PURE__ */ a("p", { children: t("dashboard.deviceStats.noData") }) });
}
function J(e) {
  if (e < 60) return `${e} min`;
  const t = Math.floor(e / 60), i = e % 60;
  return i > 0 ? `${t}h ${i}m` : `${t}h`;
}
function Ga({
  data: e,
  title: t,
  subtitle: i,
  yAxisLabel: n,
  averageLabel: r,
  dayLabels: u
}) {
  const { t: m } = f("common"), g = p(() => N(0), []), d = p(() => Da("neutral"), []), l = !e?.dayStats?.length, y = p(
    () => (e?.dayStats ?? []).map((s) => ({
      day: u[s.dayName.toLowerCase()] ?? s.dayName,
      duration: s.sessionCount > 0 ? Math.round(s.totalDuration / s.sessionCount) : 0,
      sessionCount: s.sessionCount
    })),
    [e?.dayStats, u]
  ), c = p(() => {
    const s = y.filter((v) => v.sessionCount > 0);
    return s.length === 0 ? 0 : s.reduce((v, x) => v + x.duration, 0) / s.length;
  }, [y]);
  return /* @__PURE__ */ a(
    A,
    {
      title: t,
      subtitle: i,
      icon: /* @__PURE__ */ a(xa, { className: "w-5 h-5" }),
      height: "md",
      empty: l,
      emptyMessage: m("dashboard.noChartData"),
      emptyHint: m("dashboard.noDataHint"),
      children: /* @__PURE__ */ a($, { width: "100%", height: "100%", children: /* @__PURE__ */ o(aa, { data: y, margin: z, children: [
        /* @__PURE__ */ a(U, { strokeDasharray: "3 3", stroke: "var(--border-color)" }),
        /* @__PURE__ */ a(
          H,
          {
            dataKey: "day",
            stroke: "var(--text-secondary)",
            tick: { fill: "var(--text-secondary)", fontSize: 12 }
          }
        ),
        /* @__PURE__ */ a(
          D,
          {
            stroke: "var(--text-secondary)",
            tick: { fill: "var(--text-secondary)", fontSize: 12 },
            label: {
              value: n,
              angle: -90,
              position: "insideLeft",
              fill: "var(--text-secondary)"
            }
          }
        ),
        /* @__PURE__ */ a(
          R,
          {
            cursor: { fill: "transparent" },
            content: /* @__PURE__ */ a(
              T,
              {
                valueFormatter: (s) => typeof s == "number" ? J(s) : String(s)
              }
            )
          }
        ),
        /* @__PURE__ */ a(
          Ra,
          {
            y: c,
            stroke: d,
            strokeDasharray: "5 5",
            label: {
              value: `${r}: ${J(Math.round(c))}`,
              position: "right",
              fill: d,
              fontSize: 11
            }
          }
        ),
        /* @__PURE__ */ a(ea, { dataKey: "duration", fill: g, radius: [4, 4, 0, 0] })
      ] }) })
    }
  );
}
function Oa(e) {
  return `${e.toString().padStart(2, "0")}:00`;
}
function Wa(e) {
  if (e < 60) return `${e} min`;
  const t = Math.floor(e / 60), i = e % 60;
  return i > 0 ? `${t}h ${i}m` : `${t}h`;
}
function _a({
  data: e,
  title: t,
  subtitle: i,
  yAxisLabel: n
}) {
  const { t: r } = f("common"), u = p(() => $a(), []), m = p(() => N(0), []), g = !e?.hourStats?.length, d = p(
    () => (e?.hourStats ?? []).map((l) => ({
      hour: Oa(l.hour),
      hourNum: l.hour,
      duration: l.sessionCount > 0 ? Math.round(l.totalDuration / l.sessionCount) : 0,
      sessionCount: l.sessionCount,
      isPeak: l.hour === e?.peakHour
    })),
    [e?.hourStats, e?.peakHour]
  );
  return /* @__PURE__ */ a(
    A,
    {
      title: t,
      subtitle: i,
      icon: /* @__PURE__ */ a(Z, { className: "w-5 h-5" }),
      height: "md",
      empty: g,
      emptyMessage: r("dashboard.noChartData"),
      emptyHint: r("dashboard.noDataHint"),
      children: /* @__PURE__ */ a($, { width: "100%", height: "100%", children: /* @__PURE__ */ o(aa, { data: d, margin: z, children: [
        /* @__PURE__ */ a(U, { strokeDasharray: "3 3", stroke: "var(--border-color)" }),
        /* @__PURE__ */ a(
          H,
          {
            dataKey: "hour",
            stroke: "var(--text-secondary)",
            tick: { fill: "var(--text-secondary)", fontSize: 11 },
            interval: 0,
            angle: -45,
            textAnchor: "end",
            height: 60
          }
        ),
        /* @__PURE__ */ a(
          D,
          {
            stroke: "var(--text-secondary)",
            tick: { fill: "var(--text-secondary)", fontSize: 12 },
            label: {
              value: n,
              angle: -90,
              position: "insideLeft",
              fill: "var(--text-secondary)"
            }
          }
        ),
        /* @__PURE__ */ a(
          R,
          {
            cursor: { fill: "transparent" },
            content: /* @__PURE__ */ a(
              T,
              {
                valueFormatter: (l) => typeof l == "number" ? Wa(l) : String(l)
              }
            )
          }
        ),
        /* @__PURE__ */ a(ea, { dataKey: "duration", radius: [4, 4, 0, 0], children: d.map((l, y) => /* @__PURE__ */ a(
          ta,
          {
            fill: l.isPeak ? u : m
          },
          `${l.hour}-${y}`
        )) })
      ] }) })
    }
  );
}
function qa(e) {
  return e < 60 ? `${e}s` : e < 3600 ? `${Math.round(e / 60)}m` : `${Math.round(e / 3600)}h`;
}
function Va({
  data: e,
  title: t,
  subtitle: i,
  accessLabel: n
}) {
  const { t: r } = f("common"), [u, m] = b(0), g = !e?.applications?.length, d = p(
    () => (e?.applications ?? []).map((c, s) => ({
      ...c,
      name: c.applicationName,
      value: c.accessCount,
      fill: N(s)
    })),
    [e?.applications]
  ), l = p(
    () => Pa({
      getLabel: (c) => String(c.applicationName ?? ""),
      getValueText: (c, s) => {
        const v = typeof s.totalDurationSeconds == "number" ? qa(s.totalDurationSeconds) : "", x = `${c.toLocaleString()} ${n}`;
        return v ? `${x} · ${v}` : x;
      }
    }),
    [n]
  ), y = d.map((c) => ({
    id: c.applicationId,
    label: c.applicationName,
    color: c.fill,
    value: `${c.accessCount.toLocaleString()} ${n}`
  }));
  return /* @__PURE__ */ a(
    A,
    {
      title: t,
      subtitle: i,
      icon: /* @__PURE__ */ a(ba, { className: "w-5 h-5" }),
      height: "lg",
      empty: g,
      emptyMessage: r("dashboard.noChartData"),
      emptyHint: r("dashboard.noDataHint"),
      footer: !g && /* @__PURE__ */ a(
        ra,
        {
          items: y,
          activeId: d[u]?.applicationId,
          onHover: (c) => {
            if (!c) return;
            const s = d.findIndex((v) => v.applicationId === c);
            s >= 0 && m(s);
          },
          ariaLabel: t
        }
      ),
      children: /* @__PURE__ */ a($, { width: "100%", height: "100%", children: /* @__PURE__ */ a(za, { children: /* @__PURE__ */ a(
        Ta,
        {
          activeIndex: u,
          activeShape: l,
          data: d,
          cx: "50%",
          cy: "50%",
          innerRadius: Y.inner,
          outerRadius: Y.outer,
          dataKey: "value",
          onMouseEnter: (c, s) => m(s),
          isAnimationActive: !1,
          children: d.map((c) => /* @__PURE__ */ a(ta, { fill: c.fill }, c.applicationId))
        }
      ) }) })
    }
  );
}
function Xa({ name: e, className: t }) {
  const n = pa[e];
  return n ? /* @__PURE__ */ a(n, { className: t }) : /* @__PURE__ */ a(E, { className: t });
}
function se() {
  const { t: e } = f(["navigation", "common"]), t = ga(), { user: i } = Aa(), { currentTenant: n } = Ma(), { menu: r } = La(), { favorites: u, loading: m, triggerExpand: g } = Ea(), [d, l] = b(30), [y, c] = b(!0), [s, v] = b(null), [x, P] = b([]), [oa, K] = b(null), [na, j] = b(null), [sa, F] = b(null), [M, B] = b(null), [ia, G] = b(null), ca = (h) => {
    if (r)
      for (const w of r.applications) {
        const W = w.modules.find((C) => C.id === h.id);
        if (W?.sections?.length) {
          const C = [...W.sections].sort((ha, ma) => ha.displayOrder - ma.displayOrder)[0];
          if (C.route) return C.route;
        }
      }
    return h.route;
  }, da = (h) => {
    const w = ca(h);
    w && (g(), t(w));
  }, la = i?.firstName && i?.lastName ? `${i.firstName} ${i.lastName}` : i?.email || "Utilisateur", O = ua(async () => {
    try {
      c(!0);
      const h = await Ia.dashboard.getAll(d, 10);
      v(h.sessionAnalytics), P(h.loginErrors ?? []), K(h.currentSession), j(h.deviceStats), F(h.weeklyStats), B(h.hourlyStats), G(h.applicationUsage);
    } catch {
      v(null), P([]), K(null), j(null), F(null), B(null), G(null);
    } finally {
      c(!1);
    }
  }, [d]);
  return va(() => {
    O();
  }, [d, O]), y ? /* @__PURE__ */ a("div", { className: "flex items-center justify-center min-h-[400px]", children: /* @__PURE__ */ a(q, { className: "w-8 h-8 animate-spin text-[var(--color-accent-500)]" }) }) : /* @__PURE__ */ o(
    Ua,
    {
      title: `${e("navigation:dashboard.welcome")}, ${la}`,
      subtitle: e("navigation:breadcrumb.myspace"),
      icon: /* @__PURE__ */ a(ka, { className: "w-6 h-6" }),
      children: [
        /* @__PURE__ */ o(
          "div",
          {
            className: "p-6 bg-[var(--bg-card)] border border-[var(--border-color)] rounded-[var(--radius-card)]",
            children: [
              /* @__PURE__ */ o("div", { className: "flex items-center justify-between mb-4", children: [
                /* @__PURE__ */ o("div", { className: "flex items-center gap-3", children: [
                  /* @__PURE__ */ a(E, { className: "w-5 h-5 text-[var(--color-accent-500)]" }),
                  /* @__PURE__ */ a("h2", { className: "font-semibold text-[var(--text-primary)]", children: e("common:favorites.quickAccess") }),
                  n && /* @__PURE__ */ o("span", { className: "flex items-center gap-1.5 text-xs text-[var(--text-tertiary)] px-2 py-1 bg-[var(--bg-secondary)] border border-[var(--border-color)] rounded-[var(--radius-button)]", children: [
                    /* @__PURE__ */ a(fa, { className: "w-3.5 h-3.5" }),
                    n.name
                  ] })
                ] }),
                /* @__PURE__ */ o(
                  "button",
                  {
                    onClick: () => t("/myspace/preferences?tab=favorites"),
                    className: "flex items-center gap-1.5 px-3 py-1.5 text-sm text-[var(--text-secondary)] hover:text-[var(--text-primary)] hover:bg-[var(--bg-hover)] transition-colors rounded-[var(--radius-button)]",
                    children: [
                      /* @__PURE__ */ a(Na, { className: "w-4 h-4" }),
                      e("common:favorites.manage")
                    ]
                  }
                )
              ] }),
              m && /* @__PURE__ */ a("div", { className: "flex items-center justify-center py-8", children: /* @__PURE__ */ a(q, { className: "w-6 h-6 animate-spin text-[var(--color-accent-500)]" }) }),
              !m && u.length === 0 && /* @__PURE__ */ o("div", { className: "text-center py-8", children: [
                /* @__PURE__ */ a(E, { className: "w-12 h-12 mx-auto text-[var(--text-muted)] mb-3" }),
                /* @__PURE__ */ a("p", { className: "text-[var(--text-secondary)] mb-4", children: e("common:favorites.noFavorites") }),
                /* @__PURE__ */ a(
                  "button",
                  {
                    onClick: () => t("/myspace/preferences?tab=favorites"),
                    className: "px-4 py-2 bg-[var(--color-accent-600)] text-white font-medium hover:bg-[var(--color-accent-700)] transition-colors rounded-[var(--radius-button)]",
                    children: e("common:favorites.configureFavorites")
                  }
                )
              ] }),
              !m && u.length > 0 && /* @__PURE__ */ a("div", { className: "grid grid-cols-2 sm:grid-cols-3 md:grid-cols-5 gap-3", children: u.map((h) => /* @__PURE__ */ o(
                "button",
                {
                  onClick: () => da(h),
                  className: "flex flex-col items-center gap-2 p-4 bg-[var(--bg-secondary)] hover:bg-[var(--bg-hover)] border border-[var(--border-color)] hover:border-[var(--color-accent-500)] transition-all group rounded-[var(--radius-card)]",
                  children: [
                    /* @__PURE__ */ a(
                      "div",
                      {
                        className: "w-12 h-12 flex items-center justify-center bg-[var(--color-accent-100)] text-[var(--color-accent-600)] group-hover:bg-[var(--color-accent-600)] group-hover:text-white transition-colors rounded-[var(--radius-button)]",
                        children: /* @__PURE__ */ a(Xa, { name: h.icon, className: "w-6 h-6" })
                      }
                    ),
                    /* @__PURE__ */ a("span", { className: "text-sm font-medium text-[var(--text-primary)] text-center", children: h.label }),
                    /* @__PURE__ */ a("span", { className: "text-xs text-[var(--text-muted)]", children: h.applicationLabel })
                  ]
                },
                h.id
              )) })
            ]
          }
        ),
        /* @__PURE__ */ o("div", { className: "grid grid-cols-1 md:grid-cols-3 gap-4", children: [
          /* @__PURE__ */ a(
            L,
            {
              title: e("navigation:dashboard.stats.totalSessions"),
              value: s?.totalSessions ?? 0,
              icon: /* @__PURE__ */ a(wa, { className: "w-5 h-5" }),
              subtitle: `${d} ${e("navigation:dashboard.stats.lastDays")}`
            }
          ),
          /* @__PURE__ */ a(
            L,
            {
              title: e("navigation:dashboard.stats.avgDuration"),
              value: `${Math.round(s?.avgSessionDuration ?? 0)} min`,
              icon: /* @__PURE__ */ a(Ca, { className: "w-5 h-5" }),
              subtitle: e("navigation:dashboard.stats.perSession")
            }
          ),
          /* @__PURE__ */ a(
            L,
            {
              title: e("navigation:dashboard.stats.connectionErrors"),
              value: (x ?? []).length,
              icon: /* @__PURE__ */ a(S, { className: "w-5 h-5" }),
              subtitle: e("navigation:dashboard.stats.recent"),
              accent: (x ?? []).length > 0 ? void 0 : 5,
              trend: (x ?? []).length > 0 ? { value: `${(x ?? []).length}`, direction: "down" } : void 0
            }
          )
        ] }),
        /* @__PURE__ */ o("div", { className: "grid grid-cols-1 lg:grid-cols-2 gap-6", children: [
          /* @__PURE__ */ a(
            Ga,
            {
              data: sa,
              title: e("navigation:dashboard.weeklyUsage.title"),
              yAxisLabel: e("navigation:dashboard.weeklyUsage.duration"),
              averageLabel: e("navigation:dashboard.weeklyUsage.average"),
              dayLabels: {
                monday: e("navigation:dashboard.days.monday"),
                tuesday: e("navigation:dashboard.days.tuesday"),
                wednesday: e("navigation:dashboard.days.wednesday"),
                thursday: e("navigation:dashboard.days.thursday"),
                friday: e("navigation:dashboard.days.friday"),
                saturday: e("navigation:dashboard.days.saturday"),
                sunday: e("navigation:dashboard.days.sunday")
              }
            }
          ),
          /* @__PURE__ */ a(
            _a,
            {
              data: M,
              title: e("navigation:dashboard.hourlyUsage.title"),
              yAxisLabel: e("navigation:dashboard.hourlyUsage.duration"),
              subtitle: M?.peakHour !== void 0 ? `${e("navigation:dashboard.hourlyUsage.peakHour")}: ${String(M.peakHour).padStart(2, "0")}:00` : void 0
            }
          )
        ] }),
        /* @__PURE__ */ a(
          Va,
          {
            data: ia,
            title: e("navigation:dashboard.applicationUsage.title"),
            accessLabel: e("navigation:dashboard.applicationUsage.accesses")
          }
        ),
        /* @__PURE__ */ a("div", { className: "flex flex-wrap gap-2 justify-end", children: [7, 30, 90].map((h) => /* @__PURE__ */ a(
          "button",
          {
            type: "button",
            onClick: () => l(h),
            className: `px-3 py-1 text-sm font-medium transition-colors ${d === h ? "bg-[var(--color-accent-500)] text-white" : "bg-[var(--bg-secondary)] text-[var(--text-secondary)] hover:bg-[var(--bg-tertiary)]"} rounded-[var(--radius-button)]`,
            children: e(`navigation:dashboard.sessionAnalytics.period.${h}days`)
          },
          h
        )) }),
        /* @__PURE__ */ a(
          Ka,
          {
            data: s?.dailyStats ?? [],
            title: e("navigation:dashboard.sessionAnalytics.title"),
            connectionsLabel: e("navigation:dashboard.sessionAnalytics.connections"),
            avgDurationLabel: e("navigation:dashboard.sessionAnalytics.avgDuration"),
            minutesSuffix: e("navigation:dashboard.weeklyUsage.duration", "min")
          }
        ),
        /* @__PURE__ */ o(
          "div",
          {
            className: "p-6 bg-[var(--bg-card)] border border-[var(--border-color)] rounded-[var(--radius-card)]",
            children: [
              /* @__PURE__ */ o("div", { className: "flex items-center gap-3 mb-4", children: [
                /* @__PURE__ */ a(k, { className: "w-5 h-5 text-[var(--text-secondary)]" }),
                /* @__PURE__ */ a("h2", { className: "font-semibold text-[var(--text-primary)]", children: e("navigation:dashboard.currentSession.title") })
              ] }),
              /* @__PURE__ */ a(Fa, { session: oa })
            ]
          }
        ),
        /* @__PURE__ */ o(
          "div",
          {
            className: "p-6 bg-[var(--bg-card)] border border-[var(--border-color)] rounded-[var(--radius-card)]",
            children: [
              /* @__PURE__ */ o("div", { className: "flex items-center gap-3 mb-4", children: [
                /* @__PURE__ */ a(S, { className: "w-5 h-5 text-[var(--text-secondary)]" }),
                /* @__PURE__ */ a("h2", { className: "font-semibold text-[var(--text-primary)]", children: e("navigation:dashboard.loginErrors.title") })
              ] }),
              /* @__PURE__ */ a(ja, { errors: x ?? [] })
            ]
          }
        ),
        /* @__PURE__ */ o(
          "div",
          {
            className: "p-6 bg-[var(--bg-card)] border border-[var(--border-color)] rounded-[var(--radius-card)]",
            children: [
              /* @__PURE__ */ o("div", { className: "flex items-center gap-3 mb-4", children: [
                /* @__PURE__ */ a(Sa, { className: "w-5 h-5 text-[var(--text-secondary)]" }),
                /* @__PURE__ */ a("h2", { className: "font-semibold text-[var(--text-primary)]", children: e("navigation:dashboard.deviceStats.title") })
              ] }),
              /* @__PURE__ */ a(Ba, { stats: na })
            ]
          }
        )
      ]
    }
  );
}
export {
  se as UserDashboardPage
};
//# sourceMappingURL=UserDashboardPage-DY_7Ypai.js.map
