"use client"; import Link from "next/link"; import { useRouter } from "next/navigation"; import { useEffect, useMemo } from "react"; import { useDashboardSummary } from "@/src/hooks/useDashboardSummary"; import { clearAuth, getStoredUser } from "@/src/lib/auth"; import { Spinner, Alert } from "@/src/Components/UI"; export default function DashboardPage() { const router = useRouter(); const { data, error, loading } = useDashboardSummary(); useEffect(() => { const storedUser = getStoredUser(); const role = typeof storedUser?.role === "string" ? storedUser.role : ""; if (!role || ["driver", "سائق"].includes(role)) { clearAuth(); router.replace("/login"); } }, [router]); const stats = data?.stats; const alerts = data?.alerts; const activeTrips = data?.activeTrips || []; const summaryCards = useMemo( () => [ { label: "العملاء", value: stats?.clients ?? 0, accent: "#06B6D4" }, { label: "الطلبات", value: stats?.orders ?? 0, accent: "#A78BFA" }, { label: "الرحلات", value: stats?.trips ?? 0, accent: "#34D399" }, { label: "المركبات", value: (stats?.cars ?? 0) + (stats?.drivers ?? 0), accent: "#FBBF24" }, ], [stats], ); return (
{/* ── Header ── */}

لوحة العمليات

ذكاء الأسطول في لمحة سريعة

عرض واضح لطلبات الأسطول وتنبيهات السلامة وتقدم الرحلات.

العودة إلى بوابة العميل
{/* ── Loading ── */} {loading && (
جارٍ تحميل البيانات…
)} {/* ── Error ── */} {error && ( )} {!loading && !error && ( <> {/* ── Summary cards ── */}
{summaryCards.map((item) => (

{item.label}

{item.value}

))}
{/* ── Active trips + alerts ── Column order in the template below stays [trips, alerts] — same reading order as before. In RTL this now renders trips on the right (read first) and alerts on the left, which is the correct mirror; no class change needed (see grid + RTL note in the project report). */}

الرحلات النشطة

تقدم الرحلات

مباشر
{activeTrips.length ? activeTrips.map((trip) => (

{trip.tripNumber}

{trip.title}

{trip.progress}%
{/* Progress fill: width % growing from the bar's start edge is correct in both directions since `width` itself is non-directional — the bar's own inline-start (right, in RTL) is where the fill begins, matching how the rest of the RTL layout fills from the right. No change needed. */}
)) : (

لا توجد رحلات نشطة حالياً.

)}

تنبيهات الالتزام

التجديدات القادمة

{(alerts?.expiringCars || []).slice(0, 3).map((item, i) => (
{String((item as Record).message || "Vehicle expiry alert")}
))} {(alerts?.expiringDrivers || []).slice(0, 3).map((item, i) => (
{String((item as Record).message || "Driver expiry alert")}
))} {(alerts?.upcomingMaint || []).slice(0, 3).map((item, i) => (
{String((item as Record).message || "Maintenance alert")}
))} {!(alerts?.expiringCars?.length || alerts?.expiringDrivers?.length || alerts?.upcomingMaint?.length) && (

لا توجد تنبيهات حالياً.

)}
{/* ── Security + endpoints ── */}

الأمان

لمحة الحساب

آخر تسجيل دخول: {data?.accountSecurity?.lastLogin || "—"}
{/* JSON.stringify output is structurally LTR (braces, colons, commas read left-to-right regardless of locale). Wrapping it in .ltr-embed prevents the surrounding RTL paragraph from reordering the punctuation — without this, nested objects can render with their braces visually swapped. */} بيانات الجهاز: {data?.accountSecurity?.requestMeta ? JSON.stringify(data.accountSecurity.requestMeta) : "—"}

خريطة الخلفية

النقاط النهائية

    {[ "/v1/dashboard/summary — نظرة عامة تشغيلية", "/v1/client — إدارة العملاء", "/v1/orders — دورة شحن الطلبات", "/v1/trip — تنظيم الرحلات", ].map((ep) => (
  • {/* Each entry mixes an LTR API path with an Arabic description. Splitting on the em-dash and isolating only the path keeps the route string from reading backwards while letting the Arabic half flow naturally in the paragraph's own direction. */} {ep.split(" — ")[0]} {" — "} {ep.split(" — ")[1]}
  • ))}
)}
); }