import { useState, useMemo } from 'react'; import { Grid, Card, Stack, Button, TextField, MenuItem, InputAdornment, Box, IconButton, Tooltip, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, TablePagination, Typography, Dialog, DialogTitle, DialogContent, DialogActions } from '@mui/material'; import SearchIcon from '@mui/icons-material/Search'; import CalendarTodayOutlinedIcon from '@mui/icons-material/CalendarTodayOutlined'; import FileDownloadOutlinedIcon from '@mui/icons-material/FileDownloadOutlined'; import MapOutlinedIcon from '@mui/icons-material/MapOutlined'; import CloseIcon from '@mui/icons-material/Close'; import PageHeader from '@/components/PageHeader'; import StatusChip from '@/components/StatusChip'; import MapPlaceholder from '@/components/MapPlaceholder'; import { ordersDetailReport, locations, tenantsList } from '@/data/mock'; import { inr } from '@/utils/format'; const STATUSES = ['all', 'created', 'pending', 'picked', 'active', 'delivered', 'cancelled']; export default function OrdersDetails() { const [location, setLocation] = useState('all'); const [tenant, setTenant] = useState('all'); const [loc2, setLoc2] = useState('all'); const [status, setStatus] = useState('all'); const [search, setSearch] = useState(''); const [page, setPage] = useState(0); const [rpp, setRpp] = useState(10); const [mapRow, setMapRow] = useState(null); const [exportOpen, setExportOpen] = useState(false); const filtered = useMemo( () => ordersDetailReport.filter((o) => { const matchStatus = status === 'all' || o.status === status; const matchTenant = tenant === 'all' || o.client === tenant; const matchSearch = !search || [o.id, o.client, o.pickup, o.drop].join(' ').toLowerCase().includes(search.toLowerCase()); return matchStatus && matchTenant && matchSearch; }), [status, tenant, search] ); const paged = filtered.slice(page * rpp, page * rpp + rpp); return ( <> setLocation(e.target.value)} sx={{ minWidth: 160 }} label="Location"> All Locations {locations.map((l) => {l})} } /> setTenant(e.target.value)} sx={{ minWidth: 170 }} label="Tenant"> All Tenants {tenantsList.map((t) => {t})} setLoc2(e.target.value)} sx={{ minWidth: 160 }} label="Location"> All Locations {locations.map((l) => {l})} { setStatus(e.target.value); setPage(0); }} sx={{ minWidth: 150 }} label="Status"> {STATUSES.map((s) => {s === 'all' ? 'All Status' : s[0].toUpperCase() + s.slice(1)})} { setSearch(e.target.value); setPage(0); }} sx={{ minWidth: 220 }} InputProps={{ startAdornment: }} /> # Client Pickup Drop Status Assigned Accepted Arrived Picked Active Delivered Cancelled Notes KMS Charges {paged.map((o, i) => ( {page * rpp + i + 1} setMapRow(o)}> {o.client} {o.pickup} {o.drop} {o.assigned} {o.accepted} {o.arrived} {o.picked} {o.active} {o.delivered} {o.cancelled} {o.notes || '—'} {o.kms} {inr(o.charges)} ))}
setPage(p)} rowsPerPage={rpp} onRowsPerPageChange={(e) => { setRpp(+e.target.value); setPage(0); }} rowsPerPageOptions={[10, 25, 50]} />
{/* Map dialog */} setMapRow(null)} fullScreen> Route — {mapRow?.id} {mapRow?.pickup} → {mapRow?.drop} setMapRow(null)}> {/* Export dialog */} setExportOpen(false)} maxWidth="xs" fullWidth> Export Report The export will include {filtered.length} record(s) matching the current filters: ); } function Filter({ label, value }) { return ( {label} {value} ); }