"use strict";(self.webpackChunkmantis_material_react=self.webpackChunkmantis_material_react||[]).push([[8012],{34815:(e,s,t)=>{t.r(s),t.d(s,{default:()=>oe});var a=t(80045),i=t(89379),r=t(9950),l=t(98007),n=t(47113),c=t(48513),d=t(82215),o=t(99810),p=t(49029),u=t(33516),m=t(37119),h=t(2527),x=t.n(h);t(55392);x().PolylineOffset={translatePoint:(e,s,t)=>x().point(e.x+s*Math.cos(t),e.y+s*Math.sin(t)),offsetPointLine(e,s){const t=e.length;if(t<2)throw new Error("Line should be defined by at least 2 points");let a,i=e[0];const r=Math.PI/2,l=[];for(let n=1;n=0&&n<=1&&c>=0&&c<=1?x().point(e.x+c*i.x,e.y+c*i.y):null},segmentAsVector:(e,s)=>x().point(s.x-e.x,s.y-e.y),joinLineSegments(e){const s=[];let t=e[0].offset;s.push(t[0]);for(let a=1;ae.latLngToLayerPoint(s)));return this.offsetPoints(a,t).map((s=>e.layerPointToLatLng(s)))}};const v=x().Polyline.prototype._projectLatlngs;x().Polyline.prototype._projectLatlngs=function(e,s,t){const a=this.options.offset;if(!a||"number"!==typeof a)return v.call(this,e,s,t);if(!(e[0]instanceof x().LatLng)){for(let a=0;athis._map.latLngToLayerPoint(e))),r=x().PolylineOffset.offsetPoints(i,a);for(let l=0;lw[String(e||"").toLowerCase()]||{label:e||"Unknown",bg:"#64748b",fg:"#fff"},z=new Set(["delivered"]),M=new Set(["cancelled","skipped"]),C=["#2563eb","#dc2626","#16a34a","#ea580c","#9333ea","#0891b2","#ca8a04","#db2777","#0f766e","#7c3aed","#65a30d","#0284c7","#b91c1c","#15803d","#a16207","#86198f"],P=e=>C[(e%C.length+C.length)%C.length],A=e=>{if(null==e)return"";const s=["th","st","nd","rd"],t=e%100;return e+(s[(t-20)%10]||s[t]||s[0])};var D=t(44414);const q=function(e){let{focusedRider:s,compareDeltas:t,compareSummary:a,actualOrdered:i,focusedCompareStep:l,setFocusedCompareStep:n,sequenceOpen:c,setSequenceOpen:d,expandedSeqGroups:o,setExpandedSeqGroups:p,onClose:u}=e;const m=(0,r.useMemo)((()=>{const e=a,r=e.onTime+e.late,l=s.orders.reduce(((e,s)=>e+parseFloat(s.profit||0)),0),n=l<0,c=t.filter((e=>e.anomaly)),d=t.filter((e=>z.has(String(e.orderstatus||"").toLowerCase()))).length,o=t.filter((e=>M.has(String(e.orderstatus||"").toLowerCase()))).length,p=null==e.kmDeltaPct?"":e.kmDeltaPct>25?"is-over":e.kmDeltaPct<-5?"is-under":"",u=t.length||1,m=e.onTime+e.late||1,h=Math.round(d/u*60+e.onTime/m*25+(u-e.anomalies)/u*15),x=h>=85?"#16a34a":h>=65?"#f59e0b":"#dc2626",v=h>=85?"Excellent":h>=65?"Acceptable":"Needs review",j=t.filter((e=>e.actualTs)),g=j.reduce(((e,s)=>!e||s.actualTs.isBefore(e)?s.actualTs:e),null),N=j.reduce(((e,s)=>!e||s.actualTs.isAfter(e)?s.actualTs:e),null),f=g&&N?Math.max(0,N.diff(g,"minute")):0,b=t.length>1?Math.round(f/(t.length-1)):0,y=f>0?(e.actualKm/(f/60)).toFixed(1):null,k=t.filter((e=>!e.isLoading&&e.coordsCount>0)),S=k.filter((e=>null!=e.timeDeltaMin&&!e.anomaly)).sort(((e,s)=>e.timeDeltaMin-s.timeDeltaMin))[0]||null,w=k.filter((e=>e.anomaly)).sort(((e,s)=>{const t=Math.abs(e.kmDeltaPct||0)+(e.timeDeltaMin>0?e.timeDeltaMin:0);return Math.abs(s.kmDeltaPct||0)+(s.timeDeltaMin>0?s.timeDeltaMin:0)-t}))[0]||null,F=i.filter(((e,s)=>{var t;const a=null===(t=e.order)||void 0===t?void 0:t.step;return null!=a&&a!==s+1})),C=[];F.forEach((e=>{var s;const t=null===(s=e.order)||void 0===s?void 0:s.step,a=i.findIndex((s=>s.sequenceStep===e.sequenceStep))+1,r=a-t,l=C[C.length-1];l&&l.delta===r&&l.lastActualPos+1===a?(l.items.push({d:e,planned:t,actualPos:a,delta:r}),l.lastActualPos=a):C.push({delta:r,items:[{d:e,planned:t,actualPos:a,delta:r}],lastActualPos:a})}));const P={};s.orders.forEach((e=>{const s=e.trip_number||1;P[s]||(P[s]=[]),P[s].push(e)}));const A=Object.entries(P).sort(((e,s)=>{let[t]=e,[a]=s;return Number(t)-Number(a)})).map((e=>{let[s,t]=e;return{tNum:s,count:t.length,plannedKm:t.reduce(((e,s)=>e+parseFloat(s.kms||0)),0),actualKm:t.reduce(((e,s)=>e+parseFloat(s.actualkms||s.kms||0)),0),profit:t.reduce(((e,s)=>e+parseFloat(s.profit||0)),0),delivered:t.filter((e=>z.has(String(e.orderstatus||"").toLowerCase()))).length}}));return{sum:e,totalSteps:r,totalProfit:l,isLoss:n,deviations:c,delivered:d,skipped:o,stepDeltaPct:p,score:h,scoreColor:x,scoreLabel:v,firstDelivery:g,lastDelivery:N,activeMin:f,avgPerStop:b,avgSpeed:y,bestStep:S,worstStep:w,outOfOrderSteps:F,seqRuns:C,tripList:A}}),[s,t,a,i]),h=null!=l?t.find((e=>e.sequenceStep===l)):null,x=e=>{n((s=>s===e?null:e))},v=function(e){let s=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];const{d:t,planned:a,actualPos:i,delta:r}=e;return(0,D.jsxs)("li",{className:"cdp-seq-diff".concat(l===t.sequenceStep?" is-focused":"").concat(s?"":" is-nested"),onClick:()=>x(t.sequenceStep),children:[(0,D.jsx)("span",{className:"cdp-seq-diff-num",style:{background:P((a||t.sequenceStep)-1)},children:a||t.sequenceStep}),(0,D.jsxs)("div",{className:"cdp-seq-diff-body",children:[(0,D.jsx)("div",{className:"cdp-seq-diff-title",children:t.deliverycustomer||"Step ".concat(a||t.sequenceStep)}),(0,D.jsxs)("div",{className:"cdp-seq-diff-sub",children:["Visited ",(0,D.jsx)("strong",{children:A(i)})," ","\xb7 planned ",(0,D.jsx)("strong",{children:A(a)})]})]}),(0,D.jsx)("span",{className:"cdp-seq-diff-tag",children:r>0?"+".concat(r):"".concat(r)})]},"diff-".concat(t.sequenceStep))},{sum:j,totalSteps:g,totalProfit:N,isLoss:f,deviations:b,delivered:y,skipped:S,stepDeltaPct:w,score:C,scoreColor:q,scoreLabel:L,firstDelivery:E,lastDelivery:_,activeMin:O,avgPerStop:I,avgSpeed:R,bestStep:H,worstStep:T,outOfOrderSteps:K,seqRuns:V,tripList:Y}=m;return(0,D.jsxs)("aside",{id:"compare-data-panel",className:"compare-data-panel",children:[(0,D.jsxs)("div",{className:"cdp-head",children:[(0,D.jsxs)("div",{className:"cdp-head-title",children:[(0,D.jsx)("span",{className:"cdp-rider-dot",style:{background:s.color}}),(0,D.jsxs)("div",{className:"cdp-head-text",children:[(0,D.jsx)("div",{className:"cdp-rider-name",children:s.riderName}),(0,D.jsx)("div",{className:"cdp-head-badge",children:"PLANNED vs ACTUAL"})]})]}),(0,D.jsx)("button",{type:"button",className:"cdp-close",onClick:u,title:"Exit compare","aria-label":"Exit compare",children:(0,D.jsx)(k.m6K,{})})]}),(0,D.jsxs)("div",{className:"cdp-scroll",children:[(0,D.jsx)("section",{className:"cdp-section cdp-score-section",children:(0,D.jsxs)("div",{className:"cdp-score-wrap",children:[(0,D.jsx)("div",{className:"cdp-score-ring",style:{background:"conic-gradient(".concat(q," ").concat(3.6*C,"deg, rgba(15,23,42,0.08) 0deg)")},children:(0,D.jsxs)("div",{className:"cdp-score-inner",children:[(0,D.jsx)("div",{className:"cdp-score-value",style:{color:q},children:C}),(0,D.jsx)("div",{className:"cdp-score-unit",children:"/100"})]})}),(0,D.jsxs)("div",{className:"cdp-score-body",children:[(0,D.jsx)("div",{className:"cdp-score-label",style:{color:q},children:L}),(0,D.jsx)("div",{className:"cdp-score-title",children:"Compliance score"}),(0,D.jsxs)("div",{className:"cdp-score-sub",children:[y,"/",t.length," delivered",j.anomalies>0?" \xb7 ".concat(j.anomalies," deviation").concat(j.anomalies>1?"s":""):"",j.late>0?" \xb7 ".concat(j.late," late"):"",S>0?" \xb7 ".concat(S," skipped"):""]})]})]})}),(0,D.jsxs)("section",{className:"cdp-section",children:[(0,D.jsxs)("div",{className:"cdp-section-head",children:[(0,D.jsx)("span",{className:"cdp-section-icon",children:(0,D.jsx)(k.Zs6,{})}),(0,D.jsx)("span",{className:"cdp-section-title",children:"Day overview"})]}),(0,D.jsxs)("div",{className:"cdp-tiles",children:[(0,D.jsxs)("div",{className:"cdp-tile",children:[(0,D.jsxs)("div",{className:"cdp-tile-label",children:[(0,D.jsx)(k.xI$,{})," Distance"]}),(0,D.jsxs)("div",{className:"cdp-tile-value",children:[j.actualKm.toFixed(1),(0,D.jsx)("span",{className:"cdp-tile-unit",children:"km"})]}),(0,D.jsxs)("div",{className:"cdp-tile-sub",children:["planned ",j.plannedKm.toFixed(1)," km"]})]}),(0,D.jsxs)("div",{className:"cdp-tile".concat(j.anomalies>0?" is-warn":""),children:[(0,D.jsxs)("div",{className:"cdp-tile-label",children:[(0,D.jsx)(k.Wux,{})," Deviation"]}),(0,D.jsx)("div",{className:"cdp-tile-value ".concat(w),children:null!=j.kmDeltaPct?"".concat(j.kmDeltaPct>0?"+":"").concat(j.kmDeltaPct.toFixed(0),"%"):"\u2014"}),(0,D.jsx)("div",{className:"cdp-tile-sub",children:j.anomalies>0?"".concat(j.anomalies," flagged"):"within plan"})]}),(0,D.jsxs)("div",{className:"cdp-tile".concat(j.late>0?" is-warn":""),children:[(0,D.jsxs)("div",{className:"cdp-tile-label",children:[(0,D.jsx)(k.VP9,{})," On-time"]}),(0,D.jsxs)("div",{className:"cdp-tile-value",children:[j.onTime,g>0&&(0,D.jsxs)("span",{className:"cdp-tile-unit",children:["/",g]})]}),(0,D.jsx)("div",{className:"cdp-tile-sub",children:j.late>0?"".concat(j.late," late"):"all on schedule"})]}),(0,D.jsxs)("div",{className:"cdp-tile ".concat(f?"is-loss":"is-gain"),children:[(0,D.jsxs)("div",{className:"cdp-tile-label",children:[f?(0,D.jsx)(k.Rod,{}):(0,D.jsx)(k.imn,{})," ",f?"Loss":"Profit"]}),(0,D.jsxs)("div",{className:"cdp-tile-value",children:[f?"-":"","\u20b9",Math.abs(N).toFixed(0)]}),(0,D.jsxs)("div",{className:"cdp-tile-sub",children:[s.orders.length," ",1===s.orders.length?"order":"orders"," \xb7 ",y," delivered"]})]})]})]}),t.length>0&&(0,D.jsxs)("section",{className:"cdp-section cdp-seq-section",children:[(0,D.jsxs)("div",{className:"cdp-section-head cdp-section-head-clickable",onClick:()=>d((e=>!e)),role:"button","aria-expanded":c,title:c?"Collapse route sequence":"Expand route sequence",children:[(0,D.jsx)("span",{className:"cdp-section-icon",children:(0,D.jsx)(k.$G1,{})}),(0,D.jsx)("span",{className:"cdp-section-title",children:"Route sequence"}),(0,D.jsx)("span",{className:"cdp-seq-status".concat(K.length>0?" is-warn":" is-good"),children:K.length>0?"".concat(K.length," out of order"):"In order"}),(0,D.jsx)("span",{className:"cdp-seq-toggle".concat(c?" is-open":""),children:(0,D.jsx)(k.j1Q,{})})]}),c&&(0,D.jsx)("div",{className:"cdp-seq",children:K.length>0?(0,D.jsx)("ul",{className:"cdp-seq-diffs",children:V.map(((e,s)=>{if(1===e.items.length)return v(e.items[0]);const t=e.items[0],a=e.items[e.items.length-1],i=o.has(s),n=e.delta>0?"+".concat(e.delta):"".concat(e.delta),c=e.items.some((e=>e.d.sequenceStep===l));return(0,D.jsxs)(r.Fragment,{children:[(0,D.jsxs)("li",{className:"cdp-seq-diff is-group".concat(i?" is-expanded":"").concat(c?" is-focused":""),onClick:()=>{return e=s,void p((s=>{const t=new Set(s);return t.has(e)?t.delete(e):t.add(e),t}));var e},"aria-expanded":i,children:[(0,D.jsxs)("span",{className:"cdp-seq-group-num",children:[(0,D.jsx)("span",{className:"cdp-seq-group-num-bg",style:{background:"linear-gradient(135deg, ".concat(P((t.planned||1)-1),", ").concat(P((a.planned||1)-1),")")}}),(0,D.jsxs)("span",{className:"cdp-seq-group-num-label",children:[e.items.length,"\xd7"]})]}),(0,D.jsxs)("div",{className:"cdp-seq-diff-body",children:[(0,D.jsxs)("div",{className:"cdp-seq-diff-title",children:[e.items.length," consecutive steps shifted"," ",(0,D.jsx)("span",{className:"cdp-seq-group-delta",children:n})]}),(0,D.jsxs)("div",{className:"cdp-seq-diff-sub",children:["Planned ",A(t.planned),"\u2013",A(a.planned)," ","visited"," ",(0,D.jsxs)("strong",{children:[A(t.actualPos),"\u2013",A(a.actualPos)]})]})]}),(0,D.jsx)("span",{className:"cdp-seq-diff-tag",children:n}),(0,D.jsx)("span",{className:"cdp-seq-group-toggle".concat(i?" is-open":""),"aria-hidden":"true",children:(0,D.jsx)(k.j1Q,{})})]}),i&&(0,D.jsx)("li",{className:"cdp-seq-group-children-wrap",children:(0,D.jsx)("ul",{className:"cdp-seq-group-children",children:e.items.map((e=>v(e,!1)))})})]},"run-".concat(s,"-").concat(t.d.sequenceStep))}))}):(0,D.jsxs)("div",{className:"cdp-seq-good",children:[(0,D.jsx)(k.mU9,{})," Rider followed the planned route in order."]})})]}),(E||_)&&(0,D.jsxs)("section",{className:"cdp-section cdp-timing-section",children:[(0,D.jsxs)("div",{className:"cdp-section-head",children:[(0,D.jsx)("span",{className:"cdp-section-icon",children:(0,D.jsx)(k.pWE,{})}),(0,D.jsx)("span",{className:"cdp-section-title",children:"Timing"}),O>0&&(0,D.jsxs)("span",{className:"cdp-timing-active-tag",children:[(0,D.jsx)("span",{className:"cdp-timing-active-pulse"}),"Day window"]})]}),(0,D.jsxs)("div",{className:"cdp-timing-clock",children:[(0,D.jsxs)("div",{className:"cdp-clock-card is-start",children:[(0,D.jsxs)("div",{className:"cdp-clock-label",children:[(0,D.jsx)(k.WVj,{})," First delivery"]}),(0,D.jsxs)("div",{className:"cdp-clock-face",children:[(0,D.jsx)("span",{className:"cdp-clock-time",children:E?E.format("hh:mm"):"\u2014"}),(0,D.jsx)("span",{className:"cdp-clock-period",children:E?E.format("A"):""})]}),(0,D.jsx)("div",{className:"cdp-clock-caption",children:"Started"})]}),(0,D.jsxs)("div",{className:"cdp-clock-track","aria-hidden":"true",children:[(0,D.jsx)("span",{className:"cdp-clock-track-line"}),(0,D.jsx)("span",{className:"cdp-clock-track-dot is-start"}),(0,D.jsx)("span",{className:"cdp-clock-track-dot is-end"}),(0,D.jsxs)("div",{className:"cdp-clock-duration",children:[(0,D.jsx)("span",{className:"cdp-clock-duration-icon",children:(0,D.jsx)(k.DZH,{})}),(0,D.jsx)("span",{className:"cdp-clock-duration-val",children:O>0?O>=60?"".concat(Math.floor(O/60),"h ").concat(O%60,"m"):"".concat(O,"m"):"\u2014"}),(0,D.jsx)("span",{className:"cdp-clock-duration-sub",children:"active"})]})]}),(0,D.jsxs)("div",{className:"cdp-clock-card is-end",children:[(0,D.jsxs)("div",{className:"cdp-clock-label",children:[(0,D.jsx)(k.mU9,{})," Last delivery"]}),(0,D.jsxs)("div",{className:"cdp-clock-face",children:[(0,D.jsx)("span",{className:"cdp-clock-time",children:_?_.format("hh:mm"):"\u2014"}),(0,D.jsx)("span",{className:"cdp-clock-period",children:_?_.format("A"):""})]}),(0,D.jsx)("div",{className:"cdp-clock-caption",children:"Finished"})]})]}),(0,D.jsxs)("div",{className:"cdp-timing-stats",children:[(0,D.jsxs)("div",{className:"cdp-timing-stat",children:[(0,D.jsxs)("div",{className:"cdp-timing-stat-head",children:[(0,D.jsx)("div",{className:"cdp-timing-stat-icon",children:(0,D.jsx)(k.VP9,{})}),(0,D.jsxs)("div",{className:"cdp-timing-stat-body",children:[(0,D.jsxs)("div",{className:"cdp-timing-stat-value",children:[I>0?"".concat(I):"\u2014",I>0&&(0,D.jsx)("span",{className:"cdp-timing-stat-unit",children:"min"})]}),(0,D.jsx)("div",{className:"cdp-timing-stat-label",children:"Avg / stop"})]})]}),t.length>0&&(0,D.jsxs)("div",{className:"cdp-timing-stat-viz cdp-stops-dots","aria-hidden":"true",children:[Array.from({length:Math.min(t.length,12)}).map(((e,s)=>(0,D.jsx)("span",{className:"cdp-stop-dot"},"dot-".concat(s)))),(0,D.jsxs)("span",{className:"cdp-timing-stat-viz-label",children:[t.length," stop",1===t.length?"":"s"]})]})]}),null!=R&&(0,D.jsxs)("div",{className:"cdp-timing-stat",children:[(0,D.jsxs)("div",{className:"cdp-timing-stat-head",children:[(0,D.jsx)("div",{className:"cdp-timing-stat-icon",children:(0,D.jsx)(k.BJM,{})}),(0,D.jsxs)("div",{className:"cdp-timing-stat-body",children:[(0,D.jsxs)("div",{className:"cdp-timing-stat-value",children:[R,(0,D.jsx)("span",{className:"cdp-timing-stat-unit",children:"km/h"})]}),(0,D.jsx)("div",{className:"cdp-timing-stat-label",children:"Avg speed"})]})]}),(0,D.jsxs)("div",{className:"cdp-timing-stat-viz cdp-speed-gauge","aria-hidden":"true",children:[(0,D.jsx)("div",{className:"cdp-speed-gauge-track",children:(0,D.jsx)("div",{className:"cdp-speed-gauge-fill",style:{width:"".concat(Math.min(100,parseFloat(R)/60*100),"%")}})}),(0,D.jsxs)("div",{className:"cdp-speed-gauge-scale",children:[(0,D.jsx)("span",{children:"0"}),(0,D.jsx)("span",{children:"30"}),(0,D.jsx)("span",{children:"60 km/h"})]})]})]})]})]}),(H||T)&&(0,D.jsxs)("section",{className:"cdp-section",children:[(0,D.jsxs)("div",{className:"cdp-section-head",children:[(0,D.jsx)("span",{className:"cdp-section-icon",children:(0,D.jsx)(k.SeC,{})}),(0,D.jsx)("span",{className:"cdp-section-title",children:"Highlights"})]}),(0,D.jsxs)("div",{className:"cdp-highlights",children:[H&&(0,D.jsxs)("div",{className:"cdp-highlight is-best",onClick:()=>x(H.sequenceStep),role:"button",title:"Focus this step",children:[(0,D.jsx)("span",{className:"cdp-highlight-rail","aria-hidden":"true"}),(0,D.jsxs)("div",{className:"cdp-highlight-content",children:[(0,D.jsxs)("div",{className:"cdp-highlight-top",children:[(0,D.jsxs)("span",{className:"cdp-highlight-label",children:[(0,D.jsx)("span",{className:"cdp-highlight-chip",children:(0,D.jsx)(k.mU9,{})}),"Fastest stop"]}),(0,D.jsxs)("span",{className:"cdp-highlight-step-chip",style:{background:P(H.sequenceStep-1)},children:["Step ",H.sequenceStep]})]}),(0,D.jsx)("div",{className:"cdp-highlight-title",children:H.deliverycustomer||"Step ".concat(H.sequenceStep)}),(0,D.jsx)("div",{className:"cdp-highlight-meta",children:(0,D.jsx)("span",{className:"cdp-highlight-pill is-good",children:null!=H.timeDeltaMin?0===H.timeDeltaMin?"On schedule":"".concat(H.timeDeltaMin>0?"+":"").concat(H.timeDeltaMin," min vs plan"):"On schedule"})})]})]}),T&&(0,D.jsxs)("div",{className:"cdp-highlight is-worst",onClick:()=>x(T.sequenceStep),role:"button",title:"Focus this step",children:[(0,D.jsx)("span",{className:"cdp-highlight-rail","aria-hidden":"true"}),(0,D.jsxs)("div",{className:"cdp-highlight-content",children:[(0,D.jsxs)("div",{className:"cdp-highlight-top",children:[(0,D.jsxs)("span",{className:"cdp-highlight-label",children:[(0,D.jsx)("span",{className:"cdp-highlight-chip",children:(0,D.jsx)(k.Wux,{})}),"Biggest deviation"]}),(0,D.jsxs)("span",{className:"cdp-highlight-step-chip",style:{background:P(T.sequenceStep-1)},children:["Step ",T.sequenceStep]})]}),(0,D.jsx)("div",{className:"cdp-highlight-title",children:T.deliverycustomer||"Step ".concat(T.sequenceStep)}),(0,D.jsxs)("div",{className:"cdp-highlight-meta",children:[null!=T.kmDeltaPct&&(0,D.jsxs)("span",{className:"cdp-highlight-pill is-bad",children:[T.kmDeltaPct>0?"+":"",T.kmDeltaPct.toFixed(0),"% route"]}),null!=T.timeDeltaMin&&T.timeDeltaMin>0&&(0,D.jsxs)("span",{className:"cdp-highlight-pill is-bad",children:["+",T.timeDeltaMin,"m late"]})]})]})]})]})]}),Y.length>1&&(0,D.jsxs)("section",{className:"cdp-section",children:[(0,D.jsxs)("div",{className:"cdp-section-head",children:[(0,D.jsx)("span",{className:"cdp-section-icon",children:(0,D.jsx)(k.$G1,{})}),(0,D.jsxs)("span",{className:"cdp-section-title",children:["Trips (",Y.length,")"]})]}),(0,D.jsx)("div",{className:"cdp-trips",children:Y.map((e=>{const s=e.profit<0;return(0,D.jsxs)("div",{className:"cdp-trip",children:[(0,D.jsxs)("div",{className:"cdp-trip-head",children:[(0,D.jsxs)("span",{className:"cdp-trip-badge",children:["Trip ",e.tNum]}),(0,D.jsxs)("span",{className:"cdp-trip-meta",children:[e.delivered,"/",e.count," delivered"]})]}),(0,D.jsxs)("div",{className:"cdp-trip-stats",children:[(0,D.jsxs)("span",{title:"Distance",children:[(0,D.jsx)(k.xI$,{}),e.actualKm.toFixed(1),"km",(0,D.jsxs)("small",{children:[" / ",e.plannedKm.toFixed(1)]})]}),(0,D.jsxs)("span",{className:s?"is-over":"",title:s?"Loss":"Profit",children:[(0,D.jsx)(k.ohY,{}),s?"-":"","\u20b9",Math.abs(e.profit).toFixed(0)]})]})]},"trip-".concat(e.tNum))}))})]}),h&&(e=>{const s=P(h.sequenceStep-1),t=h.kmDelta>=0?"+":"",a=h.anomaly?"is-over":h.kmDelta<-.1?"is-under":"",i=null!=h.timeDeltaMin?h.timeDeltaMin>10?"is-over":h.timeDeltaMin<-2?"is-under":"":"",r=F(h.orderstatus),l=parseFloat((null===(e=h.order)||void 0===e?void 0:e.profit)||0);return(0,D.jsxs)("section",{className:"cdp-section",children:[(0,D.jsxs)("div",{className:"cdp-section-head",children:[(0,D.jsx)("span",{className:"cdp-section-icon",children:(0,D.jsx)(k.$G1,{})}),(0,D.jsxs)("span",{className:"cdp-section-title",children:["Step ",h.sequenceStep," details"]}),(0,D.jsx)("button",{type:"button",className:"cdp-section-clear",onClick:()=>n(null),title:"Clear step focus",children:"Show all"})]}),(0,D.jsxs)("div",{className:"compare-delta".concat(h.anomaly?" is-anomaly":""),children:[(0,D.jsxs)("div",{className:"compare-delta-title",children:[(0,D.jsx)("span",{className:"compare-delta-step-badge",style:{background:s},children:h.sequenceStep}),(0,D.jsxs)("div",{className:"compare-delta-title-text",children:[(0,D.jsx)("div",{className:"compare-delta-title-main",children:h.deliverycustomer||"Step ".concat(h.sequenceStep)}),(0,D.jsxs)("div",{className:"compare-delta-title-sub",children:[h.pickupcustomer?"from ".concat(h.pickupcustomer," \xb7 "):"","Order #",h.orderid]})]}),h.orderstatus&&(0,D.jsx)("span",{className:"compare-delta-status",style:{background:r.bg,color:r.fg},children:r.label})]}),(0,D.jsxs)("div",{className:"compare-delta-grid",children:[(0,D.jsxs)("div",{className:"compare-delta-cell".concat(h.anomaly?" is-anomaly":""),children:[(0,D.jsx)("span",{className:"compare-delta-cell-label",children:"Distance"}),(0,D.jsxs)("span",{className:"compare-delta-cell-val",children:[h.actualKm.toFixed(2)," ",(0,D.jsx)("span",{className:"compare-delta-cell-unit",children:"km"})]}),(0,D.jsxs)("span",{className:"compare-delta-cell-sub",children:["planned ",h.plannedKm.toFixed(2)," km"]})]}),(0,D.jsxs)("div",{className:"compare-delta-cell",children:[(0,D.jsx)("span",{className:"compare-delta-cell-label",children:"\u0394 Route"}),(0,D.jsxs)("span",{className:"compare-delta-cell-val ".concat(a),children:[t,h.kmDelta.toFixed(2)," km"]}),(0,D.jsx)("span",{className:"compare-delta-cell-sub",children:null!=h.kmDeltaPct?"".concat(t).concat(h.kmDeltaPct.toFixed(0),"% vs plan"):"no planned km"})]}),(0,D.jsxs)("div",{className:"compare-delta-cell",children:[(0,D.jsx)("span",{className:"compare-delta-cell-label",children:"Time"}),(0,D.jsx)("span",{className:"compare-delta-cell-val ".concat(i),children:null!=h.timeDeltaMin?"".concat(h.timeDeltaMin>0?"+":"").concat(h.timeDeltaMin," min"):"\u2014"}),(0,D.jsx)("span",{className:"compare-delta-cell-sub",children:h.actualTs&&h.expectedTs?"".concat(h.actualTs.format("HH:mm")," vs ").concat(h.expectedTs.format("HH:mm")):h.actualTs?"delivered ".concat(h.actualTs.format("HH:mm")):"in flight"})]}),!Number.isNaN(l)&&0!==l&&(0,D.jsxs)("div",{className:"compare-delta-cell".concat(l<0?" is-anomaly":""),children:[(0,D.jsx)("span",{className:"compare-delta-cell-label",children:l<0?"Loss":"Profit"}),(0,D.jsxs)("span",{className:"compare-delta-cell-val ".concat(l<0?"is-over":"is-under"),children:[l<0?"-":"","\u20b9",Math.abs(l).toFixed(0)]}),(0,D.jsx)("span",{className:"compare-delta-cell-sub",children:"order revenue"})]})]})]})]})})(),b.length>0&&(0,D.jsxs)("section",{className:"cdp-section",children:[(0,D.jsxs)("div",{className:"cdp-section-head",children:[(0,D.jsx)("span",{className:"cdp-section-icon cdp-icon-warn",children:(0,D.jsx)(k.ItP,{})}),(0,D.jsxs)("span",{className:"cdp-section-title",children:["Deviations (",b.length,")"]})]}),(0,D.jsx)("ul",{className:"cdp-dev-list",children:b.map((e=>{const s=P(e.sequenceStep-1),t=e.kmDelta>=0?"+":"";return(0,D.jsxs)("li",{className:"cdp-dev-item".concat(l===e.sequenceStep?" is-focused":""),onClick:()=>x(e.sequenceStep),children:[(0,D.jsx)("span",{className:"cdp-dev-num",style:{background:s},children:e.sequenceStep}),(0,D.jsxs)("div",{className:"cdp-dev-body",children:[(0,D.jsx)("div",{className:"cdp-dev-title",children:e.deliverycustomer||"Step ".concat(e.sequenceStep)}),(0,D.jsxs)("div",{className:"cdp-dev-meta",children:[null!=e.kmDeltaPct&&(0,D.jsxs)("span",{className:"cdp-dev-chip is-over",children:[t,e.kmDeltaPct.toFixed(0),"% route"]}),null!=e.timeDeltaMin&&e.timeDeltaMin>10&&(0,D.jsxs)("span",{className:"cdp-dev-chip is-over",children:["+",e.timeDeltaMin,"m late"]})]})]})]},"dev-".concat(e.sequenceStep))}))})]}),(0,D.jsxs)("section",{className:"cdp-section",children:[(0,D.jsxs)("div",{className:"cdp-section-head",children:[(0,D.jsx)("span",{className:"cdp-section-icon",children:(0,D.jsx)(k.EgJ,{})}),(0,D.jsxs)("span",{className:"cdp-section-title",children:["Steps (",t.length,")"]}),(0,D.jsxs)("span",{className:"cdp-section-sub",children:[y,"/",t.length," delivered"]})]}),(0,D.jsx)("ul",{className:"cdp-step-list",children:t.map((e=>{var s;const t=P(e.sequenceStep-1),a=String(e.orderstatus||"").toLowerCase(),i=z.has(a),r=M.has(a),n=i&&!e.anomaly,c=l===e.sequenceStep,d=F(e.orderstatus),o=parseFloat((null===(s=e.order)||void 0===s?void 0:s.profit)||0),p=e.kmDelta>=0?"+":"",u=null!=e.timeDeltaMin?e.timeDeltaMin>10?"is-over":e.timeDeltaMin<-2?"is-under":"":"",m=["cdp-step",c?"is-focused":"",e.anomaly?"is-anomaly":"",n?"is-correct":"",r?"is-skipped":"",e.isLoading?"is-loading":""].filter(Boolean).join(" ");return(0,D.jsxs)("li",{className:m,onClick:()=>x(e.sequenceStep),children:[(0,D.jsxs)("span",{className:"cdp-step-num",style:{background:t},children:[e.sequenceStep,n&&(0,D.jsx)("span",{className:"cdp-step-check",children:(0,D.jsx)(k.mU9,{})}),e.anomaly&&(0,D.jsx)("span",{className:"cdp-step-flag",children:(0,D.jsx)(k.ItP,{})})]}),(0,D.jsxs)("div",{className:"cdp-step-body",children:[(0,D.jsxs)("div",{className:"cdp-step-title-row",children:[(0,D.jsx)("span",{className:"cdp-step-title",children:e.deliverycustomer||"Step ".concat(e.sequenceStep)}),e.orderstatus&&(0,D.jsx)("span",{className:"cdp-step-status",style:{background:d.bg,color:d.fg},children:d.label})]}),(0,D.jsxs)("div",{className:"cdp-step-sub",children:[e.pickupcustomer?"from ".concat(e.pickupcustomer," \xb7 "):"","Order #",e.orderid]}),(0,D.jsxs)("div",{className:"cdp-step-deltas",children:[(0,D.jsxs)("span",{className:"cdp-step-delta",title:"Distance",children:[(0,D.jsx)(k.xI$,{}),e.actualKm.toFixed(1),"km",e.plannedKm>0&&(0,D.jsxs)("small",{className:e.anomaly?"is-over":"",children:[" ",p,e.kmDelta.toFixed(1)]})]}),(0,D.jsxs)("span",{className:"cdp-step-delta ".concat(u),title:"Delivery time",children:[(0,D.jsx)(k.VP9,{}),e.actualTs?e.actualTs.format("HH:mm"):"\u2014",null!=e.timeDeltaMin&&(0,D.jsxs)("small",{children:[" ",e.timeDeltaMin>0?"+":"",e.timeDeltaMin,"m"]})]}),!Number.isNaN(o)&&0!==o&&(0,D.jsxs)("span",{className:"cdp-step-delta".concat(o<0?" is-over":""),title:o<0?"Loss":"Profit",children:[(0,D.jsx)(k.ohY,{}),o<0?"-":"","\u20b9",Math.abs(o).toFixed(0)]})]})]})]},"step-".concat(e.sequenceStep))}))})]})]})]})},L=["_ts"],E="#6366f1",_="#10b981",O=e=>{const s=parseFloat(e);return Number.isFinite(s)?s:NaN},I=e=>{if(!e)return"";const s=String(e).trim();if(!s)return"";if(s.includes(",")){const e=s.split(",").map((e=>e.trim())).filter(Boolean);return 0===e.length?s:e.length<=2?e.join(", "):e.slice(-2).join(", ")}const t=s.split(/\s+/).filter(Boolean),a=t.length>6?t.slice(-6).join(" "):s;return a.length>40?"".concat(a.slice(0,40).trim(),"\u2026"):a},R=e=>Number.isFinite(O(e.droplat||e.deliverylat))&&Number.isFinite(O(e.droplon||e.deliverylong)),H=e=>e.pickuplat||e.pickuplatitude||e.pickup_lat,T=e=>e.pickuplong||e.pickuplongitude||e.picklongitude||e.pickup_lon,K=e=>Number.isFinite(O(H(e)))&&Number.isFinite(O(T(e))),V=[{id:"slot-1",startHour:8,endHour:12.5},{id:"slot-2",startHour:12+20/60,endHour:15},{id:"slot-3",startHour:15,endHour:19},{id:"slot-4",startHour:19,endHour:20},{id:"slot-5",startHour:20,endHour:24}],Y="dispatch.slots.v6",B=["dispatch.slots.v1","dispatch.slots.v2","dispatch.slots.v3","dispatch.slots.v4","dispatch.slots.v5"],W=(e,s)=>"Slot ".concat(e+1," \xb7 ").concat(U(s)),U=e=>{const s=Math.floor(e),t=Math.round(60*(e-s)),a=(s+11)%12+1,i=s>=12&&s<24?"PM":"AM";if(0===t)return"".concat(a," ").concat(i);const r=String(t).padStart(2,"0");return"".concat(a,":").concat(r," ").concat(i)},G=(e,s)=>s>=24?"After ".concat(U(e)):"".concat(U(e),"\u2013").concat(U(s)),J=V.map(((e,s)=>(0,i.A)((0,i.A)({},e),{},{label:W(s,e.startHour),range:G(e.startHour,e.endHour)}))),$=(e,s)=>{for(const t of s)if(e>=t.startHour&&e2&&void 0!==arguments[2]?arguments[2]:J;const t=((e,s)=>{const t=Z.find((e=>e.id===s))||Z[0];for(const a of t.keys)if(null!==e&&void 0!==e&&e[a])return e[a];return null})(e,arguments.length>1&&void 0!==arguments[1]?arguments[1]:"delivery");if(!t)return null;const a=String(t).trim();if(/^\d{4}-\d{2}-\d{2}$/.test(a))return null;const i=g()(t);return i.isValid()?$(i.hour()+i.minute()/60,s):null};function X(e){let{targetRef:s}=e;const t=(0,l.ko)();return(0,r.useEffect)((()=>(s.current=t,()=>{s.current=null})),[t]),null}function ee(e,s){const t=e=>e*Math.PI/180,a=t(e[0]),i=t(s[0]),r=t(s[0]-e[0]),l=t(s[1]-e[1]),n=Math.sin(r/2)**2+Math.cos(a)*Math.cos(i)*Math.sin(l/2)**2;return 12742*Math.asin(Math.min(1,Math.sqrt(n)))}function se(e){if(!Array.isArray(e)||e.length<2)return 0;let s=0;for(let t=1;t{let t=0,a=1/0;for(let i=0;i{const t=Math.max(s,i);a.push(e.slice(i,t+1)),i=t})),a}const ae=e=>{if(!e)return null;const s=g()(e);return s.isValid()?s.format("HH:mm:ss"):String(e)},ie=[{key:"assigntime",label:"Assigned"},{key:"acceptedtime",label:"Accepted"},{key:"arrivaltime",label:"Arrived"},{key:"pickuptime",label:"Pickup"},{key:"starttime",label:"Started"},{key:"deliverytime",label:"Delivered",final:!0}],re=e=>{const s=[...e.orders].sort(((e,s)=>{const t=e.trip_number||1,a=s.trip_number||1;return t!==a?t-a:(e.step||0)-(s.step||0)})),t=s.findIndex((e=>{const s=String(e.orderstatus||"").toLowerCase();return!z.has(s)&&!M.has(s)}));if(-1===t)return null;const a=s[t];if(!R(a))return null;const i=O(a.droplat||a.deliverylat),r=O(a.droplon||a.deliverylong);let l,n;const c=t>0?s[t-1]:null;if(c&&R(c))l=O(c.droplat||c.deliverylat),n=O(c.droplon||c.deliverylong);else{if(!K(a))return null;l=O(H(a)),n=O(T(a))}const d=(l+i)/2,o=(n+r)/2,p=s.filter((e=>z.has(String(e.orderstatus||"").toLowerCase()))).length;return{id:e.id,color:e.color,riderName:e.riderName,aerialLat:d,aerialLon:o,prevLat:l,prevLon:n,nextLat:i,nextLon:r,completedCount:p,totalCount:s.length,nextStep:a.step||t+1,nextCustomer:a.deliverycustomer||""}},le=e=>{const s=e.filter(R);if(!s.length)return[];const t=e.find(K),a=[];return t&&a.push([O(H(t)),O(T(t))]),s.forEach((e=>a.push([O(e.droplat||e.deliverylat),O(e.droplon||e.deliverylong)]))),a};delete x().Icon.Default.prototype._getIconUrl,x().Icon.Default.mergeOptions({iconRetinaUrl:"https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon-2x.png",iconUrl:"https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-icon.png",shadowUrl:"https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.7.1/images/marker-shadow.png"});const ne=["#0055FF","#00D82C","#FF6B00","#9D00FF","#FF00A8","#00C2B2","#FF9900","#FF0000"],ce=e=>{let{focusedItem:s,viewMode:t,orders:a,kitchens:i,locationKey:n}=e;const c=(0,l.ko)(),d=(0,r.useRef)(""),o=(0,r.useMemo)((()=>{const e=null!=n?"loc:".concat(n,"|"):"",r=e=>{let s=0,t=0,a=0;for(const i of e)Number.isFinite(i[0])&&Number.isFinite(i[1])&&(s+=i[0],t+=i[1],a+=1);return 0===a?"0":"".concat((s/a).toFixed(1),",").concat((t/a).toFixed(1))};if(s){var l,c,d;const t=null!==(l=null!==(c=null!==(d=s.id)&&void 0!==d?d:s.kitchenName)&&void 0!==c?c:s.name)&&void 0!==l?l:null!=s.lat?"".concat(s.lat,",").concat(s.lon):"item",a=s.orders?s.orders.length:0;return"".concat(e,"f|").concat(t,"|").concat(a)}const o=(i||[]).map((e=>[e.lat,e.lon])),p=r(o);if("kitchens"===t){const s=o.filter((e=>Number.isFinite(e[0])&&Number.isFinite(e[1]))).length;return"".concat(e,"k|").concat(s,"|").concat(p)}if("all"===t){const s=(a||[]).map((e=>[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]));return"".concat(e,"a|").concat(s.length,"|").concat(r(s))}return"".concat(e,"m|").concat(t||"","|").concat(o.length,"|").concat(p)}),[s,t,a,i,n]);return(0,r.useEffect)((()=>{if(d.current===o)return;let e=[];s?s.orders?(e=s.orders.map((e=>[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)])),s.orders.forEach((s=>e.push([O(H(s)),O(T(s))])))):e=[[s.lat,s.lon]]:"kitchens"===t?(e=(i||[]).filter((e=>Number.isFinite(e.lat)&&Number.isFinite(e.lon))).map((e=>[e.lat,e.lon])),0===e.length&&(e=(a||[]).map((e=>[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)])))):"all"===t?e=(a||[]).map((e=>[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)])):(e=(i||[]).filter((e=>Number.isFinite(e.lat)&&Number.isFinite(e.lon))).map((e=>[e.lat,e.lon])),0===e.length&&(e=(a||[]).map((e=>[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]))));const r=e.filter((e=>Number.isFinite(e[0])&&Number.isFinite(e[1])));if(r.length>0){const e=x().latLngBounds(r);if(e.isValid()){1===r.length||e.getNorthEast().equals(e.getSouthWest())?c.setView(r[0],15,{animate:!0,duration:.6}):c.flyToBounds(e,{padding:[60,60],duration:.6,maxZoom:16}),d.current=o}}else;}),[o,s,t,a,i,c]),null},de=e=>{let{children:s}=e;return(0,D.jsx)("span",{className:"ico-inline",style:{display:"inline-flex",alignItems:"center",verticalAlign:"-2px",marginRight:4},children:s})},oe=e=>{var s;let{data:t,embedded:l=!1,selectedRiderId:h,onRiderSelect:v,pulseOrderId:j}=e;const w=null!==t&&void 0!==t&&t.zones&&t.zones.length>0?"zones":"riders",[A,U]=(0,r.useState)(w),[ee,oe]=(0,r.useState)(new Set),[pe,ue]=(0,r.useState)(null),[me,he]=(0,r.useState)(null),[xe,ve]=(0,r.useState)(null),[je,ge]=(0,r.useState)(null),Ne=(0,r.useRef)({}),fe=(0,r.useRef)(new Set),be=(0,r.useRef)(null),ye=void 0!==h,[ke,Se]=(0,r.useState)(""),{data:we}=(0,N.I)({queryKey:["appLocations"],queryFn:S.aL,staleTime:3e5}),Fe="undefined"!==typeof window?localStorage.getItem("applocationid"):null,[ze,Me]=(0,r.useState)(null!=Fe?Number(Fe):0),[Ce,Pe]=(0,r.useState)(!1),Ae=(0,r.useRef)(null),[De,qe]=(0,r.useState)("delivery"),[Le,Ee]=(0,r.useState)(!1),_e=(0,r.useRef)(null),[Oe,Ie]=(0,r.useState)((()=>{if("undefined"===typeof window)return J;try{const e=window.localStorage.getItem(Y);if(!e)return J;const s=JSON.parse(e);return Array.isArray(s)&&s.length===V.length?s.map(((e,s)=>({id:e.id||"slot-".concat(s+1),startHour:Number(e.startHour)||0,endHour:Number(e.endHour)||24,label:W(s,Number(e.startHour)||0),range:G(Number(e.startHour)||0,Number(e.endHour)||24)}))):J}catch(e){return J}})),Re=Oe,[He,Te]=(0,r.useState)(!1),Ke=(0,r.useRef)(null);(0,r.useEffect)((()=>{if("undefined"!==typeof window)try{B.forEach((e=>window.localStorage.removeItem(e)))}catch(e){}}),[]);const Ve=(0,r.useRef)(!1);(0,r.useEffect)((()=>{if(Ve.current){if("undefined"!==typeof window)try{window.localStorage.setItem(Y,JSON.stringify(Oe.map((e=>{let{id:s,startHour:t,endHour:a}=e;return{id:s,startHour:t,endHour:a}}))))}catch(e){}}else Ve.current=!0}),[Oe]),(0,r.useEffect)((()=>{if(!Ce)return;const e=e=>{Ae.current&&!Ae.current.contains(e.target)&&Pe(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)}),[Ce]),(0,r.useEffect)((()=>{if(!Le)return;const e=e=>{_e.current&&!_e.current.contains(e.target)&&Ee(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)}),[Le]),(0,r.useEffect)((()=>{if(!He)return;const e=e=>{Ke.current&&!Ke.current.contains(e.target)&&Te(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)}),[He]);const[Ye,Be]=(0,r.useState)(null),[We,Ue]=(0,r.useState)(""),{data:Ge,isFetching:Je,isError:$e,error:Ze}=(0,N.I)({queryKey:["riderPeriodicLog",Ye],queryFn:()=>(0,S.ne)(Ye),enabled:"rider-info"===A&&null!=Ye,refetchInterval:"rider-info"===A&&null!=Ye&&3e4,refetchIntervalInBackground:!1,staleTime:15e3,refetchOnWindowFocus:!1}),Qe=(0,r.useMemo)((()=>{const e=parseFloat(null===Ge||void 0===Ge?void 0:Ge.latitude),s=parseFloat(null===Ge||void 0===Ge?void 0:Ge.longitude);return Number.isFinite(e)&&Number.isFinite(s)?{lat:e.toFixed(4),lon:s.toFixed(4)}:null}),[null===Ge||void 0===Ge?void 0:Ge.latitude,null===Ge||void 0===Ge?void 0:Ge.longitude]),{data:Xe}=(0,N.I)({queryKey:["reverseGeocode",null===Qe||void 0===Qe?void 0:Qe.lat,null===Qe||void 0===Qe?void 0:Qe.lon],queryFn:async()=>{const e=await fetch("https://nominatim.openstreetmap.org/reverse?lat=".concat(Qe.lat,"&lon=").concat(Qe.lon,"&format=json&zoom=16&addressdetails=1"),{headers:{Accept:"application/json"}});if(!e.ok)return null;const s=await e.json(),t=(null===s||void 0===s?void 0:s.address)||{};return{area:t.suburb||t.neighbourhood||t.village||t.hamlet||t.city_district||t.town||t.city||t.county||t.state||"",display:(null===s||void 0===s?void 0:s.display_name)||""}},enabled:"rider-info"===A&&!!Qe,staleTime:3e5,refetchOnWindowFocus:!1,retry:1}),es=(0,r.useMemo)((()=>{if(!we)return null;const e=we.find((e=>String(e.applocationid)===String(ze)));return(null===e||void 0===e?void 0:e.locationname)||null}),[we,ze]),[ss,ts]=(0,r.useState)({}),as=(0,r.useRef)({}),[is,rs]=(0,r.useState)({}),ls=(0,r.useRef)({}),[ns,cs]=(0,r.useState)(!1),[ds,os]=(0,r.useState)([]),[ps,us]=(0,r.useState)({}),ms=(0,r.useRef)(!1),[hs,xs]=(0,r.useState)(g()().format("YYYY-MM-DD")),[vs,js]=(0,r.useState)(!1),[gs,Ns]=(0,r.useState)((()=>g()(hs).isValid()?g()(hs).startOf("month"):g()().startOf("month"))),fs=(0,r.useRef)(null);(0,r.useEffect)((()=>{if(!vs)return;const e=e=>{fs.current&&(fs.current.contains(e.target)||js(!1))},s=e=>{"Escape"===e.key&&js(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",s),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",s)}}),[vs]),(0,r.useEffect)((()=>{if(vs){const e=g()(hs);e.isValid()&&Ns(e.startOf("month"))}}),[vs,hs]);const[bs,ys]=(0,r.useState)(!1),[ks,Ss]=(0,r.useState)("combined"),[ws,Fs]=(0,r.useState)(!0),[zs,Ms]=(0,r.useState)(!0),[Cs,Ps]=(0,r.useState)((()=>new Set)),As=(0,r.useRef)(!1),[Ds,qs]=(0,r.useState)(!1),Ls=(0,r.useRef)(!1),Es=(0,r.useRef)(!1),[_s,Os]=(0,r.useState)(null),Is=(0,r.useRef)(null),Rs=(0,r.useRef)(null);Rs.current||(Rs.current=x().canvas({padding:1.5,tolerance:5}));const{data:Hs}=(0,N.I)({queryKey:[ze,hs,""],queryFn:S.zb,refetchInterval:3e4,refetchIntervalInBackground:!1,staleTime:15e3,refetchOnWindowFocus:!1}),Ts=(0,r.useMemo)((()=>(Hs||[]).map((e=>{var s;const t=parseFloat(null===e||void 0===e?void 0:e.latitude),a=parseFloat(null===e||void 0===e?void 0:e.longitude);return Number.isFinite(t)&&Number.isFinite(a)?{id:String(null!==(s=e.userid)&&void 0!==s?s:""),userid:e.userid,username:e.username||"Rider #".concat(e.userid),status:String(e.status||"").toLowerCase(),contactno:e.contactno,orderid:e.orderid,logdate:e.logdate,lat:t,lon:a}:null})).filter(Boolean)),[Hs]),[Ks,Vs]=(0,r.useState)((()=>{const e=g()();return $(e.hour()+e.minute()/60,J)||J[0].id}));(0,r.useEffect)((()=>{var e;"all"!==Ks&&(Re.some((e=>e.id===Ks))||Vs((null===(e=Re[0])||void 0===e?void 0:e.id)||"all"))}),[Re,Ks]);const Ys=(0,r.useRef)(null),Bs=!t,Ws="undefined"!==typeof window&&localStorage.getItem("userid")||0,{data:Us,isFetching:Gs,isError:Js,fetchNextPage:$s,hasNextPage:Zs,isFetchingNextPage:Qs}=(0,f.q)({queryKey:["dispatchDeliveries",ze,Ws,"all",hs,hs,50,"",0,0,0],queryFn:S.tL,getNextPageParam:e=>{var s;return null!==(s=e.nextPage)&&void 0!==s?s:void 0},enabled:Bs});(0,r.useEffect)((()=>{Bs&&Zs&&!Qs&&$s()}),[Bs,Zs,Qs,$s]);const Xs=(0,r.useMemo)((()=>{const e=((null===Us||void 0===Us?void 0:Us.pages)||[]).flatMap((e=>e.rows||[])),s=new Set,t=[];for(const a of e){const e=null!=a.orderid?String(a.orderid):null;e&&s.has(e)||(e&&s.add(e),t.push(a))}return t}),[Us]),et=(0,r.useMemo)((()=>{const e=new Map;return Xs.forEach((s=>{const t=String(s.userid||s.rider_id||"");t&&"unassigned"!==t&&"0"!==t&&(e.has(t)||e.set(t,{id:t,riderName:s.ridername||s.rider_name||s.username||"Rider ".concat(t)}))})),Array.from(e.values()).sort(((e,s)=>String(e.riderName).localeCompare(String(s.riderName))))}),[Xs]),st=(0,r.useMemo)((()=>{const e={all:Xs.length};return Re.forEach((s=>{e[s.id]=0})),Xs.forEach((s=>{const t=Q(s,De,Re);t&&(e[t]=(e[t]||0)+1)})),e}),[Xs,De,Re]),tt=(0,r.useMemo)((()=>"all"===Ks?Xs:Xs.filter((e=>Q(e,De,Re)===Ks))),[Xs,Ks,De,Re]),at=(0,r.useMemo)((()=>{if(!Bs)return null;if(!tt.length)return{code:200,zone_summary:[],zones:[]};const e=e=>String(e||"").trim(),s={};tt.forEach((t=>{const a=e(t.deliverysuburb)||e(t.locationsuburb)||e(t.zone_name)||"Unzoned",i=a.toLowerCase(),r=String(t.userid||t.rider_id||"unassigned"),l=t.ridername||t.rider_name||t.username||("unassigned"===r?"Unassigned":"Rider ".concat(r));s[i]||(s[i]={zone_name:a,riders:{}}),s[i].riders[r]||(s[i].riders[r]={rider_id:r,rider_name:l,orders:[]}),s[i].riders[r].orders.push(t)}));const t=Object.values(s).map((e=>{const s=Object.values(e.riders).map((e=>{const s=[...e.orders].sort(((e,s)=>g()(e.deliverydate||e.assigntime||0).valueOf()-g()(s.deliverydate||s.assigntime||0).valueOf()));return(0,i.A)((0,i.A)({},e),{},{orders:s.map(((e,s)=>(0,i.A)((0,i.A)({},e),{},{trip_number:e.trip_number||1,step:e.step||s+1})))})}));return{zone_name:e.zone_name,riders:s}}));return{code:200,zone_summary:t.map((e=>{const s=e.riders.flatMap((e=>e.orders)),t=s.filter((e=>e.userid||e.rider_id)).length;return{zone_name:e.zone_name,total_orders:s.length,assigned_orders:t,unassigned_orders_count:s.length-t,active_riders_count:e.riders.filter((e=>"unassigned"!==e.rider_id)).length,total_delivery_kms:s.reduce(((e,s)=>e+parseFloat(s.actualkms||s.kms||0)),0),total_profit:s.reduce(((e,s)=>e+parseFloat(s.profit||0)),0)}})),zones:t}}),[Bs,tt]),it=(0,r.useMemo)((()=>{const e=t||at||{zones:[],zone_summary:[]},s=e.zones||[],a={};(e.zone_summary||[]).forEach((e=>{a[e.zone_name]=e}));const i=(e,s)=>{const t={};return e.forEach((e=>{const a=s(e);a&&(t[a]=(t[a]||0)+1)})),Object.entries(t).map((e=>{let[s,t]=e;return{name:s,count:t}})).sort(((e,s)=>s.count-e.count))};return s.map((e=>{var s,t,r,l;const n=a[e.zone_name]||{},c=(e.riders||[]).flatMap((e=>e.orders||[])),d=(e.riders||[]).filter((e=>e.rider_id&&"unassigned"!==e.rider_id)).length,o=i(c,(e=>e.deliverysuburb||e.locationsuburb)),p=i(c,(e=>e.pickupcustomer||e.kitchen_key)),u={};return c.forEach((e=>{const s=String(e.orderstatus||"unknown").toLowerCase();u[s]=(u[s]||0)+1})),{id:e.zone_name,name:e.zone_name,riders:e.riders||[],orders:c,totalOrders:null!==(s=n.total_orders)&&void 0!==s?s:c.length,activeRidersCount:null!==(t=n.active_riders_count)&&void 0!==t?t:d,totalKms:null!==(r=n.total_delivery_kms)&&void 0!==r?r:c.reduce(((e,s)=>e+parseFloat(s.actualkms||s.kms||0)),0),totalProfit:null!==(l=n.total_profit)&&void 0!==l?l:c.reduce(((e,s)=>e+parseFloat(s.profit||0)),0),suburbs:o,kitchens:p,statusCounts:u}}))}),[t,at]),{riders:rt,kitchens:lt,allOrders:nt,stats:ct}=(0,r.useMemo)((()=>{const e=[];((t||at||{zones:[],zone_summary:[]}).zones||[]).forEach((s=>{(s.riders||[]).forEach((t=>{t.orders.forEach((a=>{e.push((0,i.A)((0,i.A)({},a),{},{zone_name:s.zone_name,rider_name:t.rider_name,rider_id:t.rider_id}))}))}))}));const s={};e.forEach((e=>{const t=e.rider_id||e.userid||"unknown";s[t]||(s[t]={id:t,riderName:e.rider_name||e.username||e.rider||t,orders:[],color:ne[Object.keys(s).length%ne.length]}),s[t].orders.push(e)}));const a={};e.forEach((e=>{const s=e.pickupcustomer||e.kitchen_key||"Unknown",t=s.toLowerCase().trim();a[t]?!Number.isFinite(a[t].lat)&&K(e)&&(a[t].lat=O(H(e)),a[t].lon=O(T(e))):a[t]={id:t,kitchenName:s,lat:O(H(e)),lon:O(T(e)),orders:[],riders:new Set},a[t].orders.push(e),e.rider_id&&a[t].riders.add(e.rider_id)}));const r=e.reduce(((e,s)=>e+parseFloat(s.actualkms||s.kms||0)),0),l=e.reduce(((e,s)=>e+parseFloat(s.profit||0)),0);return{riders:Object.values(s).map((e=>(0,i.A)((0,i.A)({},e),{},{orders:[...e.orders].sort(((e,s)=>{const t=e.trip_number||1,a=s.trip_number||1;return t!==a?t-a:(e.step||0)-(s.step||0)}))}))).sort(((e,s)=>s.orders.length-e.orders.length)),kitchens:Object.values(a).sort(((e,s)=>s.orders.length-e.orders.length)),allOrders:e,stats:{totalOrders:e.length,totalKms:r,totalProfit:l,totalRiders:Object.keys(s).length}}}),[t,at]),dt=ye?h&&rt.find((e=>e.id===h))||null:pe,ot=(0,r.useCallback)((e=>{v&&v(e?e.id:null),ye||ue(e),ge(null)}),[ye,v]),pt=(0,r.useMemo)((()=>dt?{orders:dt.orders.length,riders:1,km:dt.orders.reduce(((e,s)=>e+parseFloat(s.actualkms||s.kms||0)),0),profit:dt.orders.reduce(((e,s)=>e+parseFloat(s.profit||0)),0),label:"Focused Rider"}:me?{orders:me.orders.length,riders:me.riders.size,km:me.orders.reduce(((e,s)=>e+parseFloat(s.actualkms||s.kms||0)),0),profit:me.orders.reduce(((e,s)=>e+parseFloat(s.profit||0)),0),label:"Focused Kitchen"}:{orders:ct.totalOrders,riders:ct.totalRiders,km:ct.totalKms,profit:ct.totalProfit,label:"Total Fleet"}),[dt,me,ct]),ut=(0,r.useMemo)((()=>rt.map(re).filter(Boolean)),[rt]),mt=(0,r.useMemo)((()=>{if(!dt)return[];const e=new Set;return dt.orders.forEach((s=>{null!=s.deliveryid&&""!==s.deliveryid&&0!==s.deliveryid&&e.add(String(s.deliveryid))})),Array.from(e)}),[dt]),ht=(0,b.E)({queries:mt.map((e=>({queryKey:["deliveryLogs",e],queryFn:async()=>{var s,t;const i=await y.A.get("".concat("https://jupiter.nearle.app/live/api/v3","/deliveries/getdeliverylogs/?deliveryid=").concat(e));return function(e){let s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(!Array.isArray(e)||0===e.length)return[];if(1===e.length)return[{lat:e[0].lat,lng:e[0].lng,logdate:e[0].logdate}];const t=null!=s.processNoise?s.processNoise:1e-9,a=null!=s.measurementNoise?s.measurementNoise:1e-7,i=e=>e._ts||(e.logdate?new Date(e.logdate).getTime():0),r=s=>{let r=e[0][s],l=0,n=1,c=0,d=0,o=1;const p=[r];let u=i(e[0]);for(let m=1;m({lat:l[s],lng:n[s],logdate:e.logdate,_ts:e._ts})))}(([null===i||void 0===i||null===(s=i.data)||void 0===s?void 0:s.details,null===i||void 0===i||null===(t=i.data)||void 0===t?void 0:t.data,null===i||void 0===i?void 0:i.data,i].find((e=>Array.isArray(e)))||[]).map((e=>{var s,t,a;const i=null!==e&&void 0!==e&&e.logdate?g()(e.logdate):null;return{lat:parseFloat(null!==(s=null===e||void 0===e?void 0:e.latitude)&&void 0!==s?s:null===e||void 0===e?void 0:e.lat),lng:parseFloat(null!==(t=null!==(a=null===e||void 0===e?void 0:e.longitude)&&void 0!==a?a:null===e||void 0===e?void 0:e.lng)&&void 0!==t?t:null===e||void 0===e?void 0:e.lon),logdate:null===e||void 0===e?void 0:e.logdate,_ts:i&&i.isValid()?i.valueOf():Number.MAX_SAFE_INTEGER}})).filter((e=>Number.isFinite(e.lat)&&Number.isFinite(e.lng))).sort(((e,s)=>e._ts-s._ts))).map((e=>{let{_ts:s}=e;return(0,a.A)(e,L)}))},enabled:bs&&null!=dt,staleTime:3e5,refetchOnWindowFocus:!1,retry:1})))}),xt=(0,r.useMemo)((()=>{if(!dt)return[];const e=e=>{const s=e.deliverytime||e.expecteddeliverytime;if(!s)return Number.MAX_SAFE_INTEGER;const t=g()(s);return t.isValid()?t.valueOf():Number.MAX_SAFE_INTEGER};return dt.orders.filter((e=>null!=e.deliveryid&&""!==e.deliveryid&&0!==e.deliveryid)).sort(((s,t)=>{const a=e(s)-e(t);return 0!==a?a:(s.step||0)-(t.step||0)})).map(((e,s)=>{const t=mt.indexOf(String(e.deliveryid)),a=t>=0?ht[t]:null;return{sequenceStep:s+1,orderid:e.orderid,deliveryid:e.deliveryid,deliverycustomer:e.deliverycustomer,pickupcustomer:e.pickupcustomer,step:e.step,tripNumber:e.trip_number||1,deliverytime:e.deliverytime||e.expecteddeliverytime,kms:parseFloat(e.actualkms||e.kms||0)||0,profit:parseFloat(e.profit||0)||0,orderstatus:e.orderstatus,isLoading:(null===a||void 0===a?void 0:a.isLoading)||(null===a||void 0===a?void 0:a.isFetching),isError:null===a||void 0===a?void 0:a.isError,coords:(null===a||void 0===a?void 0:a.data)||[]}}))}),[dt,mt,ht]),vt=(0,r.useMemo)((()=>dt?xt.map((e=>{const s=dt.orders.find((s=>String(s.deliveryid)===String(e.deliveryid))),t=parseFloat((null===s||void 0===s?void 0:s.kms)||0)||0,a=is[e.deliveryid];let i=0;Array.isArray(a)&&a.length>=2?i=se(a):null!=(null===s||void 0===s?void 0:s.actualkms)&&""!==s.actualkms?i=parseFloat(s.actualkms)||0:e.coords.length>=2&&(i=se(e.coords.map((e=>[e.lat,e.lng]))));const r=i-t,l=t>0?r/t*100:null,n=null!==s&&void 0!==s&&s.expecteddeliverytime?g()(s.expecteddeliverytime):null,c=null!==s&&void 0!==s&&s.deliverytime?g()(s.deliverytime):null,d=null!==n&&void 0!==n&&n.isValid()&&null!==c&&void 0!==c&&c.isValid()?c.diff(n,"minute"):null,o=t>0&&i>1.25*t||null!=d&&d>15;return{sequenceStep:e.sequenceStep,deliveryid:e.deliveryid,orderid:e.orderid,order:s,plannedKm:t,actualKm:i,kmDelta:r,kmDeltaPct:l,expectedTs:null!==n&&void 0!==n&&n.isValid()?n:null,actualTs:null!==c&&void 0!==c&&c.isValid()?c:null,timeDeltaMin:d,anomaly:o,orderstatus:e.orderstatus,deliverycustomer:e.deliverycustomer,pickupcustomer:null===s||void 0===s?void 0:s.pickupcustomer,isLoading:e.isLoading,coordsCount:e.coords.length}})):[]),[xt,dt,is]),jt=(0,r.useMemo)((()=>{if(0===vt.length)return{plannedKm:0,actualKm:0,kmDeltaPct:null,anomalies:0,late:0,onTime:0};const e=vt.filter((e=>!e.isLoading&&e.coordsCount>0)),s=e.reduce(((e,s)=>e+s.plannedKm),0),t=e.reduce(((e,s)=>e+s.actualKm),0);return{plannedKm:s,actualKm:t,kmDeltaPct:s>0?(t-s)/s*100:null,anomalies:e.filter((e=>e.anomaly)).length,late:e.filter((e=>null!=e.timeDeltaMin&&e.timeDeltaMin>5)).length,onTime:e.filter((e=>null!=e.timeDeltaMin&&e.timeDeltaMin<=5)).length}}),[vt]),gt=(0,r.useMemo)((()=>[...vt].sort(((e,s)=>{var t,a;return((null===(t=e.order)||void 0===t?void 0:t.step)||e.sequenceStep)-((null===(a=s.order)||void 0===a?void 0:a.step)||s.sequenceStep)}))),[vt]),Nt=(0,r.useMemo)((()=>[...vt].sort(((e,s)=>e.sequenceStep-s.sequenceStep))),[vt]),ft=(0,r.useMemo)((()=>{if(!bs||!_s||!dt)return null;const e=xt.find((e=>e.sequenceStep===_s));if(!e)return null;const s=dt.orders.find((s=>String(s.deliveryid)===String(e.deliveryid)));return s?{orders:[s],id:"cmp-step-".concat(_s,"-").concat(s.orderid)}:null}),[bs,_s,dt,xt]);(0,r.useEffect)((()=>{Os(null),Ps(new Set),Ss("combined")}),[bs,null===dt||void 0===dt?void 0:dt.id]),(0,r.useEffect)((()=>{!dt&&bs&&ys(!1)}),[dt,bs]),(0,r.useEffect)((()=>{As.current&&dt&&(As.current=!1,ys(!0))}),[dt]),(0,r.useEffect)((()=>{bs&&!Es.current?(Ls.current=Ds,qs(!0)):!bs&&Es.current&&qs(Ls.current),Es.current=bs}),[bs]);const bt=(0,r.useCallback)((async(e,s,t)=>{const a="".concat(e,"-").concat(s);if(void 0!==as.current[a])return;if(t.length<2)return;as.current[a]=null,ts((e=>(0,i.A)((0,i.A)({},e),{},{[a]:null})));const r=t.map((e=>"".concat(e[1],",").concat(e[0]))).join(";"),l="https://router.project-osrm.org/route/v1/driving/".concat(r,"?overview=full&geometries=geojson");try{const e=await fetch(l),s=await e.json();if(s.routes&&s.routes[0]){const e=s.routes[0].geometry.coordinates.map((e=>[e[1],e[0]]));as.current[a]=e,ts((s=>(0,i.A)((0,i.A)({},s),{},{[a]:e})))}else as.current[a]=!1,ts((e=>(0,i.A)((0,i.A)({},e),{},{[a]:!1})))}catch(n){console.error("OSRM Fetch error:",n),as.current[a]=!1,ts((e=>(0,i.A)((0,i.A)({},e),{},{[a]:!1})))}}),[]);(0,r.useEffect)((()=>{as.current={},ts({}),ls.current={},rs({})}),[hs,Ks]);const yt=(0,r.useCallback)((async(e,s)=>{if(void 0!==ls.current[e])return;if(!Array.isArray(s)||s.length<2)return;ls.current[e]=null,rs((s=>(0,i.A)((0,i.A)({},s),{},{[e]:null})));const t=s=>{ls.current[e]=s,rs((t=>(0,i.A)((0,i.A)({},t),{},{[e]:s})))},a=()=>{ls.current[e]=!1,rs((s=>(0,i.A)((0,i.A)({},s),{},{[e]:!1})))},r=(e,s)=>{if(e.length<=s)return e;const t=Math.ceil(e.length/s),a=e.filter(((e,s)=>s%t===0)),i=e[e.length-1];return a[a.length-1]!==i&&a.push(i),a};try{const e=r(s,90).map((e=>"".concat(e[1],",").concat(e[0]))).join(";"),a="https://router.project-osrm.org/match/v1/driving/".concat(e,"?overview=full&geometries=geojson&gaps=ignore&tidy=true"),i=await fetch(a),l=await i.json();if(l.matchings&&l.matchings.length>0){const e=l.matchings.flatMap((e=>{var s;return((null===(s=e.geometry)||void 0===s?void 0:s.coordinates)||[]).map((e=>[e[1],e[0]]))}));if(e.length>=2)return void t(e)}}catch(l){console.warn("OSRM Match error, trying route fallback:",l)}try{const e=r(s,25).map((e=>"".concat(e[1],",").concat(e[0]))).join(";"),i="https://router.project-osrm.org/route/v1/driving/".concat(e,"?overview=full&geometries=geojson"),l=await fetch(i),n=await l.json();if(n.routes&&n.routes[0]){const e=n.routes[0].geometry.coordinates.map((e=>[e[1],e[0]]));if(e.length>=2)return void t(e)}a()}catch(l){console.error("OSRM Route fallback error:",l),a()}}),[]);(0,r.useEffect)((()=>{bs&&dt&&xt.forEach((e=>{if(!e.deliveryid||e.coords.length<2)return;const s=e.coords.map((e=>[e.lat,e.lng]));yt(e.deliveryid,s)}))}),[xt,bs,dt,yt]),(0,r.useEffect)((()=>{ms.current=ns}),[ns]),(0,r.useEffect)((()=>{if(l)return;const e=()=>{const e=new Date;Se([e.getHours(),e.getMinutes(),e.getSeconds()].map((e=>String(e).padStart(2,"0"))).join(":"))},s=setInterval(e,1e3);return e(),()=>clearInterval(s)}),[l]),(0,r.useEffect)((()=>{oe(new Set(rt.map((e=>e.id))))}),[rt]),(0,r.useEffect)((()=>{rt.forEach((e=>{if(!ee.has(e.id))return;if(dt&&dt.id!==e.id)return;const s={};e.orders.forEach((e=>{const t=e.trip_number||1;s[t]||(s[t]=[]),s[t].push(e)})),Object.entries(s).forEach((s=>{let[t,a]=s;const i=[...a].sort(((e,s)=>(e.step||0)-(s.step||0))),r=le(i);r.length>=2&&bt(e.id,t,r)}))}))}),[rt,ee,dt,bt]),(0,r.useEffect)((()=>{ut.forEach((e=>{if(me)return;if(dt&&dt.id!==e.id)return;if(!ee.has(e.id))return;const s=[[e.prevLat,e.prevLon],[e.nextLat,e.nextLon]];bt(e.id,"seg-".concat(e.nextStep),s)}))}),[ut,dt,me,ee,bt]);const kt=(0,r.useRef)(null);(0,r.useEffect)((()=>{if(!Bs)return;const e=()=>{const e=g()();return e.hour()+e.minute()/60};null===kt.current&&(kt.current=e());const s=setInterval((()=>{const s=e(),t=$(kt.current,Re),a=$(s,Re);kt.current=s,a&&a!==t&&Vs((e=>e===t?a:e))}),3e4);return()=>clearInterval(s)}),[Bs,Re]),(0,r.useEffect)((()=>{ge(null)}),[null===me||void 0===me?void 0:me.id]),(0,r.useEffect)((()=>{const e=Ys.current;e&&"function"===typeof e.scrollIntoView&&e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"center"})}),[Ks]),(0,r.useEffect)((()=>{if(!je)return;const e=setTimeout((()=>{const e=Ne.current[String(je.orderid)];e&&"function"===typeof e.openPopup&&e.openPopup()}),350);return()=>clearTimeout(e)}),[je]);const St=function(e){let s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return x().divIcon({className:"",iconSize:s?[56,56]:[46,46],iconAnchor:s?[28,28]:[23,23],popupAnchor:[0,s?-30:-24],html:'
').concat((e||"K").charAt(0).toUpperCase(),"
")})},wt=e=>{var s;return(null===(s=rt.find((s=>s.id===e)))||void 0===s?void 0:s.color)||"#475569"},Ft=e=>{const s=F(e.orderstatus);return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)("div",{className:"pu-header",children:[(0,D.jsxs)("div",{className:"pu-header-top",children:[(0,D.jsxs)("div",{className:"pu-id",children:["ORDER #",e.orderid]}),e.orderstatus&&(0,D.jsx)("span",{className:"pu-status-chip",style:{background:s.bg,color:s.fg},children:s.label})]}),(0,D.jsxs)("div",{className:"pu-rider",children:[(0,D.jsx)(k.aVM,{})," ",(0,D.jsx)("span",{children:e.rider_name||e.ridername||"Unassigned"})]}),null!=e.deliveryid&&(0,D.jsxs)("div",{className:"pu-delivery-id",children:["Delivery #",e.deliveryid]})]}),(0,D.jsxs)("div",{className:"pu-body",children:[ie.some((s=>e[s.key]))&&(0,D.jsxs)("div",{className:"pu-section",children:[(0,D.jsx)("div",{className:"pu-section-label",children:"Timeline"}),(0,D.jsx)("div",{className:"pu-timeline",children:ie.map((s=>{const t=ae(e[s.key]);return t?(0,D.jsxs)("div",{className:"pu-tl-row ".concat(s.final?"delivered":""),children:[(0,D.jsx)("span",{className:"pu-tl-dot"}),(0,D.jsx)("span",{className:"pu-tl-label",children:s.label}),(0,D.jsx)("span",{className:"pu-tl-time",children:t})]},s.key):null}))})]}),(0,D.jsxs)("div",{className:"pu-section",children:[(0,D.jsx)("div",{className:"pu-section-label",children:"Details"}),(0,D.jsxs)("div",{className:"pu-details-grid",children:[e.pickupcustomer&&(0,D.jsxs)("div",{className:"pu-detail",children:[(0,D.jsx)("div",{className:"pu-detail-icon",children:(0,D.jsx)(k.NtI,{})}),(0,D.jsxs)("div",{className:"pu-detail-body",children:[(0,D.jsx)("div",{className:"pu-detail-label",children:"Kitchen"}),(0,D.jsx)("div",{className:"pu-detail-value",title:e.pickupcustomer,children:e.pickupcustomer})]})]}),(e.locationname||e.pickuplocation)&&(0,D.jsxs)("div",{className:"pu-detail",children:[(0,D.jsx)("div",{className:"pu-detail-icon",children:(0,D.jsx)(k.JFD,{})}),(0,D.jsxs)("div",{className:"pu-detail-body",children:[(0,D.jsx)("div",{className:"pu-detail-label",children:"Pickup"}),(0,D.jsx)("div",{className:"pu-detail-value",title:e.locationname||e.pickuplocation,children:e.locationname||e.pickuplocation})]})]}),e.zone_name&&(0,D.jsxs)("div",{className:"pu-detail",children:[(0,D.jsx)("div",{className:"pu-detail-icon",children:(0,D.jsx)(k.Cd7,{})}),(0,D.jsxs)("div",{className:"pu-detail-body",children:[(0,D.jsx)("div",{className:"pu-detail-label",children:"Zone"}),(0,D.jsx)("div",{className:"pu-detail-value",title:e.zone_name,children:e.zone_name})]})]}),(e.rider_id||e.userid)&&(0,D.jsxs)("div",{className:"pu-detail",children:[(0,D.jsx)("div",{className:"pu-detail-icon",children:(0,D.jsx)(k.aVM,{})}),(0,D.jsxs)("div",{className:"pu-detail-body",children:[(0,D.jsx)("div",{className:"pu-detail-label",children:"Rider ID"}),(0,D.jsxs)("div",{className:"pu-detail-value",children:["#",e.rider_id||e.userid]})]})]})]}),(null!=e.kms||null!=e.actualkms||null!=e.riderkms)&&(0,D.jsxs)("div",{className:"pu-distance-row",children:[null!=e.kms&&""!==e.kms&&(0,D.jsxs)("div",{className:"pu-distance-chip",children:[(0,D.jsx)("span",{className:"pu-distance-icon",children:(0,D.jsx)(k.xI$,{})}),(0,D.jsx)("span",{className:"pu-distance-label",children:"Planned"}),(0,D.jsxs)("span",{className:"pu-distance-value",children:[e.kms," km"]})]}),null!=e.actualkms&&""!==e.actualkms&&(0,D.jsxs)("div",{className:"pu-distance-chip",children:[(0,D.jsx)("span",{className:"pu-distance-icon",children:(0,D.jsx)(k.xI$,{})}),(0,D.jsx)("span",{className:"pu-distance-label",children:"Actual"}),(0,D.jsxs)("span",{className:"pu-distance-value",children:[e.actualkms," km"]})]}),null!=e.riderkms&&""!==e.riderkms&&(0,D.jsxs)("div",{className:"pu-distance-chip",children:[(0,D.jsx)("span",{className:"pu-distance-icon",children:(0,D.jsx)(k.bsz,{})}),(0,D.jsx)("span",{className:"pu-distance-label",children:"Rider"}),(0,D.jsxs)("span",{className:"pu-distance-value",children:[parseFloat(e.riderkms).toFixed(2)," km"]})]})]})]})]})]})};return(0,D.jsxs)("div",{className:"dispatch-container".concat(l?" embedded":"").concat(bs?" compare-open":""),children:[!l&&(0,D.jsxs)("div",{id:"hdr",children:[(0,D.jsxs)("div",{className:"logo",children:[(0,D.jsx)("div",{className:"logo-badge",children:"D"}),(0,D.jsx)("div",{className:"logo-name",children:"Dispatch"}),we&&we.length>0&&(0,D.jsxs)("div",{className:"logo-city-wrap",ref:Ae,children:[(0,D.jsxs)("button",{type:"button",className:"logo-city ".concat(Ce?"open":""),onClick:()=>Pe((e=>!e)),"aria-haspopup":"listbox","aria-expanded":Ce,title:"Switch hub",children:[(0,D.jsx)(k.JFD,{}),(0,D.jsx)("span",{className:"logo-city-text",children:es||"All locations"}),(0,D.jsx)(k.j1Q,{className:"logo-city-caret"})]}),Ce&&(0,D.jsx)("div",{className:"logo-city-menu",role:"listbox",children:we.map((e=>{const s=String(e.applocationid)===String(ze);return(0,D.jsxs)("button",{type:"button",role:"option","aria-selected":s,className:"logo-city-option ".concat(s?"active":""),onClick:()=>(e=>{if(Me(Number(e)),Pe(!1),"undefined"!==typeof window)try{localStorage.setItem("applocationid",String(e))}catch(s){}ot(null),he(null),ve(null)})(e.applocationid),children:[(0,D.jsx)(k.JFD,{className:"logo-city-option-icon"}),(0,D.jsx)("span",{children:e.locationname}),s&&(0,D.jsx)("span",{className:"logo-city-option-check",children:"\u2713"})]},e.applocationid)}))})]})]}),(0,D.jsxs)("div",{className:"hdr-stats",children:[(()=>{const e=pt.profit<0,s=Math.abs(pt.profit);return(0,D.jsxs)("span",{className:"strat-stat ".concat(e?"strat-stat-loss":"strat-stat-profit"),title:"".concat(e?"Loss":"Profit"," (").concat(pt.label,")"),children:[(0,D.jsx)("span",{className:"strat-stat-icon",children:e?(0,D.jsx)(k.Rod,{}):(0,D.jsx)(k.imn,{})}),(0,D.jsx)("span",{className:"strat-stat-label",children:e?"Loss":"Profit"}),(0,D.jsxs)("span",{className:"strat-stat-value",children:[e?"-":"","\u20b9",s.toFixed(0)]})]})})(),Bs&&(0,D.jsxs)(D.Fragment,{children:[Gs&&(0,D.jsxs)("span",{className:"live-status",children:[(0,D.jsx)("span",{className:"live-dot"})," Loading ",Xs.length?"\xb7 ".concat(Xs.length," loaded"):""]}),!Gs&&!Js&&(0,D.jsxs)("span",{className:"live-status live-status-ready",children:[(0,D.jsx)("span",{className:"live-dot ready"})," ",tt.length," orders",(0,D.jsxs)("span",{className:"live-status-sub",children:[" / ",Xs.length," total"]})]}),Js&&(0,D.jsxs)("span",{className:"live-status live-status-error",children:[(0,D.jsx)("span",{className:"live-dot error"})," Failed to load"]}),(()=>{const e=g()().startOf("day"),s=e.format("YYYY-MM-DD"),t=g()(hs),a=hs===s,i=t.isAfter(e,"day"),r=s=>{if(!s)return;const t=s.format("YYYY-MM-DD");t!==hs?s.isAfter(e,"day")||(xs(t),ot(null),he(null),ve(null),js(!1)):js(!1)},l=gs.startOf("month"),n=l.subtract(l.day(),"day"),c=Array.from({length:42},((e,s)=>n.add(s,"day"))),d=!gs.add(1,"month").startOf("month").isAfter(e,"month");return(0,D.jsxs)("div",{className:"date-chip".concat(a?" is-today":"").concat(vs?" is-open":""),ref:fs,children:[(0,D.jsx)("button",{type:"button",className:"date-chip-nav",onClick:()=>r(t.subtract(1,"day")),"aria-label":"Previous day",title:"Previous day",children:(0,D.jsx)(k.E_E,{})}),(0,D.jsxs)("button",{type:"button",className:"date-chip-main",onClick:()=>js((e=>!e)),"aria-haspopup":"dialog","aria-expanded":vs,children:[(0,D.jsx)("span",{className:"date-chip-icon","aria-hidden":"true",children:(0,D.jsx)(k.dDC,{})}),(0,D.jsxs)("span",{className:"date-chip-text",children:[(0,D.jsxs)("span",{className:"date-chip-label",children:["Date",a&&(0,D.jsx)("span",{className:"date-chip-today-pill",children:"Today"})]}),(0,D.jsx)("span",{className:"date-chip-value",children:t.isValid()?t.format("ddd, MMM D, YYYY"):"\u2014"})]}),(0,D.jsx)("span",{className:"date-chip-chevron".concat(vs?" is-open":""),"aria-hidden":"true",children:(0,D.jsx)(k.j1Q,{})})]}),(0,D.jsx)("button",{type:"button",className:"date-chip-nav",onClick:()=>{a||i||r(t.add(1,"day"))},disabled:a||i,"aria-label":"Next day",title:a?"You're viewing today":"Next day",children:(0,D.jsx)(k.xVu,{})}),vs&&(0,D.jsxs)("div",{className:"date-cal-popover",role:"dialog","aria-label":"Pick a date",children:[(0,D.jsxs)("div",{className:"date-cal-header",children:[(0,D.jsx)("button",{type:"button",className:"date-cal-nav",onClick:()=>Ns((e=>e.subtract(1,"month"))),"aria-label":"Previous month",children:(0,D.jsx)(k.E_E,{})}),(0,D.jsx)("div",{className:"date-cal-title",children:gs.format("MMMM YYYY")}),(0,D.jsx)("button",{type:"button",className:"date-cal-nav",onClick:()=>{const s=gs.add(1,"month");s.startOf("month").isAfter(e,"month")||Ns(s)},disabled:!d,"aria-label":"Next month",children:(0,D.jsx)(k.xVu,{})})]}),(0,D.jsx)("div",{className:"date-cal-weekdays",children:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map((e=>(0,D.jsx)("div",{className:"date-cal-weekday",children:e},e)))}),(0,D.jsx)("div",{className:"date-cal-grid",children:c.map((t=>{const a=t.month()===gs.month(),i=t.format("YYYY-MM-DD")===hs,l=t.format("YYYY-MM-DD")===s,n=t.isAfter(e,"day"),c=["date-cal-day",!a&&"is-other-month",i&&"is-selected",l&&"is-today",n&&"is-disabled"].filter(Boolean).join(" ");return(0,D.jsx)("button",{type:"button",className:c,disabled:n,onClick:()=>r(t),"aria-current":l?"date":void 0,"aria-pressed":i,children:t.date()},t.format("YYYY-MM-DD"))}))}),(0,D.jsxs)("div",{className:"date-cal-presets",children:[(0,D.jsx)("button",{type:"button",className:"date-cal-preset",onClick:()=>r(e),children:"Today"}),(0,D.jsx)("button",{type:"button",className:"date-cal-preset",onClick:()=>r(e.subtract(1,"day")),children:"Yesterday"}),(0,D.jsx)("button",{type:"button",className:"date-cal-preset",onClick:()=>r(e.subtract(7,"day")),children:"\u22127 days"})]})]})]})})()]})]}),(0,D.jsx)("div",{id:"clock",children:ke})]}),(0,D.jsxs)("div",{id:"strat-row",children:[(0,D.jsxs)("button",{className:"sbt ".concat("kitchens"===A?"active":""),onClick:()=>{U("kitchens"),ot(null),he(null),ve(null)},children:[(0,D.jsx)("span",{className:"sbt-icon",children:(0,D.jsx)(k.JFD,{})})," By Location"]}),(0,D.jsxs)("button",{className:"sbt ".concat("zones"===A?"active":""),onClick:()=>{U("zones"),ot(null),he(null),ve(null)},children:[(0,D.jsx)("span",{className:"sbt-icon",children:(0,D.jsx)(k.Cd7,{})})," By Zone"]}),(0,D.jsxs)("button",{className:"sbt ".concat("riders"===A?"active":""),onClick:()=>{U("riders"),ot(null),he(null),ve(null)},children:[(0,D.jsx)("span",{className:"sbt-icon",children:(0,D.jsx)(k.bsz,{})})," By Rider"]}),(0,D.jsxs)("button",{className:"sbt ".concat("all"===A?"active":""),onClick:()=>{U("all"),ot(null),he(null),ve(null)},children:[(0,D.jsx)("span",{className:"sbt-icon",children:(0,D.jsx)(k.Zs6,{})})," All Routes"]}),(0,D.jsxs)("button",{type:"button",className:"sbt sbt-rider-info ".concat("rider-info"===A?"active":""),onClick:()=>{U("rider-info"),ot(null),he(null),ve(null)},title:"Live GPS / battery / status snapshot for a rider",children:[(0,D.jsx)("span",{className:"sbt-icon",children:(0,D.jsx)(k.k4P,{})})," Rider Info"]})]}),Bs&&"rider-info"!==A&&(0,D.jsxs)("div",{id:"batch-row",children:[(0,D.jsx)("span",{className:"batch-label",children:"Slot"}),(0,D.jsxs)("div",{className:"time-field-wrap",ref:_e,children:[(0,D.jsxs)("button",{type:"button",className:"time-field-btn ".concat(Le?"open":""),onClick:()=>Ee((e=>!e)),"aria-haspopup":"listbox","aria-expanded":Le,title:"Bucket slots by this timestamp",children:[(0,D.jsx)(k.VP9,{}),(0,D.jsx)("span",{className:"time-field-text",children:(null===(s=Z.find((e=>e.id===De)))||void 0===s?void 0:s.label)||"Delivery"}),(0,D.jsx)(k.j1Q,{className:"time-field-caret"})]}),Le&&(0,D.jsx)("div",{className:"time-field-menu",role:"listbox",children:Z.map((e=>{const s=e.id===De;return(0,D.jsxs)("button",{type:"button",role:"option","aria-selected":s,className:"time-field-option ".concat(s?"active":""),onClick:()=>{qe(e.id),Ee(!1)},children:[(0,D.jsx)(k.VP9,{className:"time-field-option-icon"}),(0,D.jsx)("span",{children:e.label}),s&&(0,D.jsx)("span",{className:"time-field-option-check",children:"\u2713"})]},e.id)}))})]}),(0,D.jsxs)("div",{className:"slot-edit-wrap",ref:Ke,children:[(0,D.jsxs)("button",{type:"button",className:"slot-edit-btn ".concat(He?"open":""),onClick:()=>Te((e=>!e)),"aria-haspopup":"dialog","aria-expanded":He,title:"Adjust slot timings",children:[(0,D.jsx)(k.VP9,{}),(0,D.jsx)("span",{children:"Edit slots"})]}),He&&(0,D.jsxs)("div",{className:"slot-edit-panel",role:"dialog","aria-label":"Edit slot timings",children:[(0,D.jsxs)("div",{className:"slot-edit-head",children:[(0,D.jsx)("div",{className:"slot-edit-title",children:"Slot timings"}),(0,D.jsx)("div",{className:"slot-edit-sub",children:"Hours are 0\u201324 (24h clock). Half-hour steps allowed (e.g. 12.5 = 12:30). Start < End."})]}),(0,D.jsx)("div",{className:"slot-edit-list",children:Oe.map(((e,s)=>(0,D.jsxs)("div",{className:"slot-edit-row",children:[(0,D.jsx)("span",{className:"slot-edit-idx",children:s+1}),(0,D.jsxs)("label",{className:"slot-edit-field",children:[(0,D.jsx)("span",{className:"slot-edit-field-label",children:"Start"}),(0,D.jsx)("input",{type:"number",min:0,max:23.5,step:.5,value:e.startHour,onChange:e=>{const t=parseFloat(e.target.value),a=Number.isFinite(t)?Math.round(2*t)/2:0,r=Math.max(0,Math.min(23.5,a));Ie((e=>e.map(((e,t)=>t===s?(0,i.A)((0,i.A)({},e),{},{startHour:r,label:W(t,r),range:G(r,e.endHour)}):e))))}})]}),(0,D.jsxs)("label",{className:"slot-edit-field",children:[(0,D.jsx)("span",{className:"slot-edit-field-label",children:"End"}),(0,D.jsx)("input",{type:"number",min:.5,max:24,step:.5,value:e.endHour,onChange:e=>{const t=parseFloat(e.target.value),a=Number.isFinite(t)?Math.round(2*t)/2:.5,r=Math.max(.5,Math.min(24,a));Ie((e=>e.map(((e,t)=>t===s?(0,i.A)((0,i.A)({},e),{},{endHour:r,range:G(e.startHour,r)}):e))))}})]}),(0,D.jsx)("span",{className:"slot-edit-preview",title:"".concat(W(s,e.startHour)," \u2014 ").concat(G(e.startHour,e.endHour)),children:G(e.startHour,e.endHour)}),(0,D.jsx)("button",{type:"button",className:"slot-edit-remove",onClick:()=>Ie((e=>e.filter(((e,t)=>t!==s)).map(((e,s)=>(0,i.A)((0,i.A)({},e),{},{id:"slot-".concat(s+1),label:W(s,e.startHour)}))))),disabled:Oe.length<=1,title:Oe.length<=1?"Keep at least one slot":"Remove this slot",children:"\xd7"})]},e.id)))}),(0,D.jsxs)("div",{className:"slot-edit-actions",children:[(0,D.jsx)("button",{type:"button",className:"slot-edit-add",onClick:()=>Ie((e=>{var s;const t=e[e.length-1],a=Math.min(23,null!==(s=null===t||void 0===t?void 0:t.endHour)&&void 0!==s?s:0),i=Math.min(24,a+1),r=e.length;return[...e,{id:"slot-".concat(r+1),startHour:a,endHour:i,label:W(r,a),range:G(a,i)}]})),children:"+ Add slot"}),(0,D.jsx)("button",{type:"button",className:"slot-edit-reset",onClick:()=>Ie(J),children:"Reset to defaults"})]})]})]}),(0,D.jsx)("div",{className:"batch-scroll",children:Re.map((e=>{var s;const t=Ks===e.id;return(0,D.jsxs)("button",{ref:t?Ys:null,className:"batch-btn batch-slot ".concat(t?"active":""),onClick:()=>{Vs(e.id),ot(null),he(null),ve(null)},title:"".concat(e.label," (").concat(e.range,")"),children:[(0,D.jsx)("span",{className:"batch-btn-label",children:e.label}),(0,D.jsx)("span",{className:"batch-btn-count",children:null!==(s=st[e.id])&&void 0!==s?s:0})]},e.id)}))})]}),"rider-info"===A?(0,D.jsxs)("div",{className:"rider-info-mode",children:[(0,D.jsxs)("div",{className:"ri-sidebar",children:[(0,D.jsxs)("div",{className:"ri-sb-head",children:[(0,D.jsx)("div",{className:"ri-sb-title",children:"Riders"}),(0,D.jsxs)("div",{className:"ri-sb-sub",children:[et.length," ",1===et.length?"rider":"riders"," today"]})]}),(0,D.jsxs)("div",{className:"ri-search",children:[(0,D.jsx)(k.gZ7,{className:"ri-search-icon"}),(0,D.jsx)("input",{type:"text",className:"ri-search-input",placeholder:"Search by name or ID",value:We,onChange:e=>Ue(e.target.value)})]}),(()=>{const e=We.trim().toLowerCase(),s=et.filter((s=>!e||(String(s.riderName||"").toLowerCase().includes(e)||String(s.id).includes(e))));return 0===s.length?(0,D.jsx)("div",{className:"ri-empty",children:We?'No riders match "'.concat(We,'"'):"No riders have orders today"}):(0,D.jsx)("div",{className:"ri-rider-list",children:s.map((e=>{const s=String(Ye)===String(e.id);return(0,D.jsxs)("button",{type:"button",className:"ri-rider-item ".concat(s?"active":""),onClick:()=>Be(e.id),children:[(0,D.jsx)("span",{className:"ri-rider-dot",style:{background:wt(e.id)}}),(0,D.jsxs)("span",{className:"ri-rider-info-block",children:[(0,D.jsx)("span",{className:"ri-rider-name",children:e.riderName}),(0,D.jsxs)("span",{className:"ri-rider-meta",children:["#",e.id]})]}),(0,D.jsx)("span",{className:"ri-rider-arrow",children:"\u2192"})]},e.id)}))})})()]}),(0,D.jsx)("div",{className:"ri-main",children:null==Ye?(0,D.jsxs)("div",{className:"ri-placeholder",children:[(0,D.jsx)("div",{className:"ri-placeholder-icon",children:(0,D.jsx)(k.k4P,{})}),(0,D.jsx)("div",{className:"ri-placeholder-title",children:"Pick a rider"}),(0,D.jsx)("div",{className:"ri-placeholder-sub",children:"Select a rider from the list on the left to see their live GPS, battery, connection, and current order snapshot."})]}):(0,D.jsxs)(D.Fragment,{children:[Je&&!Ge&&(0,D.jsx)("div",{className:"ri-loading",children:"Loading rider snapshot\u2026"}),$e&&(0,D.jsxs)("div",{className:"ri-error",children:["Couldn't load this rider's log. ",(null===Ze||void 0===Ze?void 0:Ze.message)||""]}),Ge&&(()=>{const e=Ge,s=parseFloat(e.latitude),t=parseFloat(e.longitude),a=Number.isFinite(s)&&Number.isFinite(t),i=parseInt(String(e.battery||"").replace("%",""),10),r=Number.isFinite(i)&&i<=20,l=parseFloat(e.speed),d=String(e.status||"").toLowerCase();return(0,D.jsxs)("div",{className:"ri-snapshot",children:[(0,D.jsxs)("div",{className:"ri-snap-head",children:[(0,D.jsx)("div",{className:"ri-snap-name",children:e.username||"Rider #".concat(e.userid)}),(0,D.jsxs)("div",{className:"ri-snap-meta",children:[(0,D.jsxs)("span",{children:["#",e.userid]}),e.status&&(0,D.jsx)("span",{className:"ri-status ri-status-".concat(d),children:e.status}),(0,D.jsxs)("span",{className:"ri-live ".concat(Je?"is-refetching":""),children:[(0,D.jsx)("span",{className:"ri-live-dot"}),Je?"Updating\u2026":"Live"]})]}),e.logdate&&(0,D.jsxs)("div",{className:"ri-snap-time",children:[(0,D.jsx)(k.VP9,{})," Last seen ",e.logdate]})]}),(0,D.jsxs)("div",{className:"ri-snap-grid",children:[(0,D.jsxs)("div",{className:"ri-stat ".concat(r?"ri-stat-warn":""),children:[(0,D.jsx)("div",{className:"ri-stat-icon",children:(0,D.jsx)(k.wZm,{})}),(0,D.jsxs)("div",{className:"ri-stat-body",children:[(0,D.jsx)("div",{className:"ri-stat-label",children:"Battery"}),(0,D.jsxs)("div",{className:"ri-stat-value",children:[e.battery||"\u2014",e.is_charging&&(0,D.jsx)("span",{className:"ri-stat-tag",children:"Charging"})]})]})]}),(0,D.jsxs)("div",{className:"ri-stat",children:[(0,D.jsx)("div",{className:"ri-stat-icon",children:(0,D.jsx)(k.Xh5,{})}),(0,D.jsxs)("div",{className:"ri-stat-body",children:[(0,D.jsx)("div",{className:"ri-stat-label",children:"Connection"}),(0,D.jsx)("div",{className:"ri-stat-value",children:e.connection||"\u2014"})]})]}),(0,D.jsxs)("div",{className:"ri-stat",children:[(0,D.jsx)("div",{className:"ri-stat-icon",children:(0,D.jsx)(k.HPi,{})}),(0,D.jsxs)("div",{className:"ri-stat-body",children:[(0,D.jsx)("div",{className:"ri-stat-label",children:"GPS Accuracy"}),(0,D.jsx)("div",{className:"ri-stat-value",children:e.accuracy?"".concat(e.accuracy," m"):"\u2014"})]})]}),(0,D.jsxs)("div",{className:"ri-stat",children:[(0,D.jsx)("div",{className:"ri-stat-icon",children:(0,D.jsx)(k.o8z,{})}),(0,D.jsxs)("div",{className:"ri-stat-body",children:[(0,D.jsx)("div",{className:"ri-stat-label",children:"Location Service"}),(0,D.jsx)("div",{className:"ri-stat-value",children:e.location_service||"\u2014"})]})]}),(0,D.jsxs)("div",{className:"ri-stat",children:[(0,D.jsx)("div",{className:"ri-stat-icon",children:(0,D.jsx)(k.BJM,{})}),(0,D.jsxs)("div",{className:"ri-stat-body",children:[(0,D.jsx)("div",{className:"ri-stat-label",children:"Speed"}),(0,D.jsx)("div",{className:"ri-stat-value",children:Number.isFinite(l)?"".concat(l.toFixed(2)," km/h"):"\u2014"})]})]}),(0,D.jsxs)("div",{className:"ri-stat",children:[(0,D.jsx)("div",{className:"ri-stat-icon",children:(0,D.jsx)(k.bqQ,{})}),(0,D.jsxs)("div",{className:"ri-stat-body",children:[(0,D.jsx)("div",{className:"ri-stat-label",children:"Heading"}),(0,D.jsx)("div",{className:"ri-stat-value",children:null!=e.heading?"".concat(e.heading,"\xb0"):"\u2014"})]})]}),(0,D.jsxs)("div",{className:"ri-stat",children:[(0,D.jsx)("div",{className:"ri-stat-icon",children:(0,D.jsx)(k.pSF,{})}),(0,D.jsxs)("div",{className:"ri-stat-body",children:[(0,D.jsx)("div",{className:"ri-stat-label",children:"App State"}),(0,D.jsx)("div",{className:"ri-stat-value",children:e.is_background?"Background":"Foreground"})]})]}),(0,D.jsxs)("div",{className:"ri-stat",children:[(0,D.jsx)("div",{className:"ri-stat-icon",children:(0,D.jsx)(k.gsJ,{})}),(0,D.jsxs)("div",{className:"ri-stat-body",children:[(0,D.jsx)("div",{className:"ri-stat-label",children:"Current Order"}),(0,D.jsx)("div",{className:"ri-stat-value",children:e.orderid||"\u2014"})]})]})]}),a&&(0,D.jsxs)("div",{className:"ri-map-section",children:[(0,D.jsxs)("div",{className:"ri-coords-label",children:[(0,D.jsx)(k.gwi,{})," ",s.toFixed(6),", ",t.toFixed(6)]}),(0,D.jsx)("div",{className:"ri-map",children:(0,D.jsxs)(o.W,{center:[s,t],zoom:13,scrollWheelZoom:!1,style:{height:"100%",width:"100%"},children:[(0,D.jsx)(p.e,{url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",attribution:"\xa9 OpenStreetMap contributors"}),(0,D.jsxs)(n.p,{position:[s,t],children:[(0,D.jsx)(u.m,{direction:"top",offset:[0,-10],permanent:!0,className:"ri-area-banner",children:(null===Xe||void 0===Xe?void 0:Xe.area)||"Locating area\u2026"}),(0,D.jsxs)(c.z,{children:[(0,D.jsx)("div",{style:{fontWeight:700,marginBottom:2},children:e.username||"Rider #".concat(e.userid)}),(null===Xe||void 0===Xe?void 0:Xe.area)&&(0,D.jsx)("div",{style:{fontSize:12,color:"#0f172a",marginBottom:4},children:Xe.area}),(0,D.jsx)("div",{style:{fontSize:11,color:"#64748b"},children:e.logdate?"Last seen ".concat(e.logdate):"".concat(s.toFixed(6),", ").concat(t.toFixed(6))})]})]})]},"".concat(e.userid,"-").concat(s,"-").concat(t))})]})]})})()]})})]}):(0,D.jsxs)("div",{id:"body",className:"".concat(Ds?"sidebar-collapsed":""," ").concat(bs?"compare-mode":"").trim(),children:[(0,D.jsx)("button",{type:"button",className:"sidebar-toggle-tab".concat(Ds?" is-collapsed":""),onClick:()=>qs((e=>!e)),title:Ds?"Show sidebar":"Hide sidebar","aria-label":Ds?"Show sidebar":"Hide sidebar",children:Ds?(0,D.jsx)(k.xVu,{}):(0,D.jsx)(k.E_E,{})}),(0,D.jsxs)("div",{id:"sidebar",children:[!dt&&(0,D.jsxs)("div",{className:"sb-header",children:[(0,D.jsxs)("div",{className:"sb-header-top",children:[(0,D.jsxs)("div",{className:"sb-header-title",children:[(0,D.jsx)("span",{className:"sb-title-bar","aria-hidden":"true"}),(0,D.jsx)("span",{className:"sb-title-text",children:"RIDER DISPATCH"})]}),(0,D.jsxs)("span",{className:"sb-header-scope",title:pt.label,children:[(0,D.jsx)("span",{className:"sb-scope-dot"}),pt.label]})]}),(0,D.jsxs)("div",{className:"sb-header-tiles",children:[(0,D.jsxs)("div",{className:"sb-tile sb-tile-orders",children:[(0,D.jsx)("span",{className:"sb-tile-icon",children:(0,D.jsx)(k.gsJ,{})}),(0,D.jsxs)("div",{className:"sb-tile-body",children:[(0,D.jsx)("div",{className:"sb-tile-value",children:pt.orders}),(0,D.jsx)("div",{className:"sb-tile-label",children:1===pt.orders?"Order":"Orders"})]})]}),(0,D.jsxs)("div",{className:"sb-tile sb-tile-riders",children:[(0,D.jsx)("span",{className:"sb-tile-icon",children:(0,D.jsx)(k.aVM,{})}),(0,D.jsxs)("div",{className:"sb-tile-body",children:[(0,D.jsx)("div",{className:"sb-tile-value",children:pt.riders}),(0,D.jsx)("div",{className:"sb-tile-label",children:1===pt.riders?"Rider":"Riders"})]})]})]})]}),dt||me?(0,D.jsxs)("div",{id:"route-detail",children:[(0,D.jsxs)("button",{className:"rd-back",onClick:()=>{ot(null),he(null)},children:["\u2190 Back to ",xe?xe.name:"list"]}),dt?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)("div",{className:"rd-rider-name",style:{color:dt.color},children:dt.riderName}),(()=>{const e=dt.orders.reduce(((e,s)=>e+parseFloat(s.actualkms||s.kms||0)),0),s=dt.orders.reduce(((e,s)=>e+parseFloat(s.profit||0)),0),t=s<0;return(0,D.jsxs)("div",{className:"rd-stats-grid",children:[(0,D.jsxs)("div",{className:"rd-stat rd-stat-orders",children:[(0,D.jsx)("div",{className:"rd-stat-icon",children:(0,D.jsx)(k.gsJ,{})}),(0,D.jsx)("div",{className:"rd-stat-value",children:dt.orders.length}),(0,D.jsx)("div",{className:"rd-stat-label",children:"Orders"})]}),(0,D.jsxs)("div",{className:"rd-stat rd-stat-distance",children:[(0,D.jsx)("div",{className:"rd-stat-icon",children:(0,D.jsx)(k.xI$,{})}),(0,D.jsxs)("div",{className:"rd-stat-value",children:[e.toFixed(1),(0,D.jsx)("span",{className:"rd-stat-unit",children:"km"})]}),(0,D.jsx)("div",{className:"rd-stat-label",children:"Distance"})]}),(0,D.jsxs)("div",{className:"rd-stat rd-stat-profit ".concat(t?"is-loss":"is-gain"),children:[(0,D.jsx)("div",{className:"rd-stat-icon",children:t?(0,D.jsx)(k.Rod,{}):(0,D.jsx)(k.imn,{})}),(0,D.jsxs)("div",{className:"rd-stat-value",children:[t?"-":"","\u20b9",Math.abs(s).toFixed(0)]}),(0,D.jsx)("div",{className:"rd-stat-label",children:t?"Loss":"Profit"})]})]})})(),(()=>{const e={};dt.orders.forEach((s=>{const t=s.trip_number||1;e[t]||(e[t]=[]),e[t].push(s)}));const s=[...dt.orders].sort(((e,s)=>{const t=e.trip_number||1,a=s.trip_number||1;return t!==a?t-a:(e.step||0)-(s.step||0)})).find((e=>{const s=String(e.orderstatus||"").toLowerCase();return!z.has(s)&&!M.has(s)})),t=s?s.orderid:null;let a=null;return Object.entries(e).sort(((e,s)=>{let[t]=e,[a]=s;return Number(t)-Number(a)})).map((e=>{let[s,i]=e;return(0,D.jsxs)("div",{className:"trip-block",children:[(0,D.jsxs)("div",{className:"trip-header",style:{background:"".concat(dt.color,"12"),borderColor:"".concat(dt.color,"30")},children:[(0,D.jsxs)("span",{className:"th-badge",style:{background:dt.color},children:["Trip ",s]}),(0,D.jsxs)("span",{className:"trip-stats",children:[(0,D.jsxs)("span",{children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.gwi,{})}),i.length," stops"]}),(0,D.jsxs)("span",{children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.xI$,{})}),i.reduce(((e,s)=>e+parseFloat(s.actualkms||s.kms||0)),0).toFixed(1)," km"]})]})]}),(0,D.jsx)("div",{className:"zone-order-grid",children:i.map(((e,i)=>{const l=(e.kitchen_key||e.pickupcustomer||"Unknown").toLowerCase().trim(),n=null!==a&&l!==a;a=l;const c=je&&je.orderid===e.orderid,d=t&&e.orderid===t,o=parseFloat(e.droplat||e.deliverylat),p=parseFloat(e.droplon||e.deliverylong),u=Number.isFinite(o)&&Number.isFinite(p),m=F(e.orderstatus),h=parseFloat(e.profit||0),x=h<0;return(0,D.jsxs)(r.Fragment,{children:[n&&(0,D.jsxs)("div",{className:"kitchen-transition",children:[(0,D.jsx)("span",{className:"kt-ico",children:(0,D.jsx)(k.$G1,{})})," Switch to ",(0,D.jsx)("strong",{children:e.pickupcustomer})]}),(0,D.jsxs)("div",{className:"zone-order-card ".concat(u?"clickable":""," ").concat(c?"active":""," ").concat(d?"going-on":""),role:u?"button":void 0,tabIndex:u?0:void 0,onClick:u?()=>ge(c?null:{orderid:e.orderid,lat:o,lon:p}):void 0,onKeyDown:u?s=>{"Enter"!==s.key&&" "!==s.key||(s.preventDefault(),ge(c?null:{orderid:e.orderid,lat:o,lon:p}))}:void 0,title:u?c?"Click to show full trip":"Show ".concat(e.deliverycustomer||"order #".concat(e.orderid)," on map"):void 0,children:[(0,D.jsxs)("div",{className:"zone-order-card-head",children:[(0,D.jsx)("div",{className:"zone-order-num",children:e.step||i+1}),(0,D.jsx)("div",{className:"zone-order-id-block",children:(0,D.jsxs)("div",{className:"zone-order-id",children:["Order #",e.orderid]})}),(()=>{const s=ae(e.deliverytime),t=ae(e.expecteddeliverytime);return e.orderstatus||s||t?(0,D.jsxs)("div",{className:"zone-order-status-stack",children:[e.orderstatus&&(0,D.jsx)("span",{className:"zone-order-status",style:{background:m.bg,color:m.fg},children:m.label}),(s||t)&&(0,D.jsxs)("span",{className:"zone-order-time ".concat(s?"":"is-expected"),title:s?"Delivered at ".concat(s):"Expected at ".concat(t),children:[(0,D.jsx)(k.VP9,{}),s||t]})]}):null})()]}),(0,D.jsxs)("div",{className:"zone-order-customer",children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.u9F,{})}),e.deliverycustomer||"\u2014"]}),e.pickupcustomer&&(0,D.jsxs)("div",{className:"zone-order-line",title:"Kitchen: ".concat(e.pickupcustomer),children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.NtI,{})}),e.pickupcustomer]}),(e.deliverysuburb||e.deliveryaddress)&&(0,D.jsxs)("div",{className:"zone-order-line",title:e.deliveryaddress||e.deliverysuburb,children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.gwi,{})}),e.deliverysuburb||I(e.deliveryaddress)]}),e.ordernotes&&(0,D.jsxs)("div",{className:"zone-order-line zone-order-notes",title:e.ordernotes,children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.dKO,{})}),e.ordernotes]}),(0,D.jsxs)("div",{className:"zone-order-stats",children:[(0,D.jsxs)("span",{className:"zone-order-chip",title:"Distance",children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.xI$,{})}),e.actualkms||e.kms||0," km"]}),(0,D.jsxs)("span",{className:"zone-order-chip ".concat(x?"is-loss":"is-profit"),title:"Profit",children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.ohY,{})}),x?"-":"","\u20b9",Math.abs(h).toFixed(0)]}),null!=e.deliverycharge&&(0,D.jsxs)("span",{className:"zone-order-chip",title:"Delivery charge",children:["\u20b9",parseFloat(e.deliverycharge).toFixed(0)," chg"]}),e.ordertype&&(0,D.jsx)("span",{className:"zone-order-chip zone-order-type type-".concat(String(e.ordertype).toLowerCase()),children:e.ordertype}),(0,D.jsxs)("span",{className:"zone-order-chip zone-order-trip",children:["T",e.trip_number||s," \xb7 S",e.step||i+1]})]})]})]},e.orderid)}))})]},s)}))})()]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)("div",{className:"rd-rider-name",style:{color:"#f59e0b"},children:me.kitchenName}),(0,D.jsxs)("div",{className:"rd-rider-sub",children:[(0,D.jsxs)("span",{children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.gsJ,{})}),me.orders.length," orders"]}),(0,D.jsxs)("span",{children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.aVM,{})}),me.riders.size," riders"]})]}),(0,D.jsxs)("div",{className:"zone-detail-section",children:[(0,D.jsxs)("div",{className:"zone-section-label",children:["Orders ",(0,D.jsxs)("span",{className:"section-count",children:["(",me.orders.length,")"]})]}),0===me.orders.length?(0,D.jsx)("div",{className:"zone-suburb-panel-empty",children:"No orders for this kitchen."}):(0,D.jsx)("div",{className:"zone-order-grid",children:me.orders.map(((e,s)=>{const t=parseFloat(e.droplat||e.deliverylat),a=parseFloat(e.droplon||e.deliverylong),i=Number.isFinite(t)&&Number.isFinite(a),r=je&&je.orderid===e.orderid,l=F(e.orderstatus),n=parseFloat(e.profit||0),c=n<0;return(0,D.jsxs)("div",{className:"zone-order-card ".concat(i?"clickable":""," ").concat(r?"active":""),role:i?"button":void 0,tabIndex:i?0:void 0,onClick:i?()=>ge(r?null:{orderid:e.orderid,lat:t,lon:a}):void 0,children:[(0,D.jsxs)("div",{className:"zone-order-card-head",children:[(0,D.jsx)("div",{className:"zone-order-num",children:s+1}),(0,D.jsxs)("div",{className:"zone-order-id-block",children:[(0,D.jsxs)("div",{className:"zone-order-id",children:["Order #",e.orderid]}),(0,D.jsxs)("div",{className:"zone-order-rider",children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.aVM,{})}),e.rider_name||e.ridername||"Unassigned"]})]}),e.orderstatus&&(0,D.jsx)("span",{className:"zone-order-status",style:{background:l.bg,color:l.fg},children:l.label})]}),(0,D.jsxs)("div",{className:"zone-order-customer",children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.u9F,{})}),e.deliverycustomer||"\u2014"]}),(e.deliverysuburb||e.deliveryaddress)&&(0,D.jsxs)("div",{className:"zone-order-line",title:e.deliveryaddress||e.deliverysuburb,children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.gwi,{})}),e.deliverysuburb||I(e.deliveryaddress)]}),e.ordernotes&&(0,D.jsxs)("div",{className:"zone-order-line zone-order-notes",title:e.ordernotes,children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.dKO,{})}),e.ordernotes]}),(0,D.jsxs)("div",{className:"zone-order-stats",children:[(0,D.jsxs)("span",{className:"zone-order-chip",title:"Distance",children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.xI$,{})}),e.actualkms||e.kms||0," km"]}),(0,D.jsxs)("span",{className:"zone-order-chip ".concat(c?"is-loss":"is-profit"),title:"Profit",children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.ohY,{})}),c?"-":"","\u20b9",Math.abs(n).toFixed(0)]}),null!=e.deliverycharge&&(0,D.jsxs)("span",{className:"zone-order-chip",title:"Delivery charge",children:["\u20b9",parseFloat(e.deliverycharge).toFixed(0)," chg"]}),e.ordertype&&(0,D.jsx)("span",{className:"zone-order-chip zone-order-type type-".concat(String(e.ordertype).toLowerCase()),children:e.ordertype}),(0,D.jsxs)("span",{className:"zone-order-chip zone-order-trip",children:["T",e.trip_number||"-"," \xb7 S",e.step||"-"]})]})]},e.orderid)}))})]})]})]}):xe?(0,D.jsxs)("div",{id:"route-detail",children:[(0,D.jsx)("button",{className:"rd-back",onClick:()=>ve(null),children:"\u2190 Back to zones"}),(0,D.jsx)("div",{className:"rd-rider-name",style:{color:"#3b82f6"},children:xe.name}),(0,D.jsx)("div",{className:"rd-rider-sub",children:(0,D.jsxs)("span",{children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.gsJ,{})}),xe.totalOrders," ",1===xe.totalOrders?"order":"orders"]})}),(0,D.jsxs)("div",{className:"zone-detail-section",children:[(0,D.jsxs)("div",{className:"zone-section-label",children:["Orders ",(0,D.jsxs)("span",{className:"section-count",children:["(",xe.orders.length,")"]})]}),0===xe.orders.length?(0,D.jsx)("div",{className:"zone-suburb-panel-empty",children:"No orders in this zone."}):(0,D.jsx)("div",{className:"zone-order-grid",children:xe.orders.map(((e,s)=>{const t=parseFloat(e.droplat||e.deliverylat),a=parseFloat(e.droplon||e.deliverylong),i=Number.isFinite(t)&&Number.isFinite(a),r=je&&je.orderid===e.orderid,l=F(e.orderstatus),n=parseFloat(e.profit||0),c=n<0;return(0,D.jsxs)("div",{className:"zone-order-card ".concat(i?"clickable":""," ").concat(r?"active":""),role:i?"button":void 0,tabIndex:i?0:void 0,onClick:i?()=>ge(r?null:{orderid:e.orderid,lat:t,lon:a}):void 0,children:[(0,D.jsxs)("div",{className:"zone-order-card-head",children:[(0,D.jsx)("div",{className:"zone-order-num",children:s+1}),(0,D.jsxs)("div",{className:"zone-order-id-block",children:[(0,D.jsxs)("div",{className:"zone-order-id",children:["Order #",e.orderid]}),(0,D.jsxs)("div",{className:"zone-order-rider",children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.aVM,{})}),e.rider_name||e.ridername||"Unassigned"]})]}),e.orderstatus&&(0,D.jsx)("span",{className:"zone-order-status",style:{background:l.bg,color:l.fg},children:l.label})]}),(0,D.jsxs)("div",{className:"zone-order-customer",children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.u9F,{})}),e.deliverycustomer||"\u2014"]}),e.pickupcustomer&&(0,D.jsxs)("div",{className:"zone-order-line",title:"Kitchen: ".concat(e.pickupcustomer),children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.NtI,{})}),e.pickupcustomer]}),(e.deliverysuburb||e.deliveryaddress)&&(0,D.jsxs)("div",{className:"zone-order-line",title:e.deliveryaddress||e.deliverysuburb,children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.gwi,{})}),e.deliverysuburb||I(e.deliveryaddress)]}),e.ordernotes&&(0,D.jsxs)("div",{className:"zone-order-line zone-order-notes",title:e.ordernotes,children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.dKO,{})}),e.ordernotes]}),(0,D.jsxs)("div",{className:"zone-order-stats",children:[(0,D.jsxs)("span",{className:"zone-order-chip",title:"Distance",children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.xI$,{})}),e.actualkms||e.kms||0," km"]}),(0,D.jsxs)("span",{className:"zone-order-chip ".concat(c?"is-loss":"is-profit"),title:"Profit",children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.ohY,{})}),c?"-":"","\u20b9",Math.abs(n).toFixed(0)]}),null!=e.deliverycharge&&(0,D.jsxs)("span",{className:"zone-order-chip",title:"Delivery charge",children:["\u20b9",parseFloat(e.deliverycharge).toFixed(0)," chg"]}),e.ordertype&&(0,D.jsx)("span",{className:"zone-order-chip zone-order-type type-".concat(String(e.ordertype).toLowerCase()),children:e.ordertype}),(0,D.jsxs)("span",{className:"zone-order-chip zone-order-trip",children:["T",e.trip_number||"-"," \xb7 S",e.step||"-"]})]})]},e.orderid)}))})]})]}):(0,D.jsxs)("div",{id:"riders-panel",children:[(0,D.jsx)("div",{className:"ph",children:"zones"===A?"Zone dispatch":"kitchens"===A?"Kitchen dispatch":"Rider dispatch"}),(0,D.jsx)("div",{id:"rider-cards",children:0!==nt.length||Gs?"zones"===A?it.map(((e,s)=>{const t=e.statusCounts.delivered||0,a=e.totalProfit<0;return(0,D.jsxs)("div",{className:"rcard zone-card",onClick:()=>ve(e),style:{animationDelay:"".concat(.05*s,"s")},children:[(0,D.jsxs)("div",{className:"zone-card-header",children:[(0,D.jsx)("div",{className:"zone-card-emoji",children:(0,D.jsx)(k.Cd7,{})}),(0,D.jsxs)("div",{className:"zone-card-titles",children:[(0,D.jsx)("div",{className:"zone-card-name",children:e.name}),(0,D.jsxs)("div",{className:"zone-card-sub",children:[e.activeRidersCount," ",1===e.activeRidersCount?"rider":"riders"," \xb7 ",e.totalOrders," ",1===e.totalOrders?"order":"orders"]})]}),(0,D.jsx)("span",{className:"zone-card-arrow","aria-hidden":"true",children:"\u2192"})]}),e.totalOrders>0&&(0,D.jsxs)("div",{className:"zone-progress-row",children:[(0,D.jsx)("div",{className:"zone-status-bar",title:Object.entries(e.statusCounts).map((e=>{let[s,t]=e;return"".concat(F(s).label,": ").concat(t)})).join(" \xb7 "),children:Object.entries(e.statusCounts).map((s=>{let[t,a]=s;const i=F(t),r=a/e.totalOrders*100;return(0,D.jsx)("div",{className:"zone-status-seg",style:{width:"".concat(r,"%"),background:i.bg}},t)}))}),(0,D.jsxs)("div",{className:"zone-progress-label",children:[t,"/",e.totalOrders]})]}),(0,D.jsxs)("div",{className:"zone-stat-pills",children:[(0,D.jsxs)("span",{className:"zone-stat-pill",title:"Areas covered",children:[(0,D.jsx)("span",{className:"zone-stat-icon",children:(0,D.jsx)(k.gwi,{})}),(0,D.jsx)("span",{className:"zone-stat-value",children:e.suburbs.length}),(0,D.jsx)("span",{className:"zone-stat-label",children:1===e.suburbs.length?"area":"areas"})]}),(0,D.jsxs)("span",{className:"zone-stat-pill",title:"Total distance",children:[(0,D.jsx)("span",{className:"zone-stat-icon",children:(0,D.jsx)(k.xI$,{})}),(0,D.jsx)("span",{className:"zone-stat-value",children:e.totalKms.toFixed(1)}),(0,D.jsx)("span",{className:"zone-stat-label",children:"km"})]}),(0,D.jsxs)("span",{className:"zone-stat-pill",title:"Kitchens",children:[(0,D.jsx)("span",{className:"zone-stat-icon",children:(0,D.jsx)(k.NtI,{})}),(0,D.jsx)("span",{className:"zone-stat-value",children:e.kitchens.length}),(0,D.jsx)("span",{className:"zone-stat-label",children:1===e.kitchens.length?"kitchen":"kitchens"})]}),(0,D.jsxs)("span",{className:"zone-stat-pill ".concat(a?"profit-negative":"profit-positive"),title:"Total profit",children:[(0,D.jsx)("span",{className:"zone-stat-icon",children:(0,D.jsx)(k.ohY,{})}),(0,D.jsx)("span",{className:"zone-stat-value",children:a?"-\u20b9".concat(Math.abs(e.totalProfit).toFixed(0)):"\u20b9".concat(e.totalProfit.toFixed(0))})]})]}),e.suburbs.length>0&&(0,D.jsxs)("div",{className:"zone-card-suburbs",children:[(0,D.jsx)("span",{className:"zone-card-suburbs-text",children:e.suburbs.slice(0,3).map((e=>e.name)).join(" \xb7 ")}),e.suburbs.length>3&&(0,D.jsxs)("span",{className:"zone-card-suburbs-more",children:["+",e.suburbs.length-3]})]})]},e.id)})):"kitchens"===A?lt.map(((e,s)=>(0,D.jsxs)("div",{className:"rcard",onClick:()=>he(e),style:{animationDelay:"".concat(.05*s,"s")},children:[(0,D.jsxs)("div",{className:"rcard-top",children:[(0,D.jsx)("div",{className:"rcard-emo",style:{background:"#f59e0b18",borderColor:"#f59e0b50",color:"#f59e0b"},children:(0,D.jsx)(k.NtI,{})}),(0,D.jsxs)("div",{className:"rcard-info",children:[(0,D.jsx)("div",{className:"rcard-name",children:e.kitchenName}),(0,D.jsxs)("div",{className:"rcard-zone",children:[e.riders.size," riders \xb7 ",(0,D.jsx)(de,{children:(0,D.jsx)(k.ohY,{})}),"\u20b9",e.orders.reduce(((e,s)=>e+parseFloat(s.profit||0)),0).toFixed(0)]})]}),(0,D.jsx)("div",{className:"rcard-badge",style:{background:"#f59e0b18",color:"#f59e0b"},children:e.orders.length})]}),(0,D.jsx)("div",{className:"bar-bg",children:(0,D.jsx)("div",{className:"bar-fg",style:{width:"".concat(Math.min(100,e.orders.length/20*100),"%"),background:"#f59e0b"}})}),(0,D.jsxs)("div",{className:"rcard-meta",children:[(0,D.jsxs)("span",{children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.xI$,{})}),e.orders.reduce(((e,s)=>e+parseFloat(s.actualkms||s.kms||0)),0).toFixed(1)," km"]}),(0,D.jsxs)("span",{children:[e.riders.size," riders"]})]}),(0,D.jsx)("div",{className:"step-ids",children:Array.from(e.riders).slice(0,10).map((e=>{var s;return(0,D.jsx)("span",{className:"step-id",style:{color:wt(e)},children:null===(s=rt.find((s=>s.id===e)))||void 0===s?void 0:s.riderName.split(" ")[0]},e)}))})]},e.id))):rt.map(((e,s)=>{var t;return(0,D.jsxs)("div",{className:"rcard",onClick:()=>ot(e),style:{animationDelay:"".concat(.05*s,"s")},children:[(0,D.jsxs)("div",{className:"rcard-top",children:[(0,D.jsx)("div",{className:"rcard-emo",style:{background:"".concat(e.color,"18"),borderColor:"".concat(e.color,"50"),color:e.color},children:(0,D.jsx)(k.aVM,{})}),(0,D.jsxs)("div",{className:"rcard-info",children:[(0,D.jsx)("div",{className:"rcard-name",children:e.riderName}),(0,D.jsxs)("div",{className:"rcard-zone",children:[(null===(t=e.orders[0])||void 0===t?void 0:t.zone_name)||es||"Local"," \xb7 ",new Set(e.orders.map((e=>e.trip_number||1))).size," trips"]})]}),(0,D.jsx)("div",{className:"rcard-badge",style:{background:"".concat(e.color,"18"),color:e.color},children:e.orders.length})]}),(0,D.jsx)("div",{className:"bar-bg",children:(0,D.jsx)("div",{className:"bar-fg",style:{width:"".concat(Math.min(100,e.orders.length/15*100),"%"),background:e.color}})}),(0,D.jsxs)("div",{className:"rcard-meta",children:[(0,D.jsxs)("span",{children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.xI$,{})}),e.orders.reduce(((e,s)=>e+parseFloat(s.actualkms||s.kms||0)),0).toFixed(1)," km"]}),(0,D.jsxs)("span",{children:[(0,D.jsx)(de,{children:(0,D.jsx)(k.ohY,{})}),"\u20b9",e.orders.reduce(((e,s)=>e+parseFloat(s.profit||0)),0).toFixed(0)]})]}),(0,D.jsx)("div",{className:"step-ids",children:e.orders.slice(0,15).map((e=>(0,D.jsxs)("span",{className:"step-id",children:["S",e.step]},e.orderid)))})]},e.id)})):(e=>{const s=null===(e=Re.find((e=>e.id===Ks)))||void 0===e?void 0:e.label,t=Bs&&Xs.length>0;return(0,D.jsxs)("div",{className:"empty-slot",children:[(0,D.jsx)("div",{className:"empty-slot-icon",children:(0,D.jsx)(k.gsJ,{})}),(0,D.jsx)("div",{className:"empty-slot-title",children:s?"No orders in ".concat(s):"No orders"}),(0,D.jsx)("div",{className:"empty-slot-sub",children:t?"".concat(Xs.length," order").concat(1===Xs.length?"":"s"," exist in other slots today"):"No deliveries found for this date"})]})})()})]})]}),(0,D.jsxs)("div",{id:"map-wrap",className:"".concat("kitchens"===A?"view-mode-kitchens":""," ").concat(bs?"compare-split":"").trim(),children:[(0,D.jsxs)(o.W,{center:[11.022,76.982],zoom:12,scrollWheelZoom:!0,style:{height:"100%",width:"100%"},zoomControl:!1,renderer:Rs.current,inertia:!0,inertiaDeceleration:2400,inertiaMaxSpeed:2e3,wheelDebounceTime:20,wheelPxPerZoomLevel:80,zoomSnap:.25,children:[(0,D.jsx)(p.e,{url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",attribution:"\xa9 OpenStreetMap contributors"}),(0,D.jsx)(m.p,{position:"bottomright"}),bs&&(0,D.jsx)(X,{targetRef:Is}),(0,D.jsx)(ce,{focusedItem:ft||(dt||me)&&je||dt||me||xe,viewMode:A,orders:nt,kitchens:lt,locationKey:ze}),lt.filter((e=>Number.isFinite(e.lat)&&Number.isFinite(e.lon))).filter((e=>!dt||e.riders.has(dt.id))).map(((e,s)=>(0,D.jsx)(n.p,{position:[e.lat,e.lon],icon:St(e.kitchenName,(null===me||void 0===me?void 0:me.id)===e.id),zIndexOffset:(null===me||void 0===me?void 0:me.id)===e.id?4e3:2e3,eventHandlers:{click:()=>he(e),mouseover:e=>e.target.openPopup(),mouseout:e=>e.target.closePopup()},children:(0,D.jsxs)(c.z,{className:"kitchen-popup",maxWidth:220,minWidth:200,autoPan:!1,children:[(0,D.jsx)("div",{className:"kp-header",children:"KITCHEN"}),(0,D.jsx)("div",{className:"kp-name",children:e.kitchenName}),(0,D.jsxs)("div",{className:"kp-stat",children:[(0,D.jsx)("span",{className:"kp-stat-lbl",children:"Orders"}),(0,D.jsx)("span",{className:"kp-stat-val",children:e.orders.length})]})]})},"k-".concat(s)))),(()=>{if(bs&&dt&&"actual"===ks)return null;let e=nt;xe&&(e=xe.orders),dt&&(e=dt.orders),me&&(e=me.orders),e=e.filter(R);const s=bs&&dt?new Map(xt.map((e=>[String(e.deliveryid),e.sequenceStep]))):null;return e.map(((t,a)=>{const i=t.rider_id,r=!i||ee.has(i);let l,d=wt(i);if(s&&i===dt.id&&null!=t.deliveryid){const e=s.get(String(t.deliveryid));e&&(d=P(e-1),l=e)}const o=l||t.step||(dt||me?e.indexOf(t)+1:0),p=32,u=F(t.orderstatus),m="delivered"===String(t.orderstatus||"").toLowerCase(),h=j&&String(j)===String(t.orderid),v=t.orderstatus?'\n \n \n ').concat(m?'':"","\n "):"",g=x().divIcon({className:"",iconSize:[p,p],iconAnchor:[16,16],popupAnchor:[0,-28],html:'
9?12:14,"px;opacity:").concat(r?1:.75,'">').concat(o>0?o:"").concat(v,"
")});return(0,D.jsx)(n.p,{position:[parseFloat(t.droplat||t.deliverylat),parseFloat(t.droplon||t.deliverylong)],icon:g,zIndexOffset:i?100:0,ref:e=>{e?Ne.current[String(t.orderid)]=e:delete Ne.current[String(t.orderid)]},eventHandlers:{mouseover:e=>e.target.openPopup(),mouseout:e=>{fe.current.has(String(t.orderid))||e.target.closePopup()},click:e=>{const s=String(t.orderid);fe.current.has(s)?(fe.current.delete(s),e.target.closePopup()):(fe.current.add(s),e.target.openPopup())}},children:(0,D.jsx)(c.z,{maxWidth:520,minWidth:460,className:"dispatch-popup",autoPan:!1,children:Ft(t)})},t.orderid)}))})(),(()=>{const e=bs&&dt&&"actual"===ks;if(ns)return e?[]:ds.map(((e,s)=>(0,D.jsx)(d.R,{positions:[e.from,e.to],pathOptions:{color:e.color,weight:6,opacity:.9,lineJoin:"round",lineCap:"round"}},s)));const s=[],t=xe?new Set(xe.riders.map((e=>String(e.rider_id)))):null;return e||rt.forEach((e=>{const a=ee.has(e.id);if(dt&&dt.id!==e.id)return;if(me&&!me.riders.has(e.id))return;if(t&&!t.has(String(e.id)))return;const i=e.orders,l={};i.forEach((e=>{const s=e.trip_number||1;l[s]||(l[s]=[]),l[s].push(e)})),Object.entries(l).forEach((t=>{let[i,l]=t;const n=me?l.filter((e=>(e.pickupcustomer||e.kitchen_key||"Unknown").toLowerCase().trim()===me.id)):l;if(0===n.length)return;const c="".concat(e.id,"-").concat(i),o=ss[c],p=[...n].sort(((e,s)=>(e.step||0)-(s.step||0))),u=Array.isArray(o)&&o.length>=2,m=!1===o;if(!u&&!m)return;const h=u?o:le(p);if(!h||h.length<2)return;const x=a?1:.1,v="kitchens"===A||me?7:6,j=bs&&dt&&e.id===dt.id,g=m?"8 6":j&&"combined"===ks?"6 5":void 0;if(bs&&dt&&e.id===dt.id){const t=new Map(xt.map((e=>[String(e.deliveryid),e.sequenceStep]))),a=p.filter(R),r=a.map((e=>[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]));let l;if(u)l=te(h,r);else{const e=h.length>r.length;l=[];for(let s=0;s=h.length||a>=h.length?l.push([]):l.push([h[t],h[a]])}}const n="combined"===ks?5:0;return s.push((0,D.jsx)(d.R,{positions:h,pathOptions:{color:"#ffffff",weight:v+4,opacity:.5*x,lineJoin:"round",lineCap:"round",offset:n}},"".concat(e.id,"-").concat(i,"-halo"))),void l.forEach(((r,l)=>{if(!r||r.length<2)return;const c=a[l],o=c?t.get(String(c.deliveryid)):null,p="combined"===ks?E:o?P(o-1):e.color,u=null!=_s&&_s===o,m=u?v+1.5:v,h=u?1:_s?.5*x:x;s.push((0,D.jsx)(d.R,{positions:r,pathOptions:{color:p,weight:m,opacity:h,lineJoin:"round",lineCap:"round",dashArray:g,offset:n}},"".concat(e.id,"-").concat(i,"-step-").concat(l,"-").concat((null===c||void 0===c?void 0:c.deliveryid)||l)))}))}s.push((0,D.jsxs)(r.Fragment,{children:[(0,D.jsx)(d.R,{positions:h,pathOptions:{color:"#ffffff",weight:v+4,opacity:.5*x,lineJoin:"round",lineCap:"round"}}),(0,D.jsx)(d.R,{positions:h,pathOptions:{color:e.color,weight:v,opacity:x,lineJoin:"round",lineCap:"round",dashArray:g}})]},"".concat(e.id,"-").concat(i)))}))})),s})(),!me&&ut.filter((e=>ee.has(e.id))).filter((e=>!dt||dt.id===e.id)).map((e=>{const s=(e=>{if(!e||e.length<2)return null;const s=[];let t=0;for(let r=0;r=a){const t=(a-i)/s[r];return[e[r][0]+t*(e[r+1][0]-e[r][0]),e[r][1]+t*(e[r+1][1]-e[r][1])]}i+=s[r]}return e[e.length-1]})(ss["".concat(e.id,"-seg-").concat(e.nextStep)]),t=s||[e.aerialLat,e.aerialLon],a=Boolean(s),i=x().divIcon({className:"",iconSize:[44,44],iconAnchor:[22,22],popupAnchor:[0,-22],html:'
\n
\n
').concat('','
\n
').concat(e.completedCount,"/").concat(e.totalCount,"
\n
")});return(0,D.jsx)(n.p,{position:t,icon:i,zIndexOffset:3e3,eventHandlers:{click:()=>ot(rt.find((s=>s.id===e.id))||null),mouseover:e=>e.target.openPopup(),mouseout:e=>e.target.closePopup()},children:(0,D.jsxs)(c.z,{maxWidth:240,autoPan:!1,className:"dispatch-popup route-rider-popup",children:[(0,D.jsx)("div",{className:"pu-hdr-live",children:(0,D.jsx)("div",{className:"pu-hdr-left",children:(0,D.jsx)("span",{className:"pu-hdr-title",children:"RIDER ROUTE"})})}),(0,D.jsxs)("div",{className:"pu-rider-profile",children:[(0,D.jsx)("div",{className:"pu-avatar",style:{backgroundColor:"".concat(e.color,"12"),color:e.color},children:(0,D.jsx)(k.bsz,{})}),(0,D.jsxs)("div",{className:"pu-rider-info-text",children:[(0,D.jsx)("div",{className:"pu-rider-name",style:{color:e.color},children:e.riderName}),(0,D.jsx)("div",{className:"pu-rider-meta",children:"Active route details"})]})]}),(0,D.jsxs)("div",{className:"pu-body-content",children:[(0,D.jsxs)("div",{className:"pu-info-row",children:[(0,D.jsx)("span",{className:"pu-info-label",children:"Progress"}),(0,D.jsxs)("span",{className:"pu-info-value",children:[(0,D.jsx)("strong",{children:e.completedCount})," / ",e.totalCount," delivered"]})]}),(0,D.jsxs)("div",{className:"pu-info-row",children:[(0,D.jsx)("span",{className:"pu-info-label",children:"Next Stop"}),(0,D.jsxs)("span",{className:"pu-info-value text-indigo",style:{color:"#4f46e5"},children:["#",e.nextStep," \xb7 ",e.nextCustomer||"\u2014"]})]}),(0,D.jsxs)("div",{className:"pu-info-row",children:[(0,D.jsx)("span",{className:"pu-info-label",children:"Position"}),(0,D.jsx)("span",{className:"pu-info-value",style:{color:"#64748b"},children:a?"On road":"Estimating\u2026"})]})]})]})},"bike-".concat(e.id))})),Ts.filter((e=>rt.some((s=>String(s.id)===String(e.id))))).filter((e=>!dt||String(dt.id)===String(e.id))).map((e=>{const s="active"===e.status?"#16a34a":"#dc2626",t=x().divIcon({className:"",iconSize:[140,56],iconAnchor:[12,41],popupAnchor:[58,-40],html:'
\n
\n
').concat((e.username||"").replace(/[<>&"']/g,"")).concat(e.orderid?" #".concat(String(e.orderid).replace(/[<>&"']/g,""),""):"","
\n
")});return(0,D.jsx)(n.p,{position:[e.lat,e.lon],icon:t,zIndexOffset:2500,eventHandlers:{click:()=>{const s=rt.find((s=>String(s.id)===String(e.id)));s&&ot(s)},mouseover:e=>e.target.openPopup(),mouseout:e=>e.target.closePopup()},children:(0,D.jsxs)(c.z,{maxWidth:260,autoPan:!1,className:"dispatch-popup live-rider-popup",children:[(0,D.jsxs)("div",{className:"pu-hdr-live",children:[(0,D.jsxs)("div",{className:"pu-hdr-left",children:[(0,D.jsx)("span",{className:"pu-live-indicator",style:{"--pulse-color":s},children:(0,D.jsx)("span",{className:"pu-live-dot"})}),(0,D.jsx)("span",{className:"pu-hdr-title",children:"LIVE GPS"})]}),e.status&&(0,D.jsx)("span",{className:"pu-status-badge ".concat("active"===e.status.toLowerCase()?"active":"idle"),children:e.status})]}),(0,D.jsxs)("div",{className:"pu-rider-profile",children:[(0,D.jsx)("div",{className:"pu-avatar",style:{backgroundColor:"".concat(s,"12"),color:s},children:(0,D.jsx)(k.bsz,{})}),(0,D.jsxs)("div",{className:"pu-rider-info-text",children:[(0,D.jsx)("div",{className:"pu-rider-name",children:e.username||"Rider #".concat(e.id)}),(0,D.jsxs)("div",{className:"pu-rider-meta",children:["Rider ID: #",e.id]})]})]}),(0,D.jsxs)("div",{className:"pu-body-content",children:[e.orderid&&(0,D.jsxs)("div",{className:"pu-info-row",children:[(0,D.jsx)("span",{className:"pu-info-label",children:"Active Order"}),(0,D.jsxs)("span",{className:"pu-info-value pu-order-badge",children:["#",e.orderid]})]}),e.contactno&&(0,D.jsxs)("div",{className:"pu-info-row",children:[(0,D.jsx)("span",{className:"pu-info-label",children:"Phone"}),(0,D.jsx)("a",{href:"tel:".concat(e.contactno),className:"pu-info-value pu-phone-link",children:e.contactno})]}),e.logdate&&(0,D.jsxs)("div",{className:"pu-info-row",children:[(0,D.jsx)("span",{className:"pu-info-label",children:"Last Seen"}),(0,D.jsxs)("span",{className:"pu-info-value pu-time-stamp",children:[(0,D.jsx)(k.VP9,{className:"inline-icon"})," ",g()(e.logdate).isValid()?g()(e.logdate).format("hh:mm:ss A"):e.logdate]})]}),(0,D.jsxs)("div",{className:"pu-info-row",children:[(0,D.jsx)("span",{className:"pu-info-label",children:"Position"}),(0,D.jsxs)("span",{className:"pu-info-value pu-coordinates",children:[e.lat.toFixed(5),", ",e.lon.toFixed(5)]})]})]})]})},"live-".concat(e.id))})),bs&&dt&&"planned"!==ks&&xt.map(((e,s)=>{var t,a;if(0===e.coords.length)return null;const i=P(s),l="combined"===ks?_:i,o=[e.coords[0].lat,e.coords[0].lng],p=[e.coords[e.coords.length-1].lat,e.coords[e.coords.length-1].lng],m=is[e.deliveryid],h=Array.isArray(m)&&m.length>=2?m:e.coords.map((e=>[e.lat,e.lng]));let v=h,j=!0;if(ns){const s=ps[e.sequenceStep]||0;s<2?j=!1:v=h.slice(0,Math.min(s,h.length))}const N=_s===e.sequenceStep,f=String(e.orderstatus||"").toLowerCase(),b=z.has(f),y=M.has(f),S=vt.find((s=>s.sequenceStep===e.sequenceStep)),w=!(null===S||void 0===S||!S.anomaly),C=null===dt||void 0===dt||null===(t=dt.orders)||void 0===t?void 0:t.find((s=>null!=s.deliveryid&&String(s.deliveryid)===String(e.deliveryid))),A=["compare-step-pin"];N&&A.push("is-focused"),b&&A.push("is-delivered"),y&&A.push("is-skipped"),w&&A.push("is-anomaly");const q='
')+''.concat(e.sequenceStep,"")+(b?'':"")+"
",L=x().divIcon({className:"",iconSize:[36,36],iconAnchor:[18,18],popupAnchor:[0,-22],html:q}),E=1===e.sequenceStep,O=E?x().divIcon({className:"",iconSize:[40,40],iconAnchor:[20,20],html:'
')+'
'}):null,I=s=>{s.originalEvent&&s.originalEvent.stopPropagation(),Os((s=>s===e.sequenceStep?null:e.sequenceStep)),C&&s.target&&"function"===typeof s.target.openPopup&&s.target.openPopup()},R="combined"===ks?-5:0;return(0,D.jsxs)(r.Fragment,{children:[j&&(0,D.jsx)(d.R,{positions:v,pathOptions:{color:"#ffffff",weight:N?11:9,opacity:N?.75:.55,lineJoin:"round",lineCap:"round",offset:R}}),j&&(0,D.jsx)(d.R,{positions:v,pathOptions:{color:l,weight:N?6.5:5,opacity:N?1:_s?.55:.95,lineJoin:"round",lineCap:"round",offset:R}}),E&&(0,D.jsx)(n.p,{position:o,icon:O,zIndexOffset:N?900:100,eventHandlers:{click:s=>{s.originalEvent&&s.originalEvent.stopPropagation(),Os((s=>s===e.sequenceStep?null:e.sequenceStep))}},children:(0,D.jsx)(u.m,{direction:"top",offset:[0,-12],opacity:1,className:"compare-tooltip",children:(0,D.jsxs)("div",{className:"cmp-tip",children:[(0,D.jsxs)("div",{className:"cmp-tip-header",children:[(0,D.jsx)("span",{className:"cmp-tip-step",style:{background:i},children:(0,D.jsx)(k.zPd,{})}),(0,D.jsxs)("div",{className:"cmp-tip-title-stack",children:[(0,D.jsx)("div",{className:"cmp-tip-title",children:e.pickupcustomer||"Pickup"}),(0,D.jsx)("div",{className:"cmp-tip-sub",children:null!==(a=e.coords[0])&&void 0!==a&&a.logdate?"Picked up \xb7 ".concat(g()(e.coords[0].logdate).format("hh:mm A")):"Rider trip origin"})]})]}),(0,D.jsx)("div",{className:"cmp-tip-action",children:"Click for step 1 details"})]})})}),(0,D.jsxs)(n.p,{position:p,icon:L,zIndexOffset:N?1e3:200,eventHandlers:C?{mouseover:e=>{be.current&&(clearTimeout(be.current),be.current=null),e.target.openPopup()},mouseout:s=>{if(_s===e.sequenceStep)return;const t=s.target;be.current&&clearTimeout(be.current),be.current=setTimeout((()=>{t.closePopup(),be.current=null}),120)},click:I}:{click:I},children:[!C&&(0,D.jsx)(u.m,{direction:"top",offset:[0,-20],opacity:1,className:"compare-tooltip",children:(()=>{const s=F(e.orderstatus);return(0,D.jsxs)("div",{className:"cmp-tip",children:[(0,D.jsxs)("div",{className:"cmp-tip-header",children:[(0,D.jsx)("span",{className:"cmp-tip-step",style:{background:i},children:e.sequenceStep}),(0,D.jsxs)("div",{className:"cmp-tip-title-stack",children:[(0,D.jsx)("div",{className:"cmp-tip-title",children:e.deliverycustomer||"Step ".concat(e.sequenceStep)}),(0,D.jsx)("div",{className:"cmp-tip-sub",children:e.deliverytime?"Delivered ".concat(g()(e.deliverytime).format("hh:mm A")):"".concat(e.coords.length," GPS pings")})]}),e.orderstatus&&(0,D.jsx)("span",{className:"cmp-tip-tag",style:{background:s.bg,color:s.fg},children:s.label})]}),w&&(0,D.jsx)("div",{className:"cmp-tip-anomaly",children:"Deviation flagged \u2014 see details below"}),(0,D.jsx)("div",{className:"cmp-tip-action",children:N?"Click to deselect":"Click for details"})]})})()}),C&&(0,D.jsx)(c.z,{maxWidth:520,minWidth:460,className:"dispatch-popup",autoPan:!1,children:Ft(C)})]})]},"actual-".concat(e.deliveryid))}))]}),bs&&dt&&(0,D.jsxs)("div",{className:"compare-view-switcher",role:"group","aria-label":"Compare view layer",children:[(0,D.jsx)("button",{type:"button",className:"actual"===ks?"is-active":"",onClick:()=>Ss("actual"),title:"Show only the rider's actual GPS trail",children:"Actual"}),(0,D.jsx)("button",{type:"button",className:"planned"===ks?"is-active":"",onClick:()=>Ss("planned"),title:"Show only the dispatched planned route",children:"Planned"}),(0,D.jsx)("button",{type:"button",className:"combined"===ks?"is-active":"",onClick:()=>Ss("combined"),title:"Overlay planned (dashed) and actual (solid) on one map",children:"Combined"})]}),(0,D.jsx)("div",{id:"ov-tl"}),(0,D.jsx)("div",{id:"ov-tr",children:"kitchens"===A?lt.slice(0,10).map((e=>{const s=e.orders.length,t=e.orders.filter((e=>z.has(String(e.orderstatus||"").toLowerCase()))).length,a=s>0&&t>=s;return(0,D.jsxs)("div",{className:"rchip ".concat((null===me||void 0===me?void 0:me.id)===e.id?"active":""),onClick:()=>he(e),title:"".concat(t," delivered of ").concat(s," total"),children:[(0,D.jsx)("div",{className:"rchip-dot",style:{background:"#f59e0b"}}),(0,D.jsx)("span",{style:{maxWidth:"100px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.kitchenName}),(0,D.jsxs)("span",{className:"rchip-n ".concat(a?"is-done":""),children:[t,"/",s]})]},e.id)})):rt.slice(0,10).map((e=>{const s=e.orders.length,t=e.orders.filter((e=>z.has(String(e.orderstatus||"").toLowerCase()))).length,a=s>0&&t>=s;return(0,D.jsxs)("div",{className:"rchip ".concat((null===dt||void 0===dt?void 0:dt.id)===e.id?"active":""),onClick:()=>ot(e),title:"".concat(t," delivered of ").concat(s," total"),children:[(0,D.jsx)("div",{className:"rchip-dot",style:{background:e.color}}),(0,D.jsx)("span",{style:{maxWidth:"100px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.riderName}),(0,D.jsxs)("span",{className:"rchip-n ".concat(a?"is-done":""),children:[t,"/",s]})]},e.id)}))}),(0,D.jsxs)("div",{id:"ov-br",children:[(0,D.jsxs)("button",{className:"sbt ".concat(ns?"active":""),onClick:()=>{if(ns)return cs(!1),os([]),void us({});cs(!0),os([]),us({});const e=bs&&dt,s=e?new Map(xt.map((e=>[String(e.deliveryid),e.sequenceStep]))):null,t=[];if(rt.forEach((a=>{if(!ee.has(a.id))return;if(dt&&dt.id!==a.id)return;if(me&&!me.riders.has(a.id))return;const i={};a.orders.forEach((e=>{const s=e.trip_number||1;i[s]||(i[s]=[]),i[s].push(e)})),Object.entries(i).forEach((i=>{let[r,l]=i;const n=me?l.filter((e=>(e.pickupcustomer||e.kitchen_key||"Unknown").toLowerCase().trim()===me.id)):l;if(0===n.length)return;const c="".concat(a.id,"-").concat(r),d=ss[c],o=[...n].sort(((e,s)=>(e.step||0)-(s.step||0))),p=le(o),u="kitchens"===A||me,m=d||p;if(m.length<2)return;let h=()=>a.color;if(e&&a.id===dt.id){const e=o.filter(R).map((e=>[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)])),t=d?te(d,e):(()=>{const s=p.length>e.length,t=[];for(let a=0;a=p.length||i>=p.length?t.push([]):t.push([p[e],p[i]])}return t})(),i=[];let r=0;t.forEach(((e,s)=>{const t=Math.max(0,((null===e||void 0===e?void 0:e.length)||0)-1);for(let a=0;a{const t=i[e];if(null==t)return a.color;const r=o.filter(R)[t],l=r?s.get(String(r.deliveryid)):null;return l?P(l-1):a.color}}for(let e=0;ee.delay-s.delay)),t.forEach(((e,s)=>{setTimeout((()=>{os((s=>[...s,e])),s===t.length-1&&setTimeout((()=>{cs(!1),us({})}),1e3)}),e.delay)})),e&&xt.length>0){const e=[...xt],s=e.map((e=>{const s=is[e.deliveryid];return Array.isArray(s)&&s.length>=2?s:e.coords.map((e=>[e.lat,e.lng]))})),a=t.length>0?t[t.length-1].delay:800*e.length,i=Math.max(a,600*e.length),r=i/Math.max(1,e.length),l=Date.now(),n=()=>{if(!ms.current)return;const t=Date.now()-l,a={};e.forEach(((e,i)=>{const l=s[i];if(!l||l.length<2)return;const n=i*r;if(t>=n+r)a[e.sequenceStep]=l.length;else if(t>=n){const s=(t-n)/r;a[e.sequenceStep]=Math.max(2,Math.ceil(s*l.length))}})),us(a),t{if(bs)ys(!1);else{if(!dt){const e=rt.find((e=>(e.orders||[]).some((e=>null!=e.deliveryid&&""!==e.deliveryid&&0!==e.deliveryid)))),s=rt.find((e=>e.orders&&e.orders.length>0)),t=e||s;if(t&&(ot(t),ye))return void(As.current=!0)}ys(!0)}},title:dt?"Compare planned vs. actual route for ".concat(dt.riderName):"Compare planned vs. actual route (will focus the first rider)",style:{boxShadow:"var(--shadow-lg)",background:bs?"linear-gradient(135deg, #6366f1, #3b82f6)":"#fff",marginLeft:8,color:bs?"#fff":void 0},children:[(0,D.jsx)("span",{className:"sbt-icon",children:(0,D.jsx)(k.$G1,{})}),bs?"Exit Compare":"Compare"]})]})]}),bs&&dt&&(0,D.jsx)("div",{id:"compare-map-wrap",children:(()=>{const e=xt.length,s=xt.filter((e=>e.coords.length>0)).length,t=xt.filter((e=>e.isLoading)).length,a=e>0?Math.round(s/e*100):0,i=e>0&&s===e&&0===t,l=null!=_s?vt.find((e=>e.sequenceStep===_s)):null;return(0,D.jsxs)("div",{className:"compare-header-v2",children:[(0,D.jsxs)("div",{className:"compare-header-row",children:[(0,D.jsxs)("div",{className:"compare-title",children:[(0,D.jsx)("span",{className:"compare-title-dot",style:{background:dt.color}}),(0,D.jsx)("span",{className:"compare-title-name",children:dt.riderName}),(0,D.jsx)("span",{className:"compare-title-badge",children:"ACTUAL vs PLANNED"})]}),(0,D.jsxs)("div",{className:"compare-header-tools",children:[null!=_s&&(0,D.jsxs)("button",{type:"button",className:"compare-overall-btn",onClick:()=>Os(null),title:"Zoom out to the whole day",children:[(0,D.jsx)(k.Zs6,{})," Overall"]}),(0,D.jsx)("button",{type:"button",className:"compare-timeline-toggle".concat(zs?" is-open":""),onClick:()=>Ms((e=>!e)),title:zs?"Hide planned/actual timeline":"Show planned/actual timeline","aria-expanded":zs,children:(0,D.jsx)(k.j1Q,{})})]})]}),zs&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)("div",{className:"compare-timeline-wrap",children:[(0,D.jsxs)("div",{className:"compare-timeline-container",children:[(0,D.jsxs)("div",{className:"compare-timeline-labels",children:[(0,D.jsx)("div",{className:"compare-timeline-label",children:"Planned"}),(0,D.jsx)("div",{className:"compare-timeline-label",children:"Actual"})]}),(0,D.jsxs)("div",{className:"compare-timeline-scrollable",children:[(0,D.jsx)("div",{className:"compare-timeline-track is-planned",children:gt.map(((e,s)=>{var t;const a=String(e.orderstatus||"").toLowerCase(),i=z.has(a),l=M.has(a),n=_s===e.sequenceStep,c=e.isLoading&&0===e.coordsCount,d=!e.isLoading&&0===e.coordsCount,o=(null===(t=e.order)||void 0===t?void 0:t.step)||e.sequenceStep,p=P(o-1),u=["compare-step",n&&"is-focused",i&&"is-delivered",l&&"is-skipped",!i&&!l&&"is-pending",c&&"is-loading",d&&"is-no-data",e.anomaly&&"is-anomaly"].filter(Boolean).join(" ");return(0,D.jsxs)(r.Fragment,{children:[s>0&&(0,D.jsx)("span",{className:"compare-step-spacer"}),(0,D.jsx)("button",{type:"button",className:u,style:{"--step-color":p},onClick:()=>Os((s=>s===e.sequenceStep?null:e.sequenceStep)),title:"Planned Step ".concat(o)+(e.deliverycustomer?" \xb7 ".concat(e.deliverycustomer):"")+(e.anomaly?" \xb7 deviation flagged":""),children:(0,D.jsx)("span",{className:"compare-step-circle",children:c?(0,D.jsx)("span",{className:"compare-step-spin"}):o})})]},"step-p-".concat(e.deliveryid))}))}),(0,D.jsx)("div",{className:"compare-timeline-track is-actual",children:Nt.map(((e,s)=>{var t;const a=String(e.orderstatus||"").toLowerCase(),i=z.has(a),l=M.has(a),n=_s===e.sequenceStep,c=e.isLoading&&0===e.coordsCount,d=!e.isLoading&&0===e.coordsCount,o=(null===(t=e.order)||void 0===t?void 0:t.step)||e.sequenceStep,p=P(o-1),u=["compare-step",n&&"is-focused",i&&"is-delivered",l&&"is-skipped",!i&&!l&&"is-pending",c&&"is-loading",d&&"is-no-data",e.anomaly&&"is-anomaly"].filter(Boolean).join(" ");return(0,D.jsxs)(r.Fragment,{children:[s>0&&(0,D.jsx)("span",{className:"compare-step-spacer"}),(0,D.jsxs)("button",{type:"button",className:u,style:{"--step-color":p},onClick:()=>Os((s=>s===e.sequenceStep?null:e.sequenceStep)),title:"Actual Visit ".concat(s+1," (Planned Step ").concat(o,")")+(e.deliverycustomer?" \xb7 ".concat(e.deliverycustomer):"")+(e.actualTs?" \xb7 ".concat(e.actualTs.format("hh:mm A")):"")+(e.anomaly?" \xb7 deviation flagged":""),children:[(0,D.jsx)("span",{className:"compare-step-circle",children:c?(0,D.jsx)("span",{className:"compare-step-spin"}):o}),e.actualTs&&(0,D.jsx)("span",{className:"compare-step-tick",children:e.actualTs.format("HH:mm")}),e.anomaly&&(0,D.jsx)("span",{className:"compare-step-flag",title:"Deviation flagged"})]})]},"step-a-".concat(e.deliveryid))}))})]})]}),(0,D.jsxs)("div",{className:"compare-progress-strip",children:[(0,D.jsx)("div",{className:"compare-progress-bar-wrap",children:(0,D.jsx)("div",{className:"compare-progress-bar-fill".concat(i?" is-done":""),style:{width:"".concat(a,"%")}})}),(0,D.jsx)("span",{className:"compare-progress-text",children:t>0?"Loading GPS\u2026 ".concat(s,"/").concat(e):"".concat(s,"/").concat(e," tracks")})]})]}),(()=>{const e="combined"===ks,s=l?P(l.sequenceStep-1):"linear-gradient(90deg, ".concat(C.slice(0,6).join(", "),")"),t=e?E:s,a=e?_:s;return(0,D.jsxs)("div",{className:"compare-legend",children:[(0,D.jsxs)("span",{className:"compare-legend-item",children:[(0,D.jsx)("span",{className:"compare-legend-swatch is-step-color is-dashed",style:{background:t}}),"Planned (dashed)"]}),(0,D.jsxs)("span",{className:"compare-legend-item",children:[(0,D.jsx)("span",{className:"compare-legend-swatch is-step-color",style:{background:a}}),"Actual GPS (solid)"]}),(0,D.jsx)("span",{className:"compare-legend-note",children:"Kalman-smoothed GPS \xb7 OSRM road-snapped"})]})})()]})]})})()}),bs&&dt&&(0,D.jsx)(q,{focusedRider:dt,compareDeltas:vt,compareSummary:jt,actualOrdered:Nt,focusedCompareStep:_s,setFocusedCompareStep:Os,sequenceOpen:ws,setSequenceOpen:Fs,expandedSeqGroups:Cs,setExpandedSeqGroups:Ps,onClose:()=>ys(!1)})]})]})}}}]);