2 lines
21 KiB
JavaScript
2 lines
21 KiB
JavaScript
import{r as K,j as e,i as Q,u as ze,a as Te,b as c,k as $e,t as f,S as a,d as ae,B as o,T as s,l as _e,C as le,f as ke,g as De,m as We,U as X,D as V,n as ce,I as w,o as G}from"./index-DpAn5wLF.js";import{d as Pe,D as Re,a as Le,b as Be,c as Ae}from"./Close-BdNf_RlN.js";import{d as Ee}from"./Refresh-B8qCgQHN.js";import{d as J}from"./EditOutlined-B2ltVbl8.js";import{T as Fe,d as de}from"./DeleteOutline-BVDDlNca.js";import{d as _,a as xe,b as he,c as Me}from"./StorefrontOutlined-B0ka2NHy.js";import{d as qe,a as ue,b as me,S as Y}from"./StatusChip-C72vLAK4.js";import{D as Oe,d as ge}from"./PhoneOutlined-CDgMDTyj.js";import{d as He}from"./LocalShippingOutlined-Ds2yAonP.js";import{d as Ne}from"./MapOutlined-QidbDh4A.js";import{T as we,d as Ve}from"./TabLabelCount-C_C4hO8i.js";import{P as Ge,G as u,C as Z,A as Ue}from"./PageHeader-CEew5Fw4.js";import{S as B}from"./StatCard-Nzv53jX8.js";import{E as Ke}from"./EmptyState-BsjYeVAX.js";import{C as Qe}from"./ClientFormDialog-K7w_VS5d.js";import{B as p}from"./Button-BGNvVfej.js";import{C as Xe}from"./Link-Bme8npFv.js";import{T as Je}from"./TextField-C0dUZvW0.js";import{I as Ye}from"./InputAdornment-BWnl4jqW.js";import{T as Ze,a as et}from"./Tabs-Cp4sZXyZ.js";import{T as tt,a as rt,b as it,c as U,d as nt}from"./TableRow-BcqnvRn2.js";import{T as x}from"./TableCell-PEGz6qo_.js";import"./Snackbar-B0wJYiYQ.js";var ee={},st=Q;Object.defineProperty(ee,"__esModule",{value:!0});var pe=ee.default=void 0,at=st(K()),lt=e;pe=ee.default=(0,at.default)((0,lt.jsx)("path",{d:"M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8"}),"InfoOutlined");var te={},ot=Q;Object.defineProperty(te,"__esModule",{value:!0});var je=te.default=void 0,ct=ot(K()),dt=e;je=te.default=(0,ct.default)((0,dt.jsx)("path",{d:"M21 11.01 3 11v2h18zM3 16h12v2H3zM21 6H3v2.01L21 8z"}),"NotesOutlined");var re={},xt=Q;Object.defineProperty(re,"__esModule",{value:!0});var fe=re.default=void 0,ht=xt(K()),ut=e;fe=re.default=(0,ht.default)((0,ut.jsx)("path",{d:"M16.01 11H4v2h12.01v3L20 12l-3.99-4z"}),"ArrowRightAlt");const mt=t=>({full:"success",basiconly:"info",none:"default"})[String(t||"").toLowerCase()]||"default",gt=t=>{const l=String(t||"").toLowerCase();return/high|good|excellent/.test(l)?"success":/med|average|moderate/.test(l)?"warning":/low|poor|bad/.test(l)?"error":"info"},pt={textTransform:"uppercase",letterSpacing:.4,fontSize:"0.68rem",fontWeight:700,color:"grey.700"};function j({label:t,color:l="default"}){return t==null||t===""?e.jsx(s,{variant:"body2",sx:{fontWeight:500,color:"grey.500"},children:"—"}):e.jsx(Z,{size:"small",label:t,sx:{fontWeight:600,...l==="default"?{bgcolor:"grey.100",color:"grey.700"}:{bgcolor:`${l}.lighter`,color:`${l}.dark`}}})}function m({label:t,children:l}){return e.jsxs(o,{children:[e.jsx(s,{variant:"caption",color:"text.secondary",sx:pt,children:t}),e.jsx(o,{sx:{mt:.5},children:l})]})}function A({label:t,value:l}){return e.jsx(m,{label:t,children:e.jsx(s,{variant:"body2",sx:{fontWeight:500,color:l?"grey.800":"grey.500",wordBreak:"break-word"},children:l||"—"})})}function E({icon:t,title:l,accent:i="primary",children:d}){return e.jsxs(o,{sx:{height:"100%",borderRadius:2,border:1,borderColor:"divider",bgcolor:"background.paper",overflow:"hidden"},children:[e.jsxs(a,{direction:"row",spacing:1,alignItems:"center",sx:{px:2,py:1.25,borderBottom:1,borderColor:"divider",bgcolor:`${i}.lighter`,opacity:.999},children:[e.jsx(t,{sx:{fontSize:18,color:`${i}.main`}}),e.jsx(s,{variant:"overline",sx:{fontWeight:700,color:"grey.800",letterSpacing:.6,lineHeight:1},children:l})]}),e.jsx(a,{spacing:1.75,sx:{p:2},children:d})]})}function oe({label:t,value:l,icon:i,color:d="primary"}){return e.jsx(o,{sx:{flex:1,p:1.5,borderRadius:1.5,border:1,borderColor:"divider",bgcolor:"grey.50"},children:e.jsxs(a,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(o,{sx:{width:32,height:32,borderRadius:1,bgcolor:`${d}.lighter`,color:`${d}.main`,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx(i,{sx:{fontSize:18}})}),e.jsxs(o,{children:[e.jsx(s,{variant:"h5",sx:{fontWeight:700,color:"grey.800",lineHeight:1.1},children:l}),e.jsx(s,{variant:"caption",color:"text.secondary",children:t})]})]})})}function F({label:t,value:l,color:i="grey.800"}){return e.jsxs(o,{sx:{textAlign:"center",minWidth:56},children:[e.jsx(s,{variant:"body2",sx:{fontWeight:700,color:i,lineHeight:1.2},children:l}),e.jsx(s,{variant:"caption",color:"text.secondary",sx:{fontSize:"0.65rem"},children:t})]})}function be({row:t,onEdit:l}){return e.jsxs(o,{sx:{m:2,borderRadius:2.5,border:1,borderColor:"divider",overflow:"hidden",boxShadow:"0 4px 16px rgba(0,0,0,0.06)"},children:[e.jsxs(a,{direction:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"center"},spacing:1.5,sx:{px:2.5,py:1.75,borderBottom:1,borderColor:"divider",background:i=>`linear-gradient(90deg, ${i.palette.primary.lighter}88 0%, ${i.palette.background.paper} 75%)`},children:[e.jsxs(a,{direction:"row",spacing:1.5,alignItems:"center",children:[e.jsx(X,{name:t.name,size:40}),e.jsxs(o,{children:[e.jsx(s,{variant:"subtitle1",sx:{fontWeight:700,lineHeight:1.2},children:t.name}),e.jsxs(a,{direction:"row",spacing:.75,alignItems:"center",sx:{mt:.25},children:[e.jsx(Ve,{sx:{fontSize:14,color:"grey.400"}}),e.jsx(s,{variant:"caption",color:"text.secondary",children:t.clientId})]})]}),e.jsx(Y,{status:t.status,sx:{ml:.5}})]}),e.jsx(p,{size:"small",variant:"contained",startIcon:e.jsx(J,{}),onClick:()=>l(t),sx:{width:{xs:"100%",sm:"auto"}},children:"Edit Client"})]}),e.jsx(o,{sx:{p:{xs:1.5,sm:2.5},bgcolor:"grey.50"},children:e.jsxs(u,{container:!0,spacing:2.5,alignItems:"stretch",children:[e.jsx(u,{item:!0,xs:12,md:4,children:e.jsxs(E,{icon:Me,title:"Business",accent:"primary",children:[e.jsxs(a,{direction:"row",spacing:1.5,children:[e.jsx(oe,{label:"Parcel Volume",value:Number(t.parcelVolume).toLocaleString(),icon:ue,color:"primary"}),e.jsx(oe,{label:"Active Contracts",value:t.activeContracts,icon:me,color:"primary"})]}),e.jsx(m,{label:"Client ID",children:e.jsx(s,{variant:"body2",sx:{fontFamily:"monospace",fontWeight:600,color:"grey.800"},children:t.clientId})}),e.jsx(m,{label:"Business Type",children:e.jsx(j,{label:t.businessType&&f(t.businessType),color:"primary"})}),e.jsx(m,{label:"Order Frequency",children:e.jsx(j,{label:t.frequency&&f(t.frequency),color:"info"})})]})}),e.jsx(u,{item:!0,xs:12,md:4,children:e.jsxs(E,{icon:He,title:"Logistics",accent:"primary",children:[e.jsx(m,{label:"Logistics Segment",children:t.logisticsSegment?e.jsx(a,{direction:"row",spacing:.75,flexWrap:"wrap",useFlexGap:!0,children:String(t.logisticsSegment).split(/[,/]/).map(i=>i.trim()).filter(Boolean).map(i=>e.jsx(j,{label:f(i),color:"primary"},i))}):e.jsx(j,{label:null})}),e.jsx(A,{label:"Current Provider",value:t.provider}),e.jsx(m,{label:"Efficiency",children:e.jsx(j,{label:t.efficiency&&f(t.efficiency),color:gt(t.efficiency)})}),e.jsx(m,{label:"Transit Route",children:(()=>{const i=[t.transitFrom,...String(t.transitTo||"").split(",")].map(d=>d.trim()).filter(Boolean);return i.length?e.jsx(a,{direction:"row",spacing:.75,alignItems:"center",flexWrap:"wrap",useFlexGap:!0,children:i.map((d,h)=>e.jsxs(c.Fragment,{children:[h>0&&e.jsx(fe,{sx:{fontSize:20,color:"primary.main"}}),e.jsx(j,{label:f(d),color:h===0?"default":"info"})]},`${d}-${h}`))}):e.jsx(j,{label:null})})()})]})}),e.jsx(u,{item:!0,xs:12,md:4,children:e.jsxs(E,{icon:_,title:"Location & Survey",accent:"primary",children:[e.jsx(m,{label:"City / State",children:e.jsx(s,{variant:"body2",sx:{fontWeight:500,color:"grey.800"},children:[t.city,t.businessState].filter(Boolean).join(", ")||"—"})}),e.jsx(A,{label:"Neighbourhood",value:t.neighbourhood}),e.jsx(m,{label:"Survey Address",children:e.jsxs(a,{direction:"row",spacing:1,sx:{p:1.25,borderRadius:1.5,bgcolor:"grey.50",border:1,borderColor:"divider"},children:[e.jsx(_,{sx:{fontSize:16,color:"grey.400",mt:"2px"}}),e.jsx(s,{variant:"body2",sx:{color:"grey.800",lineHeight:1.5},children:t.surveyAddress||"—"})]})}),e.jsx(m,{label:"Coordinates",children:t.surveyLat&&t.surveyLng?e.jsxs(a,{direction:"row",spacing:1.25,alignItems:"center",flexWrap:"wrap",useFlexGap:!0,children:[e.jsx(G,{title:`${t.surveyLat}, ${t.surveyLng}`,arrow:!0,placement:"top",children:e.jsxs(a,{direction:"row",spacing:.5,alignItems:"center",sx:{cursor:"default"},children:[e.jsx(_,{sx:{fontSize:16,color:"grey.400"}}),e.jsx(s,{variant:"body2",sx:{fontWeight:500,color:"grey.800",borderBottom:"1px dotted",borderColor:"grey.300"},children:[t.neighbourhood,t.city].filter(Boolean).join(", ")||"Pinned location"})]})}),e.jsx(p,{component:"a",href:`https://www.google.com/maps?q=${t.surveyLat},${t.surveyLng}`,target:"_blank",rel:"noopener",size:"small",variant:"outlined",startIcon:e.jsx(Ne,{sx:{fontSize:16}}),sx:{py:.25,px:1.25,minWidth:0,fontSize:"0.75rem",fontWeight:600,borderRadius:5,color:"primary.main",borderColor:"primary.100",bgcolor:"primary.lighter","&:hover":{borderColor:"primary.main",bgcolor:"primary.lighter"}},children:"View on map"})]}):e.jsx(s,{variant:"body2",sx:{color:"grey.500"},children:"—"})})]})}),e.jsx(u,{item:!0,xs:12,children:e.jsx(E,{icon:pe,title:"Contact & Compliance",accent:"primary",children:e.jsxs(u,{container:!0,spacing:2.5,children:[e.jsx(u,{item:!0,xs:12,sm:6,md:4,children:e.jsx(A,{label:"Phone",value:t.phone})}),e.jsx(u,{item:!0,xs:12,sm:6,md:4,children:e.jsx(m,{label:"Data Consent",children:e.jsx(j,{label:t.dataConsent&&f(t.dataConsent),color:mt(t.dataConsent)})})}),e.jsx(u,{item:!0,xs:12,sm:6,md:4,children:e.jsx(A,{label:"Last Updated",value:t.lastUpdated})}),t.notes&&e.jsx(u,{item:!0,xs:12,children:e.jsxs(o,{sx:{p:2,borderRadius:1.5,bgcolor:"warning.lighter",border:1,borderColor:"warning.light"},children:[e.jsxs(a,{direction:"row",spacing:1,alignItems:"center",sx:{mb:.5},children:[e.jsx(je,{sx:{fontSize:16,color:"warning.dark"}}),e.jsx(s,{variant:"caption",sx:{color:"warning.dark",textTransform:"uppercase",letterSpacing:.4,fontSize:"0.68rem",fontWeight:700},children:"Notes"})]}),e.jsx(s,{variant:"body2",sx:{color:"grey.800"},children:t.notes})]})})]})})})]})})]})}function jt({row:t,onEdit:l,onDelete:i}){const[d,h]=c.useState(!1);return e.jsxs(o,{sx:{borderRadius:3,border:1,borderColor:d?"primary.light":"divider",bgcolor:"background.paper",overflow:"hidden"},children:[e.jsxs(o,{sx:{p:2},children:[e.jsxs(a,{direction:"row",spacing:1.25,alignItems:"center",children:[e.jsx(X,{name:t.name,size:42}),e.jsxs(o,{sx:{minWidth:0,flexGrow:1},children:[e.jsx(s,{variant:"body2",sx:{fontWeight:700,color:"grey.800"},noWrap:!0,children:t.name}),e.jsx(s,{variant:"caption",sx:{fontFamily:"monospace",fontWeight:700,color:"primary.main"},children:t.logicalId})]}),e.jsx(Y,{status:t.status})]}),e.jsxs(a,{spacing:1,sx:{mt:1.75},children:[e.jsxs(a,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(ge,{sx:{fontSize:16,color:"grey.400",flexShrink:0}}),e.jsx(s,{variant:"body2",children:t.phone||"—"})]}),e.jsxs(a,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(_,{sx:{fontSize:16,color:"grey.400",flexShrink:0}}),e.jsxs(s,{variant:"body2",noWrap:!0,children:[t.city||"—",t.businessState?`, ${t.businessState}`:""]})]})]}),e.jsxs(a,{direction:"row",spacing:1.5,alignItems:"center",divider:e.jsx(V,{orientation:"vertical",flexItem:!0}),sx:{mt:1.75},children:[e.jsx(F,{label:"Parcels",value:Number(t.parcelVolume).toLocaleString()}),e.jsx(F,{label:"Contracts",value:t.activeContracts,color:"primary.main"})]}),e.jsx(V,{sx:{my:1.5}}),e.jsxs(a,{direction:"row",spacing:1,justifyContent:"space-between",alignItems:"center",children:[e.jsx(p,{size:"small",onClick:()=>h(b=>!b),endIcon:d?e.jsx(xe,{}):e.jsx(he,{}),children:d?"Hide":"Details"}),e.jsxs(a,{direction:"row",spacing:1,children:[e.jsx(p,{size:"small",variant:"outlined",startIcon:e.jsx(J,{fontSize:"small"}),onClick:()=>l(t),children:"Edit"}),e.jsx(p,{size:"small",variant:"outlined",color:"error",startIcon:e.jsx(de,{fontSize:"small"}),onClick:()=>i(t),children:"Delete"})]})]})]}),e.jsx(ce,{in:d,timeout:"auto",unmountOnExit:!0,children:e.jsx(o,{sx:{borderTop:1,borderColor:"divider"},children:e.jsx(be,{row:t,onEdit:l})})})]})}function ft({row:t,index:l,onEdit:i,onDelete:d}){const[h,b]=c.useState(!1);return e.jsxs(c.Fragment,{children:[e.jsxs(U,{hover:!0,sx:{cursor:"pointer","& > *":{borderBottom:h?"unset":void 0},...h&&{bgcolor:"primary.lighter","&:hover":{bgcolor:"primary.lighter"}}},onClick:()=>b(g=>!g),children:[e.jsx(x,{padding:"checkbox",children:e.jsx(w,{size:"small",onClick:g=>{g.stopPropagation(),b(v=>!v)},children:h?e.jsx(xe,{}):e.jsx(he,{})})}),e.jsx(x,{sx:{whiteSpace:"nowrap"},children:e.jsx(s,{variant:"caption",sx:{fontFamily:"monospace",fontWeight:700,color:"primary.main",bgcolor:"primary.lighter",px:1,py:.5,borderRadius:1,border:"1px solid",borderColor:"primary.light",whiteSpace:"nowrap"},children:t.logicalId})}),e.jsx(x,{children:e.jsxs(a,{direction:"row",spacing:1.25,alignItems:"center",children:[e.jsx(X,{name:t.name,size:38}),e.jsxs(o,{sx:{minWidth:0},children:[e.jsx(s,{variant:"body2",sx:{fontWeight:600,color:"grey.800"},children:t.name}),e.jsx(a,{direction:"row",spacing:.75,alignItems:"center",sx:{mt:.4},children:t.businessType&&e.jsx(Z,{size:"small",label:f(t.businessType),sx:{height:20,fontSize:"0.68rem",fontWeight:600,bgcolor:"grey.100",color:"grey.700"}})})]})]})}),e.jsx(x,{children:e.jsxs(a,{direction:"row",spacing:.75,alignItems:"center",children:[e.jsx(ge,{sx:{fontSize:15,color:"grey.400"}}),e.jsxs(o,{children:[e.jsx(s,{variant:"body2",children:t.phone||"—"}),t.frequency&&e.jsx(s,{variant:"caption",color:"text.secondary",children:t.frequency})]})]})}),e.jsx(x,{children:e.jsxs(a,{direction:"row",spacing:.75,alignItems:"center",children:[e.jsx(_,{sx:{fontSize:15,color:"grey.400"}}),e.jsxs(o,{children:[e.jsxs(s,{variant:"body2",children:[t.city||"—",t.businessState?`, ${t.businessState}`:""]}),t.neighbourhood&&e.jsx(s,{variant:"caption",color:"text.secondary",children:t.neighbourhood})]})]})}),e.jsx(x,{children:e.jsxs(a,{direction:"row",spacing:1.5,alignItems:"center",justifyContent:"center",divider:e.jsx(V,{orientation:"vertical",flexItem:!0}),children:[e.jsx(F,{label:"Parcels",value:Number(t.parcelVolume).toLocaleString()}),e.jsx(F,{label:"Contracts",value:t.activeContracts,color:"primary.main"})]})}),e.jsx(x,{children:e.jsx(Y,{status:t.status})}),e.jsxs(x,{align:"right",children:[e.jsx(G,{title:"Edit",children:e.jsx(w,{size:"small",onClick:g=>{g.stopPropagation(),i(t)},children:e.jsx(J,{fontSize:"small"})})}),e.jsx(G,{title:"Delete",children:e.jsx(w,{size:"small",onClick:g=>{g.stopPropagation(),d(t)},children:e.jsx(de,{fontSize:"small"})})})]})]}),e.jsx(U,{children:e.jsx(x,{colSpan:8,sx:{py:0,borderBottom:h?void 0:"none"},children:e.jsx(ce,{in:h,timeout:"auto",unmountOnExit:!0,children:e.jsx(be,{row:t,onEdit:i})})})})]})}function Ht(){var se;const t=ze(),l=Te(t.breakpoints.down("md")),[i,d]=c.useState([]),[h,b]=c.useState(!0),[g,v]=c.useState(null),[M]=$e(),[q,ye]=c.useState(0),[k,ie]=c.useState(M.get("q")||""),[D,C]=c.useState(0),[S,ve]=c.useState(10);c.useEffect(()=>{const r=M.get("q");r!=null&&(ie(r),C(0))},[M]);const[O,I]=c.useState({open:!1,mode:"add",initial:null}),[z,T]=c.useState(null),[W,ne]=c.useState(!1),y=(r=!1)=>{r||(b(!0),v(null)),ke().then(n=>d(n.map(De))).catch(n=>{r||v(n.message||"Failed to load clients")}).finally(()=>{r||b(!1)})};c.useEffect(()=>{y();const r=setInterval(()=>{y(!0)},1e4);return()=>clearInterval(r)},[]);const P=c.useMemo(()=>({total:i.length,newCount:i.filter(r=>r.status==="newClient").length,parcels:i.reduce((r,n)=>r+(Number(n.parcelVolume)||0),0),contracts:i.reduce((r,n)=>r+(Number(n.activeContracts)||0),0)}),[i]),R=c.useMemo(()=>{const r=[];return i.forEach(n=>{r.includes(n.status)||r.push(n.status)}),[{key:"all",label:"All"},...r.map(n=>({key:n,label:f(n)}))]},[i]),H=((se=R[Math.min(q,R.length-1)])==null?void 0:se.key)||"all",Ce=c.useMemo(()=>{const r={all:i.length};return i.forEach(n=>{r[n.status]=(r[n.status]||0)+1}),r},[i]),L=c.useMemo(()=>i.filter(r=>{const n=H==="all"||r.status===H,$=!k||[r.name,r.phone,r.city,r.businessType,r.clientId,r.neighbourhood].join(" ").toLowerCase().includes(k.toLowerCase());return n&&$}),[i,H,k]),N=L.slice(D*S,D*S+S),Se=()=>{I({open:!1,mode:"add",initial:null}),y()},Ie=async()=>{ne(!0);try{await We(z.id),T(null),y()}catch(r){v(r.message||"Failed to delete client")}finally{ne(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx(Ge,{title:"Clients",breadcrumbs:[{label:"Clients"}],action:e.jsxs(a,{direction:"row",spacing:1.5,sx:{width:{xs:"100%",sm:"auto"}},children:[e.jsx(p,{variant:"outlined",startIcon:e.jsx(Ee,{}),onClick:y,disabled:h,sx:{flex:{xs:1,sm:"none"}},children:"Refresh"}),e.jsx(p,{variant:"contained",startIcon:e.jsx(Pe,{}),onClick:()=>I({open:!0,mode:"add",initial:null}),sx:{flex:{xs:1,sm:"none"}},children:"Add Client"})]})}),e.jsxs(u,{container:!0,spacing:2.5,sx:{mb:3},children:[e.jsx(u,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(B,{accent:!0,title:"Total Clients",value:P.total,icon:ae,caption:"All registered"})}),e.jsx(u,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(B,{accent:!0,title:"New Clients",value:P.newCount,icon:qe,color:"primary",caption:"Awaiting onboarding"})}),e.jsx(u,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(B,{accent:!0,title:"Total Parcel Volume",value:P.parcels.toLocaleString(),icon:ue,color:"primary",caption:"Across all clients"})}),e.jsx(u,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(B,{accent:!0,title:"Active Contracts",value:P.contracts,icon:me,color:"primary",caption:"Currently running"})})]}),e.jsxs(Xe,{sx:{overflow:"hidden"},children:[e.jsxs(o,{sx:{px:2.5,py:2,borderBottom:1,borderColor:"divider",display:"flex",alignItems:"center",gap:1.5,background:r=>`linear-gradient(90deg, ${r.palette.primary.lighter}66 0%, ${r.palette.background.paper} 70%)`},children:[e.jsx(o,{sx:{width:40,height:40,borderRadius:2,bgcolor:"primary.lighter",color:"primary.main",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx(ae,{fontSize:"small"})}),e.jsxs(o,{children:[e.jsx(s,{variant:"subtitle1",sx:{fontWeight:700,color:"grey.800",lineHeight:1.2},children:"Client Directory"}),e.jsx(s,{variant:"caption",color:"text.secondary",children:"Browse, search and manage every client account"})]})]}),e.jsxs(a,{direction:{xs:"column",md:"row"},spacing:1.5,sx:{p:2},alignItems:{md:"center"},children:[e.jsx(Je,{size:"small",placeholder:"Search by name, phone, city, ID…",value:k,onChange:r=>{ie(r.target.value),C(0)},sx:{width:{xs:"100%",md:300}},InputProps:{startAdornment:e.jsx(Ye,{position:"start",children:e.jsx(_e,{fontSize:"small"})})}}),e.jsx(o,{sx:{flexGrow:1}}),!h&&e.jsxs(a,{direction:"row",spacing:1,alignItems:"center",children:[e.jsxs(s,{variant:"body2",color:"text.secondary",children:[L.length," ",L.length===1?"client":"clients"]}),e.jsx(Z,{size:"small",label:"live · doormile_clients",sx:{height:22,fontSize:"0.7rem",bgcolor:"success.lighter",color:"success.dark",fontWeight:600}})]})]}),e.jsx(o,{sx:{px:2,borderBottom:1,borderColor:"divider"},children:e.jsx(Ze,{value:Math.min(q,R.length-1),onChange:(r,n)=>{ye(n),C(0)},variant:"scrollable",scrollButtons:"auto",children:R.map((r,n)=>e.jsx(et,{label:e.jsx(we,{label:r.label,count:Ce[r.key]||0,active:q===n})},r.key))})}),g&&e.jsx(Ue,{severity:"error",sx:{m:2},action:e.jsx(p,{color:"inherit",size:"small",onClick:y,children:"Retry"}),children:g}),h?e.jsx(o,{sx:{display:"flex",justifyContent:"center",py:6},children:e.jsx(le,{})}):N.length===0?e.jsx(Ke,{title:"No clients found",caption:"Try a different tab or search term, or add a client."}):l?e.jsx(a,{spacing:1.5,sx:{p:2},children:N.map(r=>e.jsx(jt,{row:r,onEdit:n=>I({open:!0,mode:"edit",initial:n}),onDelete:n=>T(n)},r.id))}):e.jsx(tt,{children:e.jsxs(rt,{sx:{minWidth:900},children:[e.jsx(it,{children:e.jsxs(U,{sx:{"& th":{bgcolor:"grey.50",fontWeight:700,color:"grey.700",textTransform:"uppercase",fontSize:"0.72rem",letterSpacing:.4}},children:[e.jsx(x,{padding:"checkbox"}),e.jsx(x,{children:"ID"}),e.jsx(x,{children:"Client"}),e.jsx(x,{children:"Contact"}),e.jsx(x,{children:"Location"}),e.jsx(x,{align:"center",children:"Volume"}),e.jsx(x,{children:"Status"}),e.jsx(x,{align:"right",children:"Actions"})]})}),e.jsx(nt,{children:N.map((r,n)=>e.jsx(ft,{row:r,index:D*S+n,onEdit:$=>I({open:!0,mode:"edit",initial:$}),onDelete:$=>T($)},r.id))})]})}),e.jsx(Fe,{component:"div",count:L.length,page:D,onPageChange:(r,n)=>C(n),rowsPerPage:S,onRowsPerPageChange:r=>{ve(+r.target.value),C(0)},rowsPerPageOptions:[5,10,25]})]}),e.jsx(Qe,{open:O.open,mode:O.mode,initial:O.initial,onClose:()=>I({open:!1,mode:"add",initial:null}),onSaved:Se}),e.jsxs(Re,{open:!!z,onClose:W?void 0:()=>T(null),children:[e.jsx(Le,{children:"Delete client?"}),e.jsx(Be,{children:e.jsxs(Oe,{children:["This will permanently remove ",e.jsx("strong",{children:z==null?void 0:z.name})," from the doormile_clients collection. This cannot be undone."]})}),e.jsxs(Ae,{sx:{px:3,py:2},children:[e.jsx(p,{onClick:()=>T(null),disabled:W,children:"Cancel"}),e.jsx(p,{color:"error",variant:"contained",onClick:Ie,disabled:W,startIcon:W?e.jsx(le,{size:16,color:"inherit"}):null,children:"Delete"})]})]})]})}export{Ht as default};
|