import { Form } from "@remix-run/react"; import { useState, useEffect } from "react"; import { Button } from "~/components/ui/Button"; import { Flex } from "~/components/layout/Flex"; import { useSettings } from "~/contexts/SettingsContext"; import type { CustomerWithVehicles } from "~/types/database"; interface CustomerListProps { customers: CustomerWithVehicles[]; currentPage: number; totalPages: number; onPageChange: (page: number) => void; onViewCustomer: (customer: CustomerWithVehicles) => void; onEditCustomer: (customer: CustomerWithVehicles) => void; isLoading: boolean; actionData?: any; } export function CustomerList({ customers, currentPage, totalPages, onPageChange, onViewCustomer, onEditCustomer, isLoading, actionData, }: CustomerListProps) { const { formatDate } = useSettings(); const [deletingCustomerId, setDeletingCustomerId] = useState(null); // Reset deleting state when delete action completes useEffect(() => { if (actionData?.success && actionData.action === "delete") { setDeletingCustomerId(null); } }, [actionData]); const columns = [ { key: "name", header: "اسم العميل", render: (customer: CustomerWithVehicles) => (
{customer.name}
{/* العميل رقم: {customer.id} */}
), }, { key: "contact", header: "معلومات الاتصال", render: (customer: CustomerWithVehicles) => (
{customer.phone && (
📞 {customer.phone}
)} {customer.email && (
✉️ {customer.email}
)} {!customer.phone && !customer.email && (
لا توجد معلومات اتصال
)}
), }, { key: "address", header: "العنوان", render: (customer: CustomerWithVehicles) => (
{customer.address || ( غير محدد )}
), }, { key: "vehicles", header: "المركبات", render: (customer: CustomerWithVehicles) => (
{customer.vehicles.length} مركبة
{customer.vehicles.length > 0 && (
{customer.vehicles.slice(0, 2).map((vehicle) => (
{vehicle.plateNumber} - {vehicle.manufacturer} {vehicle.model}
))} {customer.vehicles.length > 2 && (
و {customer.vehicles.length - 2} مركبة أخرى...
)}
)}
), }, { key: "visits", header: "الزيارات", render: (customer: CustomerWithVehicles) => (
{customer.maintenanceVisits.length} زيارة
{customer.maintenanceVisits.length > 0 && (
آخر زيارة: {formatDate(customer.maintenanceVisits[0].visitDate)}
)}
), }, { key: "createdDate", header: "تاريخ الإنشاء", render: (customer: CustomerWithVehicles) => (
{formatDate(customer.createdDate)}
), }, { key: "actions", header: "الإجراءات", render: (customer: CustomerWithVehicles) => (
), }, ]; return (
{customers.length === 0 ? (
👥

لا يوجد عملاء

لم يتم العثور على أي عملاء. قم بإضافة عميل جديد للبدء.

) : ( <>
{columns.map((column) => ( ))} {customers.map((customer) => ( {columns.map((column) => ( ))} ))}
{column.header}
{column.render ? column.render(customer) : String(customer[column.key as keyof CustomerWithVehicles] || '')}
{/* Pagination */} {totalPages > 1 && (
{Array.from({ length: Math.min(5, totalPages) }, (_, i) => { const page = i + 1; return ( ); })}

صفحة {currentPage} من {totalPages}

)} )}
); }