"use client"; import { useCallback, useEffect, useState } from "react"; import { Spinner } from "../UI"; import { driverService } from "../../services/driver.service"; import { getStoredToken } from "../../lib/auth"; import type { Driver } from "../../types/driver"; import { DRIVER_STATUS_MAP, DRIVER_CARD_TYPE_MAP, NATIONAL_ID_TYPE_MAP, } from "../../types/driver"; // ── Helpers ─────────────────────────────────────────────────────────────────── /** Format an ISO date string to a readable Arabic date. */ function fmtDate(iso?: string | null): string { if (!iso) return "—"; return new Date(iso).toLocaleDateString("ar-SA", { year: "numeric", month: "long", day: "numeric", }); } /** Returns true if the date is within 90 days in the future (or already past). */ function isExpiringSoon(iso?: string | null): boolean { if (!iso) return false; const diff = new Date(iso).getTime() - Date.now(); return diff <= 90 * 86_400_000; } /** Build the full image URL via the proxy to avoid CORS issues. */ function buildPhotoUrl(filename?: string | null): string | null { if (!filename) return null; return `/api/proxy/driver-photos/${filename}`; } // ── Sub-components ──────────────────────────────────────────────────────────── function DetailRow({ label, value, mono = false, warn = false, }: { label: string; value: string; mono?: boolean; warn?: boolean; }) { return (
{title}
); } // ── Report generator sub-panel ─────────────────────────────────────────────── function ReportPanel({ driverId }: { driverId: string }) { const today = new Date().toISOString().slice(0, 10); const [date, setDate] = useState(today); const [loading, setLoading] = useState(false); const [error, setError] = useStateإنشاء تقرير يومي