Files
dailygrubs_console_build/build/static/js/9436.401a0111.chunk.js

1 line
152 KiB
JavaScript

"use strict";(self.webpackChunkmantis_material_react=self.webpackChunkmantis_material_react||[]).push([[9436],{23447:function(e,s,n){n.r(s),n.d(s,{default:function(){return Ee}});var r=n(45987),t=n(93433),i=n(74165),a=n(15861),c=n(4942),l=n(29439),d=n(37762),o=n(1413),u=n(47313),m=n(84536),p=n(39062),h=n(98817),v=n(74580),f=n(88153),x=n(73999),j=n(93854),g=n(45158),N=n(87248),b=n.n(N);n(63331);b().PolylineOffset={translatePoint:function(e,s,n){return b().point(e.x+s*Math.cos(n),e.y+s*Math.sin(n))},offsetPointLine:function(e,s){var n=e.length;if(n<2)throw new Error("Line should be defined by at least 2 points");for(var r,t=e[0],i=Math.PI/2,a=[],c=1;c<n;c++){r=e[c];var l=Math.atan2(r.y-t.y,r.x-t.x);a.push({offsetAngle:l-i,original:[t,r],offset:[this.translatePoint(t,s,l-i),this.translatePoint(r,s,l-i)]}),t=r}return a},intersection:function(e,s,n,r){var t=this.segmentAsVector(e,s),i=this.segmentAsVector(n,r),a=-i.x*t.y+t.x*i.y;if(0===a)return null;var c=(-t.y*(e.x-n.x)+t.x*(e.y-n.y))/a,l=(i.x*(e.y-n.y)-i.y*(e.x-n.x))/a;return c>=0&&c<=1&&l>=0&&l<=1?b().point(e.x+l*t.x,e.y+l*t.y):null},segmentAsVector:function(e,s){return b().point(s.x-e.x,s.y-e.y)},joinLineSegments:function(e){var s=[],n=e[0].offset;s.push(n[0]);for(var r=1;r<e.length;r++){var t=e[r].offset,i=this.intersection(n[0],n[1],t[0],t[1]);i?s.push(i):s.push(n[1]),n=t}return s.push(n[1]),s},offsetPoints:function(e,s){if(!e||e.length<2)return e;var n=this.offsetPointLine(e,s);return this.joinLineSegments(n)},offsetLatLngs:function(e,s,n){var r=s.map((function(s){return e.latLngToLayerPoint(s)}));return this.offsetPoints(r,n).map((function(s){return e.layerPointToLatLng(s)}))}};var y=b().Polyline.prototype._projectLatlngs;b().Polyline.prototype._projectLatlngs=function(e,s,n){var r=this,t=this.options.offset;if(!t||"number"!==typeof t)return y.call(this,e,s,n);if(e[0]instanceof b().LatLng){for(var i=e.map((function(e){return r._map.latLngToLayerPoint(e)})),a=b().PolylineOffset.offsetPoints(i,t),c=0;c<a.length;c++)n.extend(a[c]);s.push(a)}else for(var l=0;l<e.length;l++)this._projectLatlngs(e[l],s,n)};var k=n(10658),S=n.n(k),_=n(50581),w=n(41962),F=n(25963),A=n(71559),C=n(56573),E=n(22539),M=n(71049),z=n(29127),P=n(46417);var R=function(e){var s=e.focusedRider,n=e.compareDeltas,r=e.compareSummary,t=e.actualOrdered,i=e.focusedCompareStep,a=e.setFocusedCompareStep,c=e.sequenceOpen,d=e.setSequenceOpen,o=e.expandedSeqGroups,m=e.setExpandedSeqGroups,p=e.onClose,h=(0,u.useMemo)((function(){var e=r,i=e.onTime+e.late,a=n.filter((function(e){return e.anomaly})),c=n.filter((function(e){return z.Q6.has(String(e.orderstatus||"").toLowerCase())})).length,d=n.filter((function(e){return z.us.has(String(e.orderstatus||"").toLowerCase())})).length,o=null==e.kmDeltaPct?"":e.kmDeltaPct>25?"is-over":e.kmDeltaPct<-5?"is-under":"",u=n.length||1,m=e.onTime+e.late||1,p=Math.round(c/u*60+e.onTime/m*25+(u-e.anomalies)/u*15),h=p>=85?"#16a34a":p>=65?"#f59e0b":"#dc2626",v=p>=85?"Excellent":p>=65?"Acceptable":"Needs review",f=n.filter((function(e){return e.actualTs})),x=f.reduce((function(e,s){return!e||s.actualTs.isBefore(e)?s.actualTs:e}),null),j=f.reduce((function(e,s){return!e||s.actualTs.isAfter(e)?s.actualTs:e}),null),g=x&&j?Math.max(0,j.diff(x,"minute")):0,N=n.length>1?Math.round(g/(n.length-1)):0,b=g>0?(e.actualKm/(g/60)).toFixed(1):null,y=n.filter((function(e){return!e.isLoading&&e.coordsCount>0})),k=y.filter((function(e){return null!=e.timeDeltaMin&&!e.anomaly})).sort((function(e,s){return e.timeDeltaMin-s.timeDeltaMin}))[0]||null,S=y.filter((function(e){return e.anomaly})).sort((function(e,s){var n=Math.abs(e.kmDeltaPct||0)+(e.timeDeltaMin>0?e.timeDeltaMin:0);return Math.abs(s.kmDeltaPct||0)+(s.timeDeltaMin>0?s.timeDeltaMin:0)-n}))[0]||null,_=t.filter((function(e,s){var n,r=null===(n=e.order)||void 0===n?void 0:n.step;return null!=r&&r!==s+1})),w=[];_.forEach((function(e){var s,n=null===(s=e.order)||void 0===s?void 0:s.step,r=t.findIndex((function(s){return s.sequenceStep===e.sequenceStep}))+1,i=r-n,a=w[w.length-1];a&&a.delta===i&&a.lastActualPos+1===r?(a.items.push({d:e,planned:n,actualPos:r,delta:i}),a.lastActualPos=r):w.push({delta:i,items:[{d:e,planned:n,actualPos:r,delta:i}],lastActualPos:r})}));var F={};s.orders.forEach((function(e){var s=e.trip_number||1;F[s]||(F[s]=[]),F[s].push(e)}));var A=Object.entries(F).sort((function(e,s){var n=(0,l.Z)(e,1)[0],r=(0,l.Z)(s,1)[0];return Number(n)-Number(r)})).map((function(e){var s=(0,l.Z)(e,2),n=s[0],r=s[1];return{tNum:n,count:r.length,actualKm:r.reduce((function(e,s){return e+parseFloat(s.actualkms||s.kms||0)}),0),delivered:r.filter((function(e){return z.Q6.has(String(e.orderstatus||"").toLowerCase())})).length}}));return{sum:e,totalSteps:i,deviations:a,delivered:c,skipped:d,stepDeltaPct:o,score:p,scoreColor:h,scoreLabel:v,firstDelivery:x,lastDelivery:j,activeMin:g,avgPerStop:N,avgSpeed:b,bestStep:k,worstStep:S,outOfOrderSteps:_,seqRuns:w,tripList:A}}),[s,n,r,t]),v=null!=i?n.find((function(e){return e.sequenceStep===i})):null,f=function(e){a((function(s){return s===e?null:e}))},x=function(e){var s=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],n=e.d,r=e.planned,t=e.actualPos,a=e.delta;return(0,P.jsxs)("li",{className:"cdp-seq-diff".concat(i===n.sequenceStep?" is-focused":"").concat(s?"":" is-nested"),onClick:function(){return f(n.sequenceStep)},children:[(0,P.jsx)("span",{className:"cdp-seq-diff-num",style:{background:(0,z.di)((r||n.sequenceStep)-1)},children:r||n.sequenceStep}),(0,P.jsxs)("div",{className:"cdp-seq-diff-body",children:[(0,P.jsx)("div",{className:"cdp-seq-diff-title",children:n.deliverycustomer||"Step ".concat(r||n.sequenceStep)}),(0,P.jsxs)("div",{className:"cdp-seq-diff-sub",children:["Visited ",(0,P.jsx)("strong",{children:(0,z.xw)(t)})," ","\xb7 planned ",(0,P.jsx)("strong",{children:(0,z.xw)(r)})]})]}),(0,P.jsx)("span",{className:"cdp-seq-diff-tag",children:a>0?"+".concat(a):"".concat(a)})]},"diff-".concat(n.sequenceStep))},j=h.sum,g=h.totalSteps,N=h.deviations,b=h.delivered,y=h.skipped,k=h.stepDeltaPct,S=h.score,_=h.scoreColor,w=h.scoreLabel,F=h.firstDelivery,A=h.lastDelivery,C=h.activeMin,M=h.avgPerStop,R=h.avgSpeed,L=h.bestStep,D=h.worstStep,Z=h.outOfOrderSteps,q=h.seqRuns,O=h.tripList;return(0,P.jsxs)("aside",{id:"compare-data-panel",className:"compare-data-panel",children:[(0,P.jsxs)("div",{className:"cdp-head",children:[(0,P.jsxs)("div",{className:"cdp-head-title",children:[(0,P.jsx)("span",{className:"cdp-rider-dot",style:{background:s.color}}),(0,P.jsxs)("div",{className:"cdp-head-text",children:[(0,P.jsx)("div",{className:"cdp-rider-name",children:s.riderName}),(0,P.jsx)("div",{className:"cdp-head-badge",children:"PLANNED vs ACTUAL"})]})]}),(0,P.jsx)("button",{type:"button",className:"cdp-close",onClick:p,title:"Exit compare","aria-label":"Exit compare",children:(0,P.jsx)(E.FU5,{})})]}),(0,P.jsxs)("div",{className:"cdp-scroll",children:[(0,P.jsx)("section",{className:"cdp-section cdp-score-section",children:(0,P.jsxs)("div",{className:"cdp-score-wrap",children:[(0,P.jsx)("div",{className:"cdp-score-ring",style:{background:"conic-gradient(".concat(_," ").concat(3.6*S,"deg, rgba(15,23,42,0.08) 0deg)")},children:(0,P.jsxs)("div",{className:"cdp-score-inner",children:[(0,P.jsx)("div",{className:"cdp-score-value",style:{color:_},children:S}),(0,P.jsx)("div",{className:"cdp-score-unit",children:"/100"})]})}),(0,P.jsxs)("div",{className:"cdp-score-body",children:[(0,P.jsx)("div",{className:"cdp-score-label",style:{color:_},children:w}),(0,P.jsx)("div",{className:"cdp-score-title",children:"Compliance score"}),(0,P.jsxs)("div",{className:"cdp-score-sub",children:[b,"/",n.length," delivered",j.anomalies>0?" \xb7 ".concat(j.anomalies," deviation").concat(j.anomalies>1?"s":""):"",j.late>0?" \xb7 ".concat(j.late," late"):"",y>0?" \xb7 ".concat(y," skipped"):""]})]})]})}),(0,P.jsxs)("section",{className:"cdp-section",children:[(0,P.jsxs)("div",{className:"cdp-section-head",children:[(0,P.jsx)("span",{className:"cdp-section-icon",children:(0,P.jsx)(E.zNX,{})}),(0,P.jsx)("span",{className:"cdp-section-title",children:"Day overview"})]}),(0,P.jsxs)("div",{className:"cdp-tiles",children:[(0,P.jsxs)("div",{className:"cdp-tile",children:[(0,P.jsxs)("div",{className:"cdp-tile-label",children:[(0,P.jsx)(E.v93,{})," Distance"]}),(0,P.jsxs)("div",{className:"cdp-tile-value",children:[j.actualKm.toFixed(1),(0,P.jsx)("span",{className:"cdp-tile-unit",children:"km"})]}),(0,P.jsx)("div",{className:"cdp-tile-sub",children:"actual"})]}),(0,P.jsxs)("div",{className:"cdp-tile".concat(j.anomalies>0?" is-warn":""),children:[(0,P.jsxs)("div",{className:"cdp-tile-label",children:[(0,P.jsx)(E.YTL,{})," Deviation"]}),(0,P.jsx)("div",{className:"cdp-tile-value ".concat(k),children:null!=j.kmDeltaPct?"".concat(j.kmDeltaPct>0?"+":"").concat(j.kmDeltaPct.toFixed(0),"%"):"\u2014"}),(0,P.jsx)("div",{className:"cdp-tile-sub",children:j.anomalies>0?"".concat(j.anomalies," flagged"):"within plan"})]}),(0,P.jsxs)("div",{className:"cdp-tile".concat(j.late>0?" is-warn":""),children:[(0,P.jsxs)("div",{className:"cdp-tile-label",children:[(0,P.jsx)(E.dKE,{})," On-time"]}),(0,P.jsxs)("div",{className:"cdp-tile-value",children:[j.onTime,g>0&&(0,P.jsxs)("span",{className:"cdp-tile-unit",children:["/",g]})]}),(0,P.jsx)("div",{className:"cdp-tile-sub",children:j.late>0?"".concat(j.late," late"):"all on schedule"})]})]})]}),n.length>0&&(0,P.jsxs)("section",{className:"cdp-section cdp-seq-section",children:[(0,P.jsxs)("div",{className:"cdp-section-head cdp-section-head-clickable",onClick:function(){return d((function(e){return!e}))},role:"button","aria-expanded":c,title:c?"Collapse route sequence":"Expand route sequence",children:[(0,P.jsx)("span",{className:"cdp-section-icon",children:(0,P.jsx)(E.x82,{})}),(0,P.jsx)("span",{className:"cdp-section-title",children:"Route sequence"}),(0,P.jsx)("span",{className:"cdp-seq-status".concat(Z.length>0?" is-warn":" is-good"),children:Z.length>0?"".concat(Z.length," out of order"):"In order"}),(0,P.jsx)("span",{className:"cdp-seq-toggle".concat(c?" is-open":""),children:(0,P.jsx)(E.Yc6,{})})]}),c&&(0,P.jsx)("div",{className:"cdp-seq",children:Z.length>0?(0,P.jsx)("ul",{className:"cdp-seq-diffs",children:q.map((function(e,s){if(1===e.items.length)return x(e.items[0]);var n=e.items[0],r=e.items[e.items.length-1],t=o.has(s),a=e.delta>0?"+".concat(e.delta):"".concat(e.delta),c=e.items.some((function(e){return e.d.sequenceStep===i}));return(0,P.jsxs)(u.Fragment,{children:[(0,P.jsxs)("li",{className:"cdp-seq-diff is-group".concat(t?" is-expanded":"").concat(c?" is-focused":""),onClick:function(){return e=s,void m((function(s){var n=new Set(s);return n.has(e)?n.delete(e):n.add(e),n}));var e},"aria-expanded":t,children:[(0,P.jsxs)("span",{className:"cdp-seq-group-num",children:[(0,P.jsx)("span",{className:"cdp-seq-group-num-bg",style:{background:"linear-gradient(135deg, ".concat((0,z.di)((n.planned||1)-1),", ").concat((0,z.di)((r.planned||1)-1),")")}}),(0,P.jsxs)("span",{className:"cdp-seq-group-num-label",children:[e.items.length,"\xd7"]})]}),(0,P.jsxs)("div",{className:"cdp-seq-diff-body",children:[(0,P.jsxs)("div",{className:"cdp-seq-diff-title",children:[e.items.length," consecutive steps shifted"," ",(0,P.jsx)("span",{className:"cdp-seq-group-delta",children:a})]}),(0,P.jsxs)("div",{className:"cdp-seq-diff-sub",children:["Planned ",(0,z.xw)(n.planned),"\u2013",(0,z.xw)(r.planned)," ","visited"," ",(0,P.jsxs)("strong",{children:[(0,z.xw)(n.actualPos),"\u2013",(0,z.xw)(r.actualPos)]})]})]}),(0,P.jsx)("span",{className:"cdp-seq-diff-tag",children:a}),(0,P.jsx)("span",{className:"cdp-seq-group-toggle".concat(t?" is-open":""),"aria-hidden":"true",children:(0,P.jsx)(E.Yc6,{})})]}),t&&(0,P.jsx)("li",{className:"cdp-seq-group-children-wrap",children:(0,P.jsx)("ul",{className:"cdp-seq-group-children",children:e.items.map((function(e){return x(e,!1)}))})})]},"run-".concat(s,"-").concat(n.d.sequenceStep))}))}):(0,P.jsxs)("div",{className:"cdp-seq-good",children:[(0,P.jsx)(E.ZSR,{})," Rider followed the planned route in order."]})})]}),(F||A)&&(0,P.jsxs)("section",{className:"cdp-section cdp-timing-section",children:[(0,P.jsxs)("div",{className:"cdp-section-head",children:[(0,P.jsx)("span",{className:"cdp-section-icon",children:(0,P.jsx)(E.Vqd,{})}),(0,P.jsx)("span",{className:"cdp-section-title",children:"Timing"}),C>0&&(0,P.jsxs)("span",{className:"cdp-timing-active-tag",children:[(0,P.jsx)("span",{className:"cdp-timing-active-pulse"}),"Day window"]})]}),(0,P.jsxs)("div",{className:"cdp-timing-clock",children:[(0,P.jsxs)("div",{className:"cdp-clock-card is-start",children:[(0,P.jsxs)("div",{className:"cdp-clock-label",children:[(0,P.jsx)(E.KGF,{})," First delivery"]}),(0,P.jsxs)("div",{className:"cdp-clock-face",children:[(0,P.jsx)("span",{className:"cdp-clock-time",children:F?F.format("hh:mm"):"\u2014"}),(0,P.jsx)("span",{className:"cdp-clock-period",children:F?F.format("A"):""})]}),(0,P.jsx)("div",{className:"cdp-clock-caption",children:"Started"})]}),(0,P.jsxs)("div",{className:"cdp-clock-track","aria-hidden":"true",children:[(0,P.jsx)("span",{className:"cdp-clock-track-line"}),(0,P.jsx)("span",{className:"cdp-clock-track-dot is-start"}),(0,P.jsx)("span",{className:"cdp-clock-track-dot is-end"}),(0,P.jsxs)("div",{className:"cdp-clock-duration",children:[(0,P.jsx)("span",{className:"cdp-clock-duration-icon",children:(0,P.jsx)(E.TSC,{})}),(0,P.jsx)("span",{className:"cdp-clock-duration-val",children:C>0?C>=60?"".concat(Math.floor(C/60),"h ").concat(C%60,"m"):"".concat(C,"m"):"\u2014"}),(0,P.jsx)("span",{className:"cdp-clock-duration-sub",children:"active"})]})]}),(0,P.jsxs)("div",{className:"cdp-clock-card is-end",children:[(0,P.jsxs)("div",{className:"cdp-clock-label",children:[(0,P.jsx)(E.ZSR,{})," Last delivery"]}),(0,P.jsxs)("div",{className:"cdp-clock-face",children:[(0,P.jsx)("span",{className:"cdp-clock-time",children:A?A.format("hh:mm"):"\u2014"}),(0,P.jsx)("span",{className:"cdp-clock-period",children:A?A.format("A"):""})]}),(0,P.jsx)("div",{className:"cdp-clock-caption",children:"Finished"})]})]}),(0,P.jsxs)("div",{className:"cdp-timing-stats",children:[(0,P.jsxs)("div",{className:"cdp-timing-stat",children:[(0,P.jsxs)("div",{className:"cdp-timing-stat-head",children:[(0,P.jsx)("div",{className:"cdp-timing-stat-icon",children:(0,P.jsx)(E.dKE,{})}),(0,P.jsxs)("div",{className:"cdp-timing-stat-body",children:[(0,P.jsxs)("div",{className:"cdp-timing-stat-value",children:[M>0?"".concat(M):"\u2014",M>0&&(0,P.jsx)("span",{className:"cdp-timing-stat-unit",children:"min"})]}),(0,P.jsx)("div",{className:"cdp-timing-stat-label",children:"Avg / stop"})]})]}),n.length>0&&(0,P.jsxs)("div",{className:"cdp-timing-stat-viz cdp-stops-dots","aria-hidden":"true",children:[Array.from({length:Math.min(n.length,12)}).map((function(e,s){return(0,P.jsx)("span",{className:"cdp-stop-dot"},"dot-".concat(s))})),(0,P.jsxs)("span",{className:"cdp-timing-stat-viz-label",children:[n.length," stop",1===n.length?"":"s"]})]})]}),null!=R&&(0,P.jsxs)("div",{className:"cdp-timing-stat",children:[(0,P.jsxs)("div",{className:"cdp-timing-stat-head",children:[(0,P.jsx)("div",{className:"cdp-timing-stat-icon",children:(0,P.jsx)(E.JKp,{})}),(0,P.jsxs)("div",{className:"cdp-timing-stat-body",children:[(0,P.jsxs)("div",{className:"cdp-timing-stat-value",children:[R,(0,P.jsx)("span",{className:"cdp-timing-stat-unit",children:"km/h"})]}),(0,P.jsx)("div",{className:"cdp-timing-stat-label",children:"Avg speed"})]})]}),(0,P.jsxs)("div",{className:"cdp-timing-stat-viz cdp-speed-gauge","aria-hidden":"true",children:[(0,P.jsx)("div",{className:"cdp-speed-gauge-track",children:(0,P.jsx)("div",{className:"cdp-speed-gauge-fill",style:{width:"".concat(Math.min(100,parseFloat(R)/60*100),"%")}})}),(0,P.jsxs)("div",{className:"cdp-speed-gauge-scale",children:[(0,P.jsx)("span",{children:"0"}),(0,P.jsx)("span",{children:"30"}),(0,P.jsx)("span",{children:"60 km/h"})]})]})]})]})]}),(L||D)&&(0,P.jsxs)("section",{className:"cdp-section",children:[(0,P.jsxs)("div",{className:"cdp-section-head",children:[(0,P.jsx)("span",{className:"cdp-section-icon",children:(0,P.jsx)(E.MVI,{})}),(0,P.jsx)("span",{className:"cdp-section-title",children:"Highlights"})]}),(0,P.jsxs)("div",{className:"cdp-highlights",children:[L&&(0,P.jsxs)("div",{className:"cdp-highlight is-best",onClick:function(){return f(L.sequenceStep)},role:"button",title:"Focus this step",children:[(0,P.jsx)("span",{className:"cdp-highlight-rail","aria-hidden":"true"}),(0,P.jsxs)("div",{className:"cdp-highlight-content",children:[(0,P.jsxs)("div",{className:"cdp-highlight-top",children:[(0,P.jsxs)("span",{className:"cdp-highlight-label",children:[(0,P.jsx)("span",{className:"cdp-highlight-chip",children:(0,P.jsx)(E.ZSR,{})}),"Fastest stop"]}),(0,P.jsxs)("span",{className:"cdp-highlight-step-chip",style:{background:(0,z.di)(L.sequenceStep-1)},children:["Step ",L.sequenceStep]})]}),(0,P.jsx)("div",{className:"cdp-highlight-title",children:L.deliverycustomer||"Step ".concat(L.sequenceStep)}),(0,P.jsx)("div",{className:"cdp-highlight-meta",children:(0,P.jsx)("span",{className:"cdp-highlight-pill is-good",children:null!=L.timeDeltaMin?0===L.timeDeltaMin?"On schedule":"".concat(L.timeDeltaMin>0?"+":"").concat(L.timeDeltaMin," min vs plan"):"On schedule"})})]})]}),D&&(0,P.jsxs)("div",{className:"cdp-highlight is-worst",onClick:function(){return f(D.sequenceStep)},role:"button",title:"Focus this step",children:[(0,P.jsx)("span",{className:"cdp-highlight-rail","aria-hidden":"true"}),(0,P.jsxs)("div",{className:"cdp-highlight-content",children:[(0,P.jsxs)("div",{className:"cdp-highlight-top",children:[(0,P.jsxs)("span",{className:"cdp-highlight-label",children:[(0,P.jsx)("span",{className:"cdp-highlight-chip",children:(0,P.jsx)(E.YTL,{})}),"Biggest deviation"]}),(0,P.jsxs)("span",{className:"cdp-highlight-step-chip",style:{background:(0,z.di)(D.sequenceStep-1)},children:["Step ",D.sequenceStep]})]}),(0,P.jsx)("div",{className:"cdp-highlight-title",children:D.deliverycustomer||"Step ".concat(D.sequenceStep)}),(0,P.jsxs)("div",{className:"cdp-highlight-meta",children:[null!=D.kmDeltaPct&&(0,P.jsxs)("span",{className:"cdp-highlight-pill is-bad",children:[D.kmDeltaPct>0?"+":"",D.kmDeltaPct.toFixed(0),"% route"]}),null!=D.timeDeltaMin&&D.timeDeltaMin>0&&(0,P.jsxs)("span",{className:"cdp-highlight-pill is-bad",children:["+",D.timeDeltaMin,"m late"]})]})]})]})]})]}),O.length>1&&(0,P.jsxs)("section",{className:"cdp-section",children:[(0,P.jsxs)("div",{className:"cdp-section-head",children:[(0,P.jsx)("span",{className:"cdp-section-icon",children:(0,P.jsx)(E.x82,{})}),(0,P.jsxs)("span",{className:"cdp-section-title",children:["Trips (",O.length,")"]})]}),(0,P.jsx)("div",{className:"cdp-trips",children:O.map((function(e){return(0,P.jsxs)("div",{className:"cdp-trip",children:[(0,P.jsxs)("div",{className:"cdp-trip-head",children:[(0,P.jsxs)("span",{className:"cdp-trip-badge",children:["Trip ",e.tNum]}),(0,P.jsxs)("span",{className:"cdp-trip-meta",children:[e.delivered,"/",e.count," delivered"]})]}),(0,P.jsx)("div",{className:"cdp-trip-stats",children:(0,P.jsxs)("span",{title:"Distance",children:[(0,P.jsx)(E.v93,{}),e.actualKm.toFixed(1),"km"]})})]},"trip-".concat(e.tNum))}))})]}),v&&function(){var e=(0,z.di)(v.sequenceStep-1),s=null!=v.timeDeltaMin?v.timeDeltaMin>10?"is-over":v.timeDeltaMin<-2?"is-under":"":"",n=(0,z.Cl)(v.orderstatus);return(0,P.jsxs)("section",{className:"cdp-section",children:[(0,P.jsxs)("div",{className:"cdp-section-head",children:[(0,P.jsx)("span",{className:"cdp-section-icon",children:(0,P.jsx)(E.x82,{})}),(0,P.jsxs)("span",{className:"cdp-section-title",children:["Step ",v.sequenceStep," details"]}),(0,P.jsx)("button",{type:"button",className:"cdp-section-clear",onClick:function(){return a(null)},title:"Clear step focus",children:"Show all"})]}),(0,P.jsxs)("div",{className:"compare-delta".concat(v.anomaly?" is-anomaly":""),children:[(0,P.jsxs)("div",{className:"compare-delta-title",children:[(0,P.jsx)("span",{className:"compare-delta-step-badge",style:{background:e},children:v.sequenceStep}),(0,P.jsxs)("div",{className:"compare-delta-title-text",children:[(0,P.jsx)("div",{className:"compare-delta-title-main",children:v.deliverycustomer||"Step ".concat(v.sequenceStep)}),(0,P.jsxs)("div",{className:"compare-delta-title-sub",children:[v.pickupcustomer?"from ".concat(v.pickupcustomer," \xb7 "):"","Order #",v.orderid]})]}),v.orderstatus&&(0,P.jsx)("span",{className:"compare-delta-status",style:{background:n.bg,color:n.fg},children:n.label})]}),(0,P.jsxs)("div",{className:"compare-delta-grid",children:[(0,P.jsxs)("div",{className:"compare-delta-cell".concat(v.anomaly?" is-anomaly":""),children:[(0,P.jsx)("span",{className:"compare-delta-cell-label",children:"Distance"}),(0,P.jsxs)("span",{className:"compare-delta-cell-val",children:[v.actualKm.toFixed(2)," ",(0,P.jsx)("span",{className:"compare-delta-cell-unit",children:"km"})]}),(0,P.jsx)("span",{className:"compare-delta-cell-sub",children:"actual"})]}),(0,P.jsxs)("div",{className:"compare-delta-cell",children:[(0,P.jsx)("span",{className:"compare-delta-cell-label",children:"Time"}),(0,P.jsx)("span",{className:"compare-delta-cell-val ".concat(s),children:null!=v.timeDeltaMin?"".concat(v.timeDeltaMin>0?"+":"").concat(v.timeDeltaMin," min"):"\u2014"}),(0,P.jsx)("span",{className:"compare-delta-cell-sub",children:v.actualTs&&v.expectedTs?"".concat(v.actualTs.format("HH:mm")," vs ").concat(v.expectedTs.format("HH:mm")):v.actualTs?"delivered ".concat(v.actualTs.format("HH:mm")):"in flight"})]})]})]})]})}(),N.length>0&&(0,P.jsxs)("section",{className:"cdp-section",children:[(0,P.jsxs)("div",{className:"cdp-section-head",children:[(0,P.jsx)("span",{className:"cdp-section-icon cdp-icon-warn",children:(0,P.jsx)(E.wr$,{})}),(0,P.jsxs)("span",{className:"cdp-section-title",children:["Deviations (",N.length,")"]})]}),(0,P.jsx)("ul",{className:"cdp-dev-list",children:N.map((function(e){var s=(0,z.di)(e.sequenceStep-1),n=e.kmDelta>=0?"+":"";return(0,P.jsxs)("li",{className:"cdp-dev-item".concat(i===e.sequenceStep?" is-focused":""),onClick:function(){return f(e.sequenceStep)},children:[(0,P.jsx)("span",{className:"cdp-dev-num",style:{background:s},children:e.sequenceStep}),(0,P.jsxs)("div",{className:"cdp-dev-body",children:[(0,P.jsx)("div",{className:"cdp-dev-title",children:e.deliverycustomer||"Step ".concat(e.sequenceStep)}),(0,P.jsxs)("div",{className:"cdp-dev-meta",children:[null!=e.kmDeltaPct&&(0,P.jsxs)("span",{className:"cdp-dev-chip is-over",children:[n,e.kmDeltaPct.toFixed(0),"% route"]}),null!=e.timeDeltaMin&&e.timeDeltaMin>10&&(0,P.jsxs)("span",{className:"cdp-dev-chip is-over",children:["+",e.timeDeltaMin,"m late"]})]})]})]},"dev-".concat(e.sequenceStep))}))})]}),(0,P.jsxs)("section",{className:"cdp-section",children:[(0,P.jsxs)("div",{className:"cdp-section-head",children:[(0,P.jsx)("span",{className:"cdp-section-icon",children:(0,P.jsx)(E.f_H,{})}),(0,P.jsxs)("span",{className:"cdp-section-title",children:["Steps (",n.length,")"]}),(0,P.jsxs)("span",{className:"cdp-section-sub",children:[b,"/",n.length," delivered"]})]}),(0,P.jsx)("ul",{className:"cdp-step-list",children:n.map((function(e){var s=(0,z.di)(e.sequenceStep-1),n=String(e.orderstatus||"").toLowerCase(),r=z.Q6.has(n),t=z.us.has(n),a=r&&!e.anomaly,c=i===e.sequenceStep,l=(0,z.Cl)(e.orderstatus),d=null!=e.timeDeltaMin?e.timeDeltaMin>10?"is-over":e.timeDeltaMin<-2?"is-under":"":"",o=["cdp-step",c?"is-focused":"",e.anomaly?"is-anomaly":"",a?"is-correct":"",t?"is-skipped":"",e.isLoading?"is-loading":""].filter(Boolean).join(" ");return(0,P.jsxs)("li",{className:o,onClick:function(){return f(e.sequenceStep)},children:[(0,P.jsxs)("span",{className:"cdp-step-num",style:{background:s},children:[e.sequenceStep,a&&(0,P.jsx)("span",{className:"cdp-step-check",children:(0,P.jsx)(E.ZSR,{})}),e.anomaly&&(0,P.jsx)("span",{className:"cdp-step-flag",children:(0,P.jsx)(E.wr$,{})})]}),(0,P.jsxs)("div",{className:"cdp-step-body",children:[(0,P.jsxs)("div",{className:"cdp-step-title-row",children:[(0,P.jsx)("span",{className:"cdp-step-title",children:e.deliverycustomer||"Step ".concat(e.sequenceStep)}),e.orderstatus&&(0,P.jsx)("span",{className:"cdp-step-status",style:{background:l.bg,color:l.fg},children:l.label})]}),(0,P.jsxs)("div",{className:"cdp-step-sub",children:[e.pickupcustomer?"from ".concat(e.pickupcustomer," \xb7 "):"","Order #",e.orderid]}),(0,P.jsxs)("div",{className:"cdp-step-deltas",children:[(0,P.jsxs)("span",{className:"cdp-step-delta",title:"Distance",children:[(0,P.jsx)(E.v93,{}),e.actualKm.toFixed(1),"km"]}),(0,P.jsxs)("span",{className:"cdp-step-delta ".concat(d),title:"Delivery time",children:[(0,P.jsx)(E.dKE,{}),e.actualTs?e.actualTs.format("HH:mm"):"\u2014",null!=e.timeDeltaMin&&(0,P.jsxs)("small",{children:[" ",e.timeDeltaMin>0?"+":"",e.timeDeltaMin,"m"]})]})]})]})]},"step-".concat(e.sequenceStep))}))})]})]})]})},L=n(85281),D=n(62180),Z=function(e){var s=e.visibleRiders,n=e.riders,r=e.focusedStop,t=e.handleRiderFocus,i=e.setFocusedStop,a=e.calculateEstMeters,c=e.getRiderColor,d=e.formatMeters,o=e.isLoading,m=s.map((function(e){return(0,z.P0)(e.orders)})).filter(Boolean).sort((function(e,s){var n,r;return(null!==(n=a(e.rider_id||e.userid,e))&&void 0!==n?n:1/0)-(null!==(r=a(s.rider_id||s.userid,s))&&void 0!==r?r:1/0)})),p=(0,u.useRef)(null);if((0,u.useEffect)((function(){var e={};s.forEach((function(s){(s.orders||[]).forEach((function(s){e[String(s.orderid)]={status:String(s.orderstatus||"").toLowerCase(),riderName:s.rider_name||s.ridername||"Rider",customer:s.deliverycustomer||s.customername||"Order #".concat(s.orderid)}}))}));var n=p.current;null!==n&&Object.entries(e).forEach((function(e){var s=(0,l.Z)(e,2),r=s[0],t=s[1],i=n[r];i?("active"!==i.status&&"active"===t.status&&(0,D.y)("\ud83d\udef5 ".concat(t.riderName," is now delivering to ").concat(t.customer),"success",3e3),"active"===i.status&&"delivered"===t.status&&(0,D.y)("\ud83d\udccd ".concat(t.riderName," has reached ").concat(t.customer,"'s location"),"info",3e3)):"active"===t.status&&(0,D.y)("\ud83d\udef5 ".concat(t.riderName," is now delivering to ").concat(t.customer),"success",3e3)})),p.current=e}),[s]),o)return(0,P.jsxs)("div",{className:"empty-slot",style:{display:"flex",flexDirection:"column",alignItems:"center",justifyContent:"center",height:"100%",minHeight:"200px"},children:[(0,P.jsx)(L.Z,{size:30,style:{color:"#7b1fa2",marginBottom:"16px"}}),(0,P.jsx)("div",{className:"empty-slot-title",children:"Loading active deliveries..."})]});if(0===m.length)return(0,P.jsxs)("div",{className:"empty-slot",children:[(0,P.jsx)("div",{className:"empty-slot-icon",children:(0,P.jsx)(E.ByW,{})}),(0,P.jsx)("div",{className:"empty-slot-title",children:"No active deliveries"}),(0,P.jsx)("div",{className:"empty-slot-sub",children:"No deliveries are currently in progress for this slot"})]});return(0,P.jsx)("div",{className:"adcard-list",children:m.map((function(e,s){var l=e.rider_id||e.userid,o=n.find((function(e){return String(e.id)===String(l)})),u=c(l),m=(0,z.Cl)(e.orderstatus),p=parseFloat(e.droplat||e.deliverylat),h=parseFloat(e.droplon||e.deliverylong),v=Number.isFinite(p)&&Number.isFinite(h),f=a(l,e),x=e.deliverycustomer||e.customername||"Order #".concat(e.orderid),j=e.deliverysuburb||e.deliveryaddress||e.zone_name||"",g=e.rider_name||e.ridername||"Unassigned",N=v&&r&&String(r.orderid)===String(e.orderid),b=g.split(/\s+/).filter(Boolean).slice(0,2).map((function(e){return e[0]})).join("").toUpperCase()||"\u2022";return(0,P.jsxs)("div",{className:"adcard".concat(N?" is-active":""),style:{"--ad-accent":u},onClick:function(){o&&t(o),v&&i({orderid:e.orderid,lat:p,lon:h})},children:[(0,P.jsxs)("div",{className:"adcard-top",children:[(0,P.jsx)("div",{className:"adcard-avatar",style:{background:u},children:b}),(0,P.jsxs)("div",{className:"adcard-titles",children:[(0,P.jsxs)("div",{className:"adcard-rider",title:g,children:[(0,P.jsx)(E.pbk,{style:{fontSize:13,flexShrink:0}}),(0,P.jsx)("span",{className:"adcard-tx",children:g})]}),(0,P.jsx)("div",{className:"adcard-customer",title:x,children:x})]}),(0,P.jsxs)("div",{style:{display:"flex",flexDirection:"column",alignItems:"flex-end",gap:"4px"},children:[(0,P.jsx)("span",{className:"adcard-status",style:{background:"".concat(m.bg,"1a"),color:m.bg},title:m.label,children:m.label}),e.deliverytime&&(0,P.jsx)("span",{className:"adcard-time",style:{fontSize:"11px",color:"#64748b"},children:S()(e.deliverytime).isValid()?S()(e.deliverytime).format("HH:mm:ss"):String(e.deliverytime)})]})]}),j&&(0,P.jsxs)("div",{className:"adcard-addr",children:[(0,P.jsx)("span",{className:"adcard-ic",children:(0,P.jsx)(E.$0r,{})}),(0,P.jsx)("span",{className:"adcard-tx adcard-addr-tx",title:j,children:j})]}),(0,P.jsxs)("div",{className:"adcard-foot",children:[e.pickupcustomer?(0,P.jsxs)("span",{className:"adcard-pickup",title:e.pickupcustomer,children:[(0,P.jsx)("span",{className:"adcard-ic",children:(0,P.jsx)(E.TkG,{})}),(0,P.jsx)("span",{className:"adcard-tx",children:e.pickupcustomer})]}):(0,P.jsx)("span",{}),(0,P.jsx)("span",{className:"adcard-metrics",children:null!==f&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)("span",{className:"adcard-m adcard-m-eta",title:"Distance to drop",children:[(0,P.jsx)("span",{className:"adcard-ic",children:(0,P.jsx)(E.x$F,{})}),d(f)]}),(0,P.jsxs)("span",{className:"adcard-m adcard-m-time",title:"Estimated time to drop",children:[(0,P.jsx)("span",{className:"adcard-ic",children:(0,P.jsx)(E.dKE,{})}),function(){var e=f/1e3/20*60;return e<1?"< 1 min":"".concat(Math.ceil(e)," min")}()]})]})})]})]},e.orderid)}))})},q=n(84506),O={DEBUG:0,INFO:1,WARN:2,ERROR:3},T=O.WARN,I=function(e,s){return"background: ".concat(e,"; color: ").concat(s,"; padding: 2px 5px; border-radius: 4px; font-weight: bold;")},H=I("#2563eb","#ffffff"),K=console.log,B=console.warn||console.log,Y=console.error||console.log,G=function(e,s,n){if(!(O[e]<T)){var r=(0,q.Z)(s),i=r[0],a=r.slice(1),c="string"===typeof i,l="".concat("%c[NearlExpress]","%c ").concat(e),d=[H,n],o="ERROR"===e?Y:"WARN"===e?B:K;c?o.apply(void 0,["".concat(l,"%c ").concat(i)].concat(d,["color: inherit;"],(0,t.Z)(a))):o.apply(void 0,["".concat(l)].concat(d,[i],(0,t.Z)(a)))}},U={debug:function(){for(var e=arguments.length,s=new Array(e),n=0;n<e;n++)s[n]=arguments[n];return G("DEBUG",s,I("#64748b","#ffffff"))},info:function(){for(var e=arguments.length,s=new Array(e),n=0;n<e;n++)s[n]=arguments[n];return G("INFO",s,I("#10b981","#ffffff"))},warn:function(){for(var e=arguments.length,s=new Array(e),n=0;n<e;n++)s[n]=arguments[n];return G("WARN",s,I("#f59e0b","#ffffff"))},error:function(){for(var e=arguments.length,s=new Array(e),n=0;n<e;n++)s[n]=arguments[n];G("ERROR",s,I("#ef4444","#ffffff"))}},V=U,W=["_ts"],J="#6366f1",Q="#10b981",$=function(e){var s=parseFloat(e);return Number.isFinite(s)?s:NaN},X=function(e){if(!e)return"";var s=String(e).trim();if(!s)return"";if(s.includes(",")){var n=s.split(",").map((function(e){return e.trim()})).filter(Boolean);return 0===n.length?s:n.length<=2?n.join(", "):n.slice(-2).join(", ")}var r=s.split(/\s+/).filter(Boolean),t=r.length>6?r.slice(-6).join(" "):s;return t.length>40?"".concat(t.slice(0,40).trim(),"\u2026"):t},ee=function(e){return Number.isFinite($(e.droplat||e.deliverylat))&&Number.isFinite($(e.droplon||e.deliverylong))},se=function(e){return e.pickuplat||e.pickuplatitude||e.pickup_lat},ne=function(e){return e.pickuplong||e.pickuplongitude||e.picklongitude||e.pickup_lon},re=function(e){return Number.isFinite($(se(e)))&&Number.isFinite($(ne(e)))},te=[{id:"morning",name:"Morning Batch",startHour:0,endHour:8},{id:"afternoon",name:"Afternoon Batch",startHour:9,endHour:12.5},{id:"evening",name:"Evening Batch",startHour:16,endHour:19}],ie="dispatch.slots.v8",ae=["dispatch.slots.v1","dispatch.slots.v2","dispatch.slots.v3","dispatch.slots.v4","dispatch.slots.v5","dispatch.slots.v6","dispatch.slots.v7"],ce=function(e,s){return"Slot ".concat(e+1," \xb7 ").concat(le(s))},le=function(e){var s=Math.floor(e),n=Math.round(60*(e-s)),r=(s+11)%12+1,t=s>=12&&s<24?"PM":"AM";if(0===n)return"".concat(r," ").concat(t);var i=String(n).padStart(2,"0");return"".concat(r,":").concat(i," ").concat(t)},de=function(e,s){return s>=24?"After ".concat(le(e)):"".concat(le(e),"\u2013").concat(le(s))},oe=te.map((function(e,s){return(0,o.Z)((0,o.Z)({},e),{},{label:e.name||ce(s,e.startHour),range:de(e.startHour,e.endHour)})})),ue=function(e,s){var n,r=(0,d.Z)(s);try{for(r.s();!(n=r.n()).done;){var t=n.value;if(e>=t.startHour&&e<t.endHour)return t.id}}catch(i){r.e(i)}finally{r.f()}return null},me=[{id:"delivered",label:"Delivered",keys:["deliverytime"]},{id:"pending",label:"Pending",keys:["expecteddeliverytime"]},{id:"assigned",label:"Assigned",keys:["assigntime"]},{id:"accepted",label:"Accepted",keys:["acceptedtime"]},{id:"started",label:"Started",keys:["starttime"]},{id:"arrived",label:"Arrived",keys:["arrivaltime"]},{id:"pickup",label:"Pickup",keys:["pickuptime"]},{id:"all",label:"All",keys:["deliverytime","expecteddeliverytime","assigntime","acceptedtime","arrivaltime","pickuptime","starttime"]}],pe=function(e,s){var n,r=me.find((function(e){return e.id===s}))||me[0],t=(0,d.Z)(r.keys);try{for(t.s();!(n=t.n()).done;){var i=n.value;if(null!==e&&void 0!==e&&e[i])return e[i]}}catch(a){t.e(a)}finally{t.f()}return null},he=function(e){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"all",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:oe,r=pe(e,s);if(!r)return null;var t=String(r).trim();if(/^\d{4}-\d{2}-\d{2}$/.test(t))return null;var i=S()(r);return i.isValid()?ue(i.hour()+i.minute()/60,n):null};function ve(e){var s=e.targetRef,n=(0,m.Sx)();return(0,u.useEffect)((function(){return s.current=n,function(){s.current=null}}),[n]),null}function fe(e,s){var n=function(e){return e*Math.PI/180},r=n(e[0]),t=n(s[0]),i=n(s[0]-e[0]),a=n(s[1]-e[1]),c=Math.pow(Math.sin(i/2),2)+Math.cos(r)*Math.cos(t)*Math.pow(Math.sin(a/2),2);return 12742*Math.asin(Math.min(1,Math.sqrt(c)))}function xe(e){if(!Array.isArray(e)||e.length<2)return 0;for(var s=0,n=1;n<e.length;n++)s+=fe(e[n-1],e[n]);return s}function je(e){var 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}];var n=null!=s.processNoise?s.processNoise:1e-9,r=null!=s.measurementNoise?s.measurementNoise:1e-7,t=function(e){return e._ts||(e.logdate?new Date(e.logdate).getTime():0)},i=function(s){for(var i=e[0][s],a=0,c=1,l=0,d=0,o=1,u=[i],m=t(e[0]),p=1;p<e.length;p++){var h=t(e[p])||m+1e3,v=Math.max(.1,(h-m)/1e3);m=h;var f=i+a*v,x=a,j=v*v,g=j*v,N=c+v*(l+d)+j*o+g*v/4*n,b=l+v*o+g/2*n,y=d+v*o+g/2*n,k=o+j*n,S=e[p][s]-f,_=N+r,w=N/_,F=y/_;i=f+w*S,a=x+F*S,c=(1-w)*N,l=(1-w)*b,d=y-F*N,o=k-F*b,u.push(i)}return u},a=i("lat"),c=i("lng");return e.map((function(e,s){return{lat:a[s],lng:c[s],logdate:e.logdate,_ts:e._ts}}))}function ge(e,s){if(!Array.isArray(e)||e.length<2||!s||!s.length)return[];for(var n=s.map((function(s){for(var n=0,r=1/0,t=0;t<e.length;t++){var i=e[t][0]-s[0],a=e[t][1]-s[1],c=i*i+a*a;c<r&&(r=c,n=t)}return n})),r=1;r<n.length;r++)n[r]<n[r-1]&&(n[r]=n[r-1]);var t=[],i=0;return n.forEach((function(s){var n=Math.max(s,i);t.push(e.slice(i,n+1)),i=n})),t}var Ne=function(e){if(!e)return null;var s=S()(e);return s.isValid()?s.format("HH:mm:ss"):String(e)},be=[{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}],ye=function(e){var s=e.filter(ee);if(!s.length)return[];var n=e.find(re),r=[];return n&&r.push([$(se(n)),$(ne(n))]),s.forEach((function(e){return r.push([$(e.droplat||e.deliverylat),$(e.droplon||e.deliverylong)])})),r};delete b().Icon.Default.prototype._getIconUrl,b().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"});var ke=["#0055FF","#00D82C","#FF6B00","#9D00FF","#FF00A8","#00C2B2","#FF9900","#FF0000"],Se=function(e){var s=String(null!==e&&void 0!==e?e:"");if(!s)return ke[0];for(var n=0,r=0;r<s.length;r++)n=31*n+s.charCodeAt(r)>>>0;return ke[n%ke.length]},_e=function(e){var s=e.focusedItem,n=e.viewMode,r=e.orders,t=e.kitchens,i=e.locationKey,a=e.extraPoints,c=e.flyTo,l=(0,m.Sx)();(0,u.useEffect)((function(){c&&l.setView([c.lat,c.lon],16,{animate:!0,duration:.6})}),[c,l]);var o=(0,u.useRef)(""),p=(0,u.useMemo)((function(){var e=null!=i?"loc:".concat(i,"|"):"",c=function(e){var s,n=0,r=0,t=0,i=(0,d.Z)(e);try{for(i.s();!(s=i.n()).done;){var a=s.value;Number.isFinite(a[0])&&Number.isFinite(a[1])&&(n+=a[0],r+=a[1],t+=1)}}catch(c){i.e(c)}finally{i.f()}return 0===t?"0":"".concat((n/t).toFixed(1),",").concat((r/t).toFixed(1))};if(s){var l,o,u,m=null!==(l=null!==(o=null!==(u=s.id)&&void 0!==u?u:s.kitchenName)&&void 0!==o?o:s.name)&&void 0!==l?l:null!=s.lat?"".concat(s.lat,",").concat(s.lon):"item",p=s.orders?s.orders.length:0;return"".concat(e,"f|").concat(m,"|").concat(p)}var h=(t||[]).map((function(e){return[e.lat,e.lon]})),v=c(h);if("kitchens"===n){var f=h.filter((function(e){return Number.isFinite(e[0])&&Number.isFinite(e[1])})).length;return"".concat(e,"k|").concat(f,"|").concat(v)}if("all"===n){var x=(r||[]).map((function(e){return[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]})),j=a||[],g=x.concat(j);return"".concat(e,"a|").concat(g.length,"|").concat(c(g))}return"".concat(e,"m|").concat(n||"","|").concat(h.length,"|").concat(v)}),[s,n,r,t,i]);return(0,u.useEffect)((function(){if(o.current!==p){var e=[];s?s.orders&&s.orders.length?(e=s.orders.map((function(e){return[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]})),s.orders.forEach((function(s){return e.push([$(se(s)),$(ne(s))])}))):e=[[s.lat,s.lon]]:"kitchens"===n?0===(e=(t||[]).filter((function(e){return Number.isFinite(e.lat)&&Number.isFinite(e.lon)})).map((function(e){return[e.lat,e.lon]}))).length&&(e=(r||[]).map((function(e){return[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]}))):"all"===n?e=(e=(r||[]).map((function(e){return[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]}))).concat(a||[]):0===(e=(t||[]).filter((function(e){return Number.isFinite(e.lat)&&Number.isFinite(e.lon)})).map((function(e){return[e.lat,e.lon]}))).length&&(e=(r||[]).map((function(e){return[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]})));var i=e.filter((function(e){return Number.isFinite(e[0])&&Number.isFinite(e[1])}));if(i.length>0){var c=b().latLngBounds(i);c.isValid()&&(1===i.length||c.getNorthEast().equals(c.getSouthWest())?l.setView(i[0],15,{animate:!0,duration:.6}):l.flyToBounds(c,{padding:[60,60],duration:.6,maxZoom:16}),o.current=p)}else;}}),[p,s,n,r,t,a,l]),null},we=function(e){var s=e.target,n=e.icon,r=e.duration,t=void 0===r?950:r,i=e.zIndexOffset,a=e.eventHandlers,c=e.children,l=e.markerRef,d=(0,u.useRef)(null),o=(0,u.useRef)(null),m=(0,u.useRef)(s),h=(0,u.useRef)(null),v=Array.isArray(s)?Number(s[0]):NaN,f=Array.isArray(s)?Number(s[1]):NaN;return(0,u.useEffect)((function(){var e=d.current;if(e&&Number.isFinite(v)&&Number.isFinite(f)){var s=b().latLng(v,f),n=e.getLatLng();if(n){var r=s.lat-n.lat,i=s.lng-n.lng;if(!(Math.abs(r)<1e-6&&Math.abs(i)<1e-6)){var a=!1;try{a=n.distanceTo(s)>2e3}catch(x){a=!1}if(a)return e.setLatLng(s),void(h.current=performance.now());o.current&&cancelAnimationFrame(o.current);var c=performance.now(),l=null==h.current?t:c-h.current,u=Math.max(800,Math.min(32e3,l));h.current=c;var m=n.lat,p=n.lng;return o.current=requestAnimationFrame((function s(n){var t=Math.min(1,(n-c)/u);e.setLatLng([m+r*t,p+i*t]),t<1&&(o.current=requestAnimationFrame(s))})),function(){o.current&&cancelAnimationFrame(o.current)}}e.setLatLng(s)}else e.setLatLng(s)}}),[v,f,t]),(0,u.useEffect)((function(){return function(){o.current&&cancelAnimationFrame(o.current)}}),[]),(0,P.jsx)(p.J,{ref:function(e){d.current=e,"function"===typeof l?l(e):l&&(l.current=e)},position:m.current,icon:n,zIndexOffset:i,eventHandlers:a,children:c})},Fe=function(e){var s=e.children;return(0,P.jsx)("span",{className:"ico-inline",style:{display:"inline-flex",alignItems:"center",verticalAlign:"-2px",marginRight:4},children:s})},Ae=[{key:"morning",label:"Morning",timeRange:"12:00 AM \u2013 8:00 AM",sub:"Early shift orders",color:"#f59e0b",bg:"#fffbeb",border:"#fde68a"},{key:"afternoon",label:"Noon",timeRange:"9:00 AM \u2013 12:30 PM",sub:"Lunch rush window",color:"#10b981",bg:"#ecfdf5",border:"#a7f3d0"},{key:"evening",label:"Evening",timeRange:"4:00 PM \u2013 7:00 PM",sub:"Dinner & end-of-day",color:"#6366f1",bg:"#eef2ff",border:"#c7d2fe"}],Ce=function(e){if(null==e)return"\u2014";if("number"===typeof e)return e.toLocaleString("en-IN");var s=parseFloat(e);return Number.isFinite(s)?s.toLocaleString("en-IN"):String(e)},Ee=function(e){var s=e.data,n=e.embedded,m=void 0!==n&&n,N=e.selectedRiderId,y=e.onRiderSelect,k=e.pulseOrderId,L=null!==s&&void 0!==s&&s.zones&&s.zones.length>0?"zones":"riders",D=(0,u.useState)(L),q=(0,l.Z)(D,2),O=q[0],T=q[1],I=(0,u.useState)("live"),H=(0,l.Z)(I,2),K=H[0],B=(H[1],(0,u.useState)({})),Y=(0,l.Z)(B,2),G=Y[0],U=Y[1],le=(0,u.useState)(null),me=(0,l.Z)(le,2),pe=me[0],Ee=me[1],Me=(0,u.useState)(null),ze=(0,l.Z)(Me,2),Pe=ze[0],Re=ze[1],Le=(0,_.D)({mutationFn:M.UV,onMutate:function(e){return Ee(e.batch)},onSuccess:function(e,s){U((function(n){return(0,o.Z)((0,o.Z)({},n),{},(0,c.Z)({},s.batch,{data:e,fetchedAt:S()().format("HH:mm:ss")}))}))},onSettled:function(){return Ee(null)}}),De=function(e){Re(e);var s=G[e];s&&s.data&&!1!==s.data.success||Le.mutate({batch:e,tenantId:916})},Ze=(0,u.useState)(new Set),qe=(0,l.Z)(Ze,2),Oe=qe[0],Te=qe[1],Ie=(0,u.useState)(null),He=(0,l.Z)(Ie,2),Ke=He[0],Be=He[1],Ye=(0,u.useState)(null),Ge=(0,l.Z)(Ye,2),Ue=Ge[0],Ve=Ge[1],We=(0,u.useState)(null),Je=(0,l.Z)(We,2),Qe=Je[0],$e=Je[1],Xe=(0,u.useState)(null),es=(0,l.Z)(Xe,2),ss=es[0],ns=es[1],rs=(0,u.useState)(null),ts=(0,l.Z)(rs,2),is=ts[0],as=(ts[1],(0,u.useState)("planned")),cs=(0,l.Z)(as,2),ls=cs[0],ds=cs[1],os=(0,u.useRef)({}),us=(0,u.useRef)(new Set),ms=(0,u.useRef)(new Set),ps=(0,u.useRef)(new Map),hs=((0,u.useRef)(null),(0,u.useRef)(null)),vs=(0,u.useState)(null),fs=(0,l.Z)(vs,2),xs=fs[0],js=fs[1],gs=void 0!==N,Ns=(0,u.useState)(""),bs=(0,l.Z)(Ns,2),ys=bs[0],ks=bs[1],Ss=(0,w.a)({queryKey:["appLocations"],queryFn:M.gO,staleTime:3e5}).data,_s="undefined"!==typeof window?localStorage.getItem("applocationid"):null,ws=(0,u.useState)(null!=_s?Number(_s):0),Fs=(0,l.Z)(ws,2),As=Fs[0],Cs=(Fs[1],(0,u.useState)(!1)),Es=(0,l.Z)(Cs,2),Ms=Es[0],zs=Es[1],Ps=(0,u.useRef)(null),Rs=(0,u.useState)("assigned"),Ls=(0,l.Z)(Rs,2),Ds=Ls[0],Zs=(Ls[1],(0,u.useState)(!1)),qs=(0,l.Z)(Zs,2),Os=qs[0],Ts=qs[1],Is=(0,u.useRef)(null),Hs=(0,u.useState)((function(){if("undefined"===typeof window)return oe;try{var e=window.localStorage.getItem(ie);if(!e)return oe;var s=JSON.parse(e);return Array.isArray(s)&&s.length===te.length?s.map((function(e,s){var n=e.id||"slot-".concat(s+1),r=Number(e.startHour)||0,t=Number(e.endHour)||24,i=oe.find((function(e){return e.id===n}));return{id:n,startHour:r,endHour:t,label:(null===i||void 0===i?void 0:i.name)||ce(s,r),range:de(r,t)}})):oe}catch(n){return oe}})),Ks=(0,l.Z)(Hs,2),Bs=Ks[0],Ys=(Ks[1],Bs),Gs=(0,u.useState)(!1),Us=(0,l.Z)(Gs,2),Vs=Us[0],Ws=Us[1],Js=(0,u.useRef)(null);(0,u.useEffect)((function(){if("undefined"!==typeof window)try{ae.forEach((function(e){return window.localStorage.removeItem(e)}))}catch(e){}}),[]);var Qs=(0,u.useRef)(!1);(0,u.useEffect)((function(){if(Qs.current){if("undefined"!==typeof window)try{window.localStorage.setItem(ie,JSON.stringify(Bs.map((function(e){return{id:e.id,startHour:e.startHour,endHour:e.endHour}}))))}catch(e){}}else Qs.current=!0}),[Bs]),(0,u.useEffect)((function(){if(Ms){var e=function(e){Ps.current&&!Ps.current.contains(e.target)&&zs(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}}),[Ms]),(0,u.useEffect)((function(){if(Os){var e=function(e){Is.current&&!Is.current.contains(e.target)&&Ts(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}}),[Os]),(0,u.useEffect)((function(){if(Vs){var e=function(e){Js.current&&!Js.current.contains(e.target)&&Ws(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}}),[Vs]);var $s=(0,u.useState)(null),Xs=(0,l.Z)($s,2),en=Xs[0],sn=Xs[1],nn=(0,u.useState)(""),rn=(0,l.Z)(nn,2),tn=rn[0],an=rn[1],cn=(0,w.a)({queryKey:["riderPeriodicLog",en],queryFn:function(){return(0,M.hG)(en)},enabled:"rider-info"===O&&null!=en,refetchInterval:"rider-info"===O&&null!=en&&15e3,refetchIntervalInBackground:!1,staleTime:5e3,refetchOnWindowFocus:!1}),ln=cn.data,dn=cn.isFetching,on=cn.isError,un=cn.error,mn=(0,u.useMemo)((function(){var e=parseFloat(null===ln||void 0===ln?void 0:ln.latitude),s=parseFloat(null===ln||void 0===ln?void 0:ln.longitude);return Number.isFinite(e)&&Number.isFinite(s)?{lat:e.toFixed(4),lon:s.toFixed(4)}:null}),[null===ln||void 0===ln?void 0:ln.latitude,null===ln||void 0===ln?void 0:ln.longitude]),pn=(0,w.a)({queryKey:["reverseGeocode",null===mn||void 0===mn?void 0:mn.lat,null===mn||void 0===mn?void 0:mn.lon],queryFn:function(){var e=(0,a.Z)((0,i.Z)().mark((function e(){var s,n,r,t;return(0,i.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch("https://nominatim.openstreetmap.org/reverse?lat=".concat(mn.lat,"&lon=").concat(mn.lon,"&format=json&zoom=16&addressdetails=1"),{headers:{Accept:"application/json"}});case 2:if((s=e.sent).ok){e.next=5;break}return e.abrupt("return",null);case 5:return e.next=7,s.json();case 7:return n=e.sent,r=(null===n||void 0===n?void 0:n.address)||{},t=r.suburb||r.neighbourhood||r.village||r.hamlet||r.city_district||r.town||r.city||r.county||r.state||"",e.abrupt("return",{area:t,display:(null===n||void 0===n?void 0:n.display_name)||""});case 11:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),enabled:"rider-info"===O&&!!mn,staleTime:3e5,refetchOnWindowFocus:!1,retry:1}),hn=pn.data,vn=(0,u.useMemo)((function(){if(!Ss)return null;var e=Ss.find((function(e){return String(e.applocationid)===String(As)}));return(null===e||void 0===e?void 0:e.locationname)||null}),[Ss,As]),fn=(0,u.useState)({}),xn=(0,l.Z)(fn,2),jn=xn[0],gn=xn[1],Nn=(0,u.useRef)({}),bn=(0,u.useState)({}),yn=(0,l.Z)(bn,2),kn=yn[0],Sn=yn[1],_n=(0,u.useRef)({}),wn=(0,u.useState)(!1),Fn=(0,l.Z)(wn,2),An=Fn[0],Cn=Fn[1],En=(0,u.useState)([]),Mn=(0,l.Z)(En,2),zn=Mn[0],Pn=Mn[1],Rn=(0,u.useState)({}),Ln=(0,l.Z)(Rn,2),Dn=Ln[0],Zn=Ln[1],qn=(0,u.useRef)(!1),On=(0,u.useState)(S()().format("YYYY-MM-DD")),Tn=(0,l.Z)(On,2),In=Tn[0],Hn=Tn[1],Kn=(0,u.useState)(!1),Bn=(0,l.Z)(Kn,2),Yn=Bn[0],Gn=Bn[1],Un=(0,u.useState)((function(){return S()(In).isValid()?S()(In).startOf("month"):S()().startOf("month")})),Vn=(0,l.Z)(Un,2),Wn=Vn[0],Jn=Vn[1],Qn=(0,u.useRef)(null);(0,u.useEffect)((function(){if(Yn){var e=function(e){Qn.current&&(Qn.current.contains(e.target)||Gn(!1))},s=function(e){"Escape"===e.key&&Gn(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",s),function(){document.removeEventListener("mousedown",e),document.removeEventListener("keydown",s)}}}),[Yn]),(0,u.useEffect)((function(){if(Yn){var e=S()(In);e.isValid()&&Jn(e.startOf("month"))}}),[Yn,In]);var $n=(0,u.useState)(!1),Xn=(0,l.Z)($n,2),er=Xn[0],sr=Xn[1],nr=(0,u.useState)("combined"),rr=(0,l.Z)(nr,2),tr=rr[0],ir=rr[1],ar=(0,u.useState)(!0),cr=(0,l.Z)(ar,2),lr=cr[0],dr=cr[1],or=(0,u.useState)(!0),ur=(0,l.Z)(or,2),mr=ur[0],pr=ur[1],hr=(0,u.useState)((function(){return new Set})),vr=(0,l.Z)(hr,2),fr=vr[0],xr=vr[1],jr=(0,u.useRef)(!1),gr=(0,u.useState)(!1),Nr=(0,l.Z)(gr,2),br=Nr[0],yr=Nr[1],kr=(0,u.useRef)(!1),Sr=(0,u.useRef)(!1),_r=(0,u.useState)(!1),wr=(0,l.Z)(_r,2),Fr=wr[0],Ar=wr[1],Cr=(0,u.useState)(null),Er=(0,l.Z)(Cr,2),Mr=Er[0],zr=Er[1],Pr=(0,u.useRef)(null),Rr=(0,u.useRef)(null);Rr.current||(Rr.current=b().canvas({padding:1.5,tolerance:5}));var Lr="all"===O?1e3:15e3,Dr=(0,w.a)({queryKey:[As,In,""],queryFn:M.N4,refetchInterval:Lr,refetchIntervalInBackground:!1,staleTime:1e3,refetchOnWindowFocus:!1}).data,Zr=(0,u.useMemo)((function(){return(Dr||[]).map((function(e){var s,n=parseFloat(null===e||void 0===e?void 0:e.latitude),r=parseFloat(null===e||void 0===e?void 0:e.longitude);return Number.isFinite(n)&&Number.isFinite(r)?{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:n,lon:r}:null})).filter(Boolean)}),[Dr]),qr=(0,u.useMemo)((function(){return new Set(Zr.filter((function(e){return"active"===e.status})).map((function(e){return String(e.id)})))}),[Zr]),Or=(0,u.useState)((function(){var e=S()();return ue(e.hour()+e.minute()/60,oe)||oe[0].id})),Tr=(0,l.Z)(Or,2),Ir=Tr[0],Hr=Tr[1];(0,u.useEffect)((function(){var e;"all"!==Ir&&(Ys.some((function(e){return e.id===Ir}))||Hr((null===(e=Ys[0])||void 0===e?void 0:e.id)||"all"))}),[Ys,Ir]);var Kr=(0,u.useRef)(null),Br=!s,Yr="undefined"!==typeof window&&localStorage.getItem("userid")||0,Gr=(0,F.N)({queryKey:["dispatchDeliveries",As,Yr,"all",In,In,1e3,"",0,0,0],queryFn:M.p7,getNextPageParam:function(e){var s;return null!==(s=e.nextPage)&&void 0!==s?s:void 0},enabled:Br,refetchInterval:"all"===O&&15e3,refetchIntervalInBackground:!1}),Ur=Gr.data,Vr=Gr.isFetching,Wr=Gr.isError,Jr=Gr.fetchNextPage,Qr=Gr.hasNextPage,$r=Gr.isFetchingNextPage;(0,u.useEffect)((function(){Br&&Qr&&!$r&&Jr()}),[Br,Qr,$r,Jr]);var Xr=(0,u.useMemo)((function(){var e,s=((null===Ur||void 0===Ur?void 0:Ur.pages)||[]).flatMap((function(e){return e.rows||[]})),n=new Set,r=[],t=(0,d.Z)(s);try{for(t.s();!(e=t.n()).done;){var i=e.value,a=null!=i.orderid?String(i.orderid):null;a&&n.has(a)||(a&&n.add(a),r.push(i))}}catch(c){t.e(c)}finally{t.f()}return r}),[Ur]),et=(0,u.useMemo)((function(){var e=new Map;return Xr.forEach((function(s){var n=String(s.userid||s.rider_id||"");n&&"unassigned"!==n&&"0"!==n&&(e.has(n)||e.set(n,{id:n,riderName:s.ridername||s.rider_name||s.username||"Rider ".concat(n)}))})),Array.from(e.values()).sort((function(e,s){return String(e.riderName).localeCompare(String(s.riderName))}))}),[Xr]),st=(0,u.useMemo)((function(){var e={all:Xr.length};return Ys.forEach((function(s){e[s.id]=0})),Xr.forEach((function(s){var n=he(s,Ds,Ys);n&&(e[n]=(e[n]||0)+1)})),e}),[Xr,Ds,Ys]),nt=(0,u.useMemo)((function(){return"all"===Ir?Xr:Xr.filter((function(e){return he(e,Ds,Ys)===Ir}))}),[Xr,Ir,Ds,Ys]),rt=(0,u.useMemo)((function(){if(!Br)return null;if(!nt.length)return{code:200,zone_summary:[],zones:[]};var e=function(e){return String(e||"").trim()},s={};nt.forEach((function(n){var r=e(n.deliverysuburb)||e(n.locationsuburb)||e(n.zone_name)||"Unzoned",t=r.toLowerCase(),i=String(n.userid||n.rider_id||"unassigned"),a=n.ridername||n.rider_name||n.username||("unassigned"===i?"Unassigned":"Rider ".concat(i));s[t]||(s[t]={zone_name:r,riders:{}}),s[t].riders[i]||(s[t].riders[i]={rider_id:i,rider_name:a,orders:[]}),s[t].riders[i].orders.push(n)}));var n=Object.values(s).map((function(e){var s=Object.values(e.riders).map((function(e){var s=(0,t.Z)(e.orders).sort((function(e,s){return S()(e.deliverydate||e.assigntime||0).valueOf()-S()(s.deliverydate||s.assigntime||0).valueOf()}));return(0,o.Z)((0,o.Z)({},e),{},{orders:s.map((function(e,s){return(0,o.Z)((0,o.Z)({},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:n.map((function(e){var s=e.riders.flatMap((function(e){return e.orders})),n=s.filter((function(e){return e.userid||e.rider_id})).length;return{zone_name:e.zone_name,total_orders:s.length,assigned_orders:n,unassigned_orders_count:s.length-n,active_riders_count:e.riders.filter((function(e){return"unassigned"!==e.rider_id})).length,total_delivery_kms:s.reduce((function(e,s){return e+parseFloat(s.actualkms||s.kms||0)}),0),total_profit:s.reduce((function(e,s){return e+parseFloat(s.profit||0)}),0)}})),zones:n}}),[Br,nt]),tt=(0,u.useMemo)((function(){var e=s||rt||{zones:[],zone_summary:[]},n=e.zones||[],r={};(e.zone_summary||[]).forEach((function(e){r[e.zone_name]=e}));var t=function(e,s){var n={};return e.forEach((function(e){var r=s(e);r&&(n[r]=(n[r]||0)+1)})),Object.entries(n).map((function(e){var s=(0,l.Z)(e,2);return{name:s[0],count:s[1]}})).sort((function(e,s){return s.count-e.count}))};return n.map((function(e){var s,n,i,a,c=r[e.zone_name]||{},l=(e.riders||[]).flatMap((function(e){return e.orders||[]})),d=(e.riders||[]).filter((function(e){return e.rider_id&&"unassigned"!==e.rider_id})).length,o=t(l,(function(e){return e.deliverysuburb||e.locationsuburb})),u=t(l,(function(e){return e.pickupcustomer||e.kitchen_key})),m={};return l.forEach((function(e){var s=String(e.orderstatus||"unknown").toLowerCase();m[s]=(m[s]||0)+1})),{id:e.zone_name,name:e.zone_name,riders:e.riders||[],orders:l,totalOrders:null!==(s=c.total_orders)&&void 0!==s?s:l.length,activeRidersCount:null!==(n=c.active_riders_count)&&void 0!==n?n:d,totalKms:null!==(i=c.total_delivery_kms)&&void 0!==i?i:l.reduce((function(e,s){return e+parseFloat(s.actualkms||s.kms||0)}),0),totalProfit:null!==(a=c.total_profit)&&void 0!==a?a:l.reduce((function(e,s){return e+parseFloat(s.profit||0)}),0),suburbs:o,kitchens:u,statusCounts:m}}))}),[s,rt]),it=(0,u.useMemo)((function(){var e=[];((s||rt||{zones:[],zone_summary:[]}).zones||[]).forEach((function(s){(s.riders||[]).forEach((function(n){n.orders.forEach((function(r){e.push((0,o.Z)((0,o.Z)({},r),{},{zone_name:s.zone_name,rider_name:n.rider_name,rider_id:n.rider_id}))}))}))}));var n={};e.forEach((function(e){var s=e.rider_id||e.userid||"unknown";n[s]||(n[s]={id:s,riderName:e.rider_name||e.username||e.rider||s,orders:[],color:ke[Object.keys(n).length%ke.length]}),n[s].orders.push(e)}));var r={};e.forEach((function(e){var s=e.pickupcustomer||e.kitchen_key||"Unknown",n=s.toLowerCase().trim();r[n]?!Number.isFinite(r[n].lat)&&re(e)&&(r[n].lat=$(se(e)),r[n].lon=$(ne(e))):r[n]={id:n,kitchenName:s,lat:$(se(e)),lon:$(ne(e)),orders:[],riders:new Set},r[n].orders.push(e),e.rider_id&&r[n].riders.add(e.rider_id)}));var i=e.reduce((function(e,s){return e+parseFloat(s.actualkms||s.kms||0)}),0),a=e.reduce((function(e,s){return e+parseFloat(s.profit||0)}),0);return{riders:Object.values(n).map((function(e){return(0,o.Z)((0,o.Z)({},e),{},{orders:(0,t.Z)(e.orders).sort((function(e,s){var n=e.trip_number||1,r=s.trip_number||1;return n!==r?n-r:(e.step||0)-(s.step||0)}))})})).sort((function(e,s){return s.orders.length-e.orders.length})),kitchens:Object.values(r).sort((function(e,s){return s.orders.length-e.orders.length})),allOrders:e,stats:{totalOrders:e.length,totalKms:i,totalProfit:a,totalRiders:Object.keys(n).length}}}),[s,rt]),at=it.riders,ct=it.kitchens,lt=it.allOrders,dt=it.stats,ot=gs?N&&at.find((function(e){return e.id===N}))||null:Ke,ut="all"===O,mt=(0,u.useMemo)((function(){return ut?lt.filter((function(e){return qr.has(String(e.rider_id||e.userid||""))})):lt}),[ut,lt,qr]),pt=(0,u.useMemo)((function(){return new Set((ut?mt:[]).filter((function(e){return"active"===String((null===e||void 0===e?void 0:e.orderstatus)||"").toLowerCase()})).map((function(e){return String(e.rider_id||e.userid||"")})))}),[ut,mt]),ht=(0,u.useMemo)((function(){return ut?at.filter((function(e){return pt.has(String(e.id))})):at}),[ut,at,pt]),vt=(0,u.useMemo)((function(){return ut?Zr.filter((function(e){return"active"===e.status&&pt.has(String(e.id))})).map((function(e){return[e.lat,e.lon]})):[]}),[ut,Zr,pt]),ft=(0,u.useCallback)((function(e){y&&y(e?e.id:null),gs||Be(e),ns(null)}),[gs,y]),xt=(0,u.useRef)(null);(0,u.useEffect)((function(){var e=ot?ot.id:null;e!==xt.current&&(ot?V.info("Focused rider changed to: ".concat(ot.riderName," (").concat(ot.orders.length," orders)")):V.info("Focused rider reset to: None"),xt.current=e)}),[ot]),(0,u.useEffect)((function(){ss?V.info("Focused order updated: ID ".concat(ss.orderid)):V.debug("Focused order selection cleared")}),[ss]);var jt=(0,u.useRef)(0);(0,u.useEffect)((function(){lt&&lt.length!==jt.current&&(V.info("Orders database updated: ".concat(lt.length," orders actively tracked")),jt.current=lt.length)}),[lt]);var gt=(0,u.useRef)(0);(0,u.useEffect)((function(){Zr&&Zr.length!==gt.current&&(V.info("Live riders list updated: ".concat(Zr.length," active riders mapped")),gt.current=Zr.length)}),[Zr]);var Nt=(0,u.useMemo)((function(){if(ot)return{orders:ot.orders.length,riders:1,km:ot.orders.reduce((function(e,s){return e+parseFloat(s.actualkms||s.kms||0)}),0),profit:ot.orders.reduce((function(e,s){return e+parseFloat(s.profit||0)}),0),label:"Focused Rider"};if(Ue)return{orders:Ue.orders.length,riders:Ue.riders.size,km:Ue.orders.reduce((function(e,s){return e+parseFloat(s.actualkms||s.kms||0)}),0),profit:Ue.orders.reduce((function(e,s){return e+parseFloat(s.profit||0)}),0),label:"Focused Kitchen"};if(ut){var e=mt.filter((function(e){return"active"===String((null===e||void 0===e?void 0:e.orderstatus)||"").toLowerCase()}));return{orders:e.length,riders:ht.length,km:e.reduce((function(e,s){return e+parseFloat(s.actualkms||s.kms||0)}),0),profit:e.reduce((function(e,s){return e+parseFloat(s.profit||0)}),0),label:"Active Fleet"}}return{orders:dt.totalOrders,riders:dt.totalRiders,km:dt.totalKms,profit:dt.totalProfit,label:"Total Fleet"}}),[ot,Ue,ut,mt,ht,dt]),bt=((0,u.useMemo)((function(){return ut?mt.filter((function(e){return"active"===String((null===e||void 0===e?void 0:e.orderstatus)||"").toLowerCase()})).length:0}),[ut,mt]),(0,u.useMemo)((function(){var e;e=ot?ot.orders:Ue?Ue.orders:Qe?Qe.orders:lt;var s=new Set;return(e||[]).forEach((function(e){null!=e.deliveryid&&""!==e.deliveryid&&0!==e.deliveryid&&s.add(String(e.deliveryid))})),Array.from(s)}),[lt,ot,Ue,Qe])),yt=(0,A.h)({queries:bt.map((function(e){return{queryKey:["deliveryLogs",e],queryFn:function(){var s=(0,a.Z)((0,i.Z)().mark((function s(){var n,t,a,c,l,d,o;return(0,i.Z)().wrap((function(s){for(;;)switch(s.prev=s.next){case 0:return s.next=2,C.Z.get("".concat({NODE_ENV:"production",PUBLIC_URL:"",WDS_SOCKET_HOST:void 0,WDS_SOCKET_PATH:void 0,WDS_SOCKET_PORT:void 0,FAST_REFRESH:!0,REACT_APP_API_URL:"https://mock-data-api-nextjs.vercel.app/",REACT_APP_AUTH0_CLIENT_ID:"",REACT_APP_AUTH0_DOMAIN:"",REACT_APP_AWS_APP_CLIENT_ID:"",REACT_APP_AWS_POOL_ID:"",REACT_APP_FIREBASE_API_KEY:"",REACT_APP_FIREBASE_APP_ID:"",REACT_APP_FIREBASE_AUTH_DOMAIN:"",REACT_APP_FIREBASE_MEASUREMENT_ID:"",REACT_APP_FIREBASE_MESSAGING_SENDER_ID:"",REACT_APP_FIREBASE_PROJECT_ID:"",REACT_APP_FIREBASE_STORAGE_BUCKET:"",REACT_APP_GOOGLE_MAPS_API_KEY:"AIzaSyCF4KatYCI3vqz1_H3kiHeyS3yCMfYToh8",REACT_APP_RIDER_ACCESS_ID:"AAAAILMpCEU:APA91bEavuOllBI6sFgYtxXAgNmAVwNA-MnCMHLGlR4_t7UqpLajAkdn3T0CZr_zaLBknLyim9ytFLMZgbeXmKqTad_PKCbqlYjHpaizVrLXtecxqyEy4UktIacK2UvHVUATHL-7VQQk",REACT_APP_STAFF_TOKEN:"",REACT_APP_URL:"https://jupiter.nearle.app/live/api/v1",REACT_APP_URL2:"https://jupiter.nearle.app/live/api/v2",REACT_APP_VERSION:"v2.1.0"}.REACT_APP_URL3,"/deliveries/getdeliverylogs/?deliveryid=").concat(e));case 2:return a=s.sent,c=[null===a||void 0===a||null===(n=a.data)||void 0===n?void 0:n.details,null===a||void 0===a||null===(t=a.data)||void 0===t?void 0:t.data,null===a||void 0===a?void 0:a.data,a],l=c.find((function(e){return Array.isArray(e)}))||[],d=l.map((function(e){var s,n,r,t=null!==e&&void 0!==e&&e.logdate?S()(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!==(n=null!==(r=null===e||void 0===e?void 0:e.longitude)&&void 0!==r?r:null===e||void 0===e?void 0:e.lng)&&void 0!==n?n:null===e||void 0===e?void 0:e.lon),logdate:null===e||void 0===e?void 0:e.logdate,_ts:t&&t.isValid()?t.valueOf():Number.MAX_SAFE_INTEGER}})).filter((function(e){return Number.isFinite(e.lat)&&Number.isFinite(e.lng)})).sort((function(e,s){return e._ts-s._ts})),o=je(d),s.abrupt("return",o.map((function(e){e._ts;return(0,r.Z)(e,W)})));case 8:case"end":return s.stop()}}),s)})));return function(){return s.apply(this,arguments)}}(),enabled:!0,staleTime:3e5,refetchOnWindowFocus:!1,retry:1}}))}),kt=(0,u.useMemo)((function(){var e=new Map;return bt.forEach((function(s,n){var r=yt[n];e.set(s,{coords:(null===r||void 0===r?void 0:r.data)||[],isLoading:!!(null!==r&&void 0!==r&&r.isLoading||null!==r&&void 0!==r&&r.isFetching),isError:!(null===r||void 0===r||!r.isError)})})),e}),[bt,yt]),St=(0,u.useMemo)((function(){if(!ot)return[];var e=function(e){var s=e.deliverytime||e.expecteddeliverytime;if(!s)return Number.MAX_SAFE_INTEGER;var n=S()(s);return n.isValid()?n.valueOf():Number.MAX_SAFE_INTEGER};return ot.orders.filter((function(e){return null!=e.deliveryid&&""!==e.deliveryid&&0!==e.deliveryid})).sort((function(s,n){var r=e(s)-e(n);return 0!==r?r:(s.step||0)-(n.step||0)})).map((function(e,s){var n=kt.get(String(e.deliveryid));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===n||void 0===n||!n.isLoading),isError:!(null===n||void 0===n||!n.isError),coords:(null===n||void 0===n?void 0:n.coords)||[]}}))}),[ot,kt]),_t=(0,u.useMemo)((function(){return ot?St.map((function(e){var s=ot.orders.find((function(s){return String(s.deliveryid)===String(e.deliveryid)})),n=parseFloat((null===s||void 0===s?void 0:s.kms)||0)||0,r=kn[e.deliveryid],t=0;Array.isArray(r)&&r.length>=2?t=xe(r):null!=(null===s||void 0===s?void 0:s.actualkms)&&""!==s.actualkms?t=parseFloat(s.actualkms)||0:e.coords.length>=2&&(t=xe(e.coords.map((function(e){return[e.lat,e.lng]}))));var i=t-n,a=n>0?i/n*100:null,c=null!==s&&void 0!==s&&s.expecteddeliverytime?S()(s.expecteddeliverytime):null,l=null!==s&&void 0!==s&&s.deliverytime?S()(s.deliverytime):null,d=null!==c&&void 0!==c&&c.isValid()&&null!==l&&void 0!==l&&l.isValid()?l.diff(c,"minute"):null,o=n>0&&t>1.25*n||null!=d&&d>15;return{sequenceStep:e.sequenceStep,deliveryid:e.deliveryid,orderid:e.orderid,order:s,plannedKm:n,actualKm:t,kmDelta:i,kmDeltaPct:a,expectedTs:null!==c&&void 0!==c&&c.isValid()?c:null,actualTs:null!==l&&void 0!==l&&l.isValid()?l: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}})):[]}),[St,ot,kn]),wt=(0,u.useMemo)((function(){if(0===_t.length)return{plannedKm:0,actualKm:0,kmDeltaPct:null,anomalies:0,late:0,onTime:0};var e=_t.filter((function(e){return!e.isLoading&&e.coordsCount>0})),s=e.reduce((function(e,s){return e+s.plannedKm}),0),n=e.reduce((function(e,s){return e+s.actualKm}),0);return{plannedKm:s,actualKm:n,kmDeltaPct:s>0?(n-s)/s*100:null,anomalies:e.filter((function(e){return e.anomaly})).length,late:e.filter((function(e){return null!=e.timeDeltaMin&&e.timeDeltaMin>5})).length,onTime:e.filter((function(e){return null!=e.timeDeltaMin&&e.timeDeltaMin<=5})).length}}),[_t]),Ft=(0,u.useMemo)((function(){return(0,t.Z)(_t).sort((function(e,s){var n,r;return((null===(n=e.order)||void 0===n?void 0:n.step)||e.sequenceStep)-((null===(r=s.order)||void 0===r?void 0:r.step)||s.sequenceStep)}))}),[_t]),At=(0,u.useMemo)((function(){return(0,t.Z)(_t).sort((function(e,s){return e.sequenceStep-s.sequenceStep}))}),[_t]),Ct=(0,u.useMemo)((function(){if(!er||!Mr||!ot)return null;var e=St.find((function(e){return e.sequenceStep===Mr}));if(!e)return null;var s=ot.orders.find((function(s){return String(s.deliveryid)===String(e.deliveryid)}));return s?{orders:[s],id:"cmp-step-".concat(Mr,"-").concat(s.orderid)}:null}),[er,Mr,ot,St]);(0,u.useEffect)((function(){zr(null),xr(new Set),ir("combined")}),[er,null===ot||void 0===ot?void 0:ot.id]),(0,u.useEffect)((function(){!ot&&er&&sr(!1)}),[ot,er]),(0,u.useEffect)((function(){jr.current&&ot&&(jr.current=!1,sr(!0))}),[ot]),(0,u.useEffect)((function(){er&&!Sr.current?(kr.current=br,yr(!0),Ar(!1)):!er&&Sr.current&&yr(kr.current),Sr.current=er}),[er]);var Et=(0,u.useCallback)(function(){var e=(0,a.Z)((0,i.Z)().mark((function e(s,n,r){var t,a,l,d,u,m;return(0,i.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t="".concat(s,"-").concat(n),void 0===Nn.current[t]){e.next=3;break}return e.abrupt("return");case 3:if(!(r.length<2)){e.next=5;break}return e.abrupt("return");case 5:return Nn.current[t]=null,gn((function(e){return(0,o.Z)((0,o.Z)({},e),{},(0,c.Z)({},t,null))})),a=r.map((function(e){return"".concat(e[1],",").concat(e[0])})).join(";"),l="https://router.project-osrm.org/route/v1/driving/".concat(a,"?overview=full&geometries=geojson"),e.prev=9,e.next=12,fetch(l);case 12:return d=e.sent,e.next=15,d.json();case 15:(u=e.sent).routes&&u.routes[0]?(m=u.routes[0].geometry.coordinates.map((function(e){return[e[1],e[0]]})),Nn.current[t]=m,gn((function(e){return(0,o.Z)((0,o.Z)({},e),{},(0,c.Z)({},t,m))}))):(Nn.current[t]=!1,gn((function(e){return(0,o.Z)((0,o.Z)({},e),{},(0,c.Z)({},t,!1))}))),e.next=24;break;case 19:e.prev=19,e.t0=e.catch(9),console.error("OSRM Fetch error:",e.t0),Nn.current[t]=!1,gn((function(e){return(0,o.Z)((0,o.Z)({},e),{},(0,c.Z)({},t,!1))}));case 24:case"end":return e.stop()}}),e,null,[[9,19]])})));return function(s,n,r){return e.apply(this,arguments)}}(),[]);(0,u.useEffect)((function(){Nn.current={},gn({}),_n.current={},Sn({})}),[In,Ir]);var Mt=(0,u.useCallback)(function(){var e=(0,a.Z)((0,i.Z)().mark((function e(s,n){var r,t,a,l,d,u,m,p,h,v,f,x,j,g,N;return(0,i.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===_n.current[s]){e.next=2;break}return e.abrupt("return");case 2:if(Array.isArray(n)&&!(n.length<2)){e.next=4;break}return e.abrupt("return");case 4:return _n.current[s]=null,Sn((function(e){return(0,o.Z)((0,o.Z)({},e),{},(0,c.Z)({},s,null))})),r=function(e){_n.current[s]=e,Sn((function(n){return(0,o.Z)((0,o.Z)({},n),{},(0,c.Z)({},s,e))}))},t=function(){_n.current[s]=!1,Sn((function(e){return(0,o.Z)((0,o.Z)({},e),{},(0,c.Z)({},s,!1))}))},a=function(e,s){if(e.length<=s)return e;var n=Math.ceil(e.length/s),r=e.filter((function(e,s){return s%n===0})),t=e[e.length-1];return r[r.length-1]!==t&&r.push(t),r},e.prev=9,l=a(n,90),d=l.map((function(e){return"".concat(e[1],",").concat(e[0])})).join(";"),u="https://router.project-osrm.org/match/v1/driving/".concat(d,"?overview=full&geometries=geojson&gaps=ignore&tidy=true"),e.next=15,fetch(u);case 15:return m=e.sent,e.next=18,m.json();case 18:if(!((p=e.sent).matchings&&p.matchings.length>0)){e.next=24;break}if(!((h=p.matchings.flatMap((function(e){var s;return((null===(s=e.geometry)||void 0===s?void 0:s.coordinates)||[]).map((function(e){return[e[1],e[0]]}))}))).length>=2)){e.next=24;break}return r(h),e.abrupt("return");case 24:e.next=29;break;case 26:e.prev=26,e.t0=e.catch(9),console.warn("OSRM Match error, trying route fallback:",e.t0);case 29:return e.prev=29,v=a(n,25),f=v.map((function(e){return"".concat(e[1],",").concat(e[0])})).join(";"),x="https://router.project-osrm.org/route/v1/driving/".concat(f,"?overview=full&geometries=geojson"),e.next=35,fetch(x);case 35:return j=e.sent,e.next=38,j.json();case 38:if(!(g=e.sent).routes||!g.routes[0]){e.next=44;break}if(!((N=g.routes[0].geometry.coordinates.map((function(e){return[e[1],e[0]]}))).length>=2)){e.next=44;break}return r(N),e.abrupt("return");case 44:t(),e.next=51;break;case 47:e.prev=47,e.t1=e.catch(29),console.error("OSRM Route fallback error:",e.t1),t();case 51:case"end":return e.stop()}}),e,null,[[9,26],[29,47]])})));return function(s,n){return e.apply(this,arguments)}}(),[]);(0,u.useEffect)((function(){kt.forEach((function(e,s){if(s&&e&&!(e.coords.length<2)){var n=e.coords.map((function(e){return[e.lat,e.lng]}));Mt(s,n)}}))}),[kt,Mt]),(0,u.useEffect)((function(){qn.current=An}),[An]),(0,u.useEffect)((function(){if(!m){var e=function(){var e=new Date;ks([e.getHours(),e.getMinutes(),e.getSeconds()].map((function(e){return String(e).padStart(2,"0")})).join(":"))},s=setInterval(e,1e3);return e(),function(){return clearInterval(s)}}}),[m]),(0,u.useEffect)((function(){Te(new Set(at.map((function(e){return e.id}))))}),[at]),(0,u.useEffect)((function(){at.forEach((function(e){if(Oe.has(e.id)&&(!ot||ot.id===e.id)){var s={};if(e.orders.forEach((function(e){var n=e.trip_number||1;s[n]||(s[n]=[]),s[n].push(e)})),Object.entries(s).forEach((function(s){var n=(0,l.Z)(s,2),r=n[0],i=n[1],a=(0,t.Z)(i).sort((function(e,s){return(e.step||0)-(s.step||0)})),c=ye(a);c.length>=2&&Et(e.id,r,c)})),ut){var n=(0,z.P0)(e.orders);if(n){var r=Zr.find((function(s){return String(s.id)===String(e.id)})),i=r&&Number.isFinite(r.lat)&&Number.isFinite(r.lon)?[r.lat,r.lon]:re(n)?[$(se(n)),$(ne(n))]:null,a=$(n.droplat||n.deliverylat),c=$(n.droplon||n.deliverylong);i&&Number.isFinite(a)&&Number.isFinite(c)&&Et(e.id,"active-".concat(n.orderid),[i,[a,c]])}}}}))}),[at,Oe,ot,ut,Zr,Et]);var zt=(0,u.useRef)(null);(0,u.useEffect)((function(){if(Br){var e=function(){var e=S()();return e.hour()+e.minute()/60};null===zt.current&&(zt.current=e());var s=setInterval((function(){var s=e(),n=ue(zt.current,Ys),r=ue(s,Ys);zt.current=s,r&&r!==n&&Hr((function(e){return e===n?r:e}))}),3e4);return function(){return clearInterval(s)}}}),[Br,Ys]),(0,u.useEffect)((function(){ns(null)}),[null===Ue||void 0===Ue?void 0:Ue.id]),(0,u.useEffect)((function(){var e=Kr.current;e&&"function"===typeof e.scrollIntoView&&e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"center"})}),[Ir]);var Pt=function(e){var s=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return b().divIcon({className:"",iconSize:s?[56,56]:[46,46],iconAnchor:s?[28,28]:[23,23],popupAnchor:[0,s?-30:-24],html:'<div class="kitchen-mark'.concat(s?" is-focused":"",'">').concat((e||"K").charAt(0).toUpperCase(),"</div>")})},Rt=function(e){var s;return(null===(s=at.find((function(s){return String(s.id)===String(e)})))||void 0===s?void 0:s.color)||"#475569"},Lt=function(e,s){if(!e||!s||!ee(s))return null;var n=Zr.find((function(s){return String(s.id)===String(e)}));if(!n)return null;var r=$(s.droplat||s.deliverylat),t=$(s.droplon||s.deliverylong);if(!Number.isFinite(r)||!Number.isFinite(t))return null;var i=fe([n.lat,n.lon],[r,t]);return Math.round(1e3*i)},Dt=function(e){return null===e||void 0===e?"":e>=1e3?"".concat((e/1e3).toFixed(1)," km"):"".concat(e," m")};return(0,P.jsxs)("div",{className:"dispatch-container".concat(m?" embedded":"").concat(er?" compare-open":""),children:[!m&&(0,P.jsxs)("div",{id:"hdr",children:[(0,P.jsxs)("div",{className:"logo",children:[(0,P.jsx)("div",{className:"logo-badge",children:"D"}),(0,P.jsx)("div",{className:"logo-name",children:"Dispatch"})]}),(0,P.jsx)("div",{className:"hdr-stats",children:Br&&(0,P.jsxs)(P.Fragment,{children:[Vr&&(0,P.jsxs)("span",{className:"live-status",children:[(0,P.jsx)("span",{className:"live-dot"})," Loading ",Xr.length?"\xb7 ".concat(Xr.length," loaded"):""]}),!Vr&&!Wr&&(0,P.jsxs)("span",{className:"live-status live-status-ready",children:[(0,P.jsx)("span",{className:"live-dot ready"})," ",nt.length," orders",(0,P.jsxs)("span",{className:"live-status-sub",children:[" / ",Xr.length," total"]})]}),Wr&&(0,P.jsxs)("span",{className:"live-status live-status-error",children:[(0,P.jsx)("span",{className:"live-dot error"})," Failed to load"]}),function(){var e=S()().startOf("day"),s=e.format("YYYY-MM-DD"),n=S()(In),r=In===s,t=n.isAfter(e,"day"),i=function(s){if(s){var n=s.format("YYYY-MM-DD");n!==In?s.isAfter(e,"day")||(Hn(n),ft(null),Ve(null),$e(null),Gn(!1)):Gn(!1)}},a=Wn.startOf("month"),c=a.subtract(a.day(),"day"),l=Array.from({length:42},(function(e,s){return c.add(s,"day")})),d=!Wn.add(1,"month").startOf("month").isAfter(e,"month");return(0,P.jsxs)("div",{className:"date-chip".concat(r?" is-today":"").concat(Yn?" is-open":""),ref:Qn,children:[(0,P.jsx)("button",{type:"button",className:"date-chip-nav",onClick:function(){return i(n.subtract(1,"day"))},"aria-label":"Previous day",title:"Previous day",children:(0,P.jsx)(E.G1X,{})}),(0,P.jsxs)("button",{type:"button",className:"date-chip-main",onClick:function(){return Gn((function(e){return!e}))},"aria-haspopup":"dialog","aria-expanded":Yn,children:[(0,P.jsx)("span",{className:"date-chip-icon","aria-hidden":"true",children:(0,P.jsx)(E.kVv,{})}),(0,P.jsxs)("span",{className:"date-chip-text",children:[(0,P.jsxs)("span",{className:"date-chip-label",children:["Date",r&&(0,P.jsx)("span",{className:"date-chip-today-pill",children:"Today"})]}),(0,P.jsx)("span",{className:"date-chip-value",children:n.isValid()?n.format("ddd, MMM D, YYYY"):"\u2014"})]}),(0,P.jsx)("span",{className:"date-chip-chevron".concat(Yn?" is-open":""),"aria-hidden":"true",children:(0,P.jsx)(E.Yc6,{})})]}),(0,P.jsx)("button",{type:"button",className:"date-chip-nav",onClick:function(){r||t||i(n.add(1,"day"))},disabled:r||t,"aria-label":"Next day",title:r?"You're viewing today":"Next day",children:(0,P.jsx)(E.FNi,{})}),Yn&&(0,P.jsxs)("div",{className:"date-cal-popover",role:"dialog","aria-label":"Pick a date",children:[(0,P.jsxs)("div",{className:"date-cal-header",children:[(0,P.jsx)("button",{type:"button",className:"date-cal-nav",onClick:function(){return Jn((function(e){return e.subtract(1,"month")}))},"aria-label":"Previous month",children:(0,P.jsx)(E.G1X,{})}),(0,P.jsx)("div",{className:"date-cal-title",children:Wn.format("MMMM YYYY")}),(0,P.jsx)("button",{type:"button",className:"date-cal-nav",onClick:function(){var s=Wn.add(1,"month");s.startOf("month").isAfter(e,"month")||Jn(s)},disabled:!d,"aria-label":"Next month",children:(0,P.jsx)(E.FNi,{})})]}),(0,P.jsx)("div",{className:"date-cal-weekdays",children:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map((function(e){return(0,P.jsx)("div",{className:"date-cal-weekday",children:e},e)}))}),(0,P.jsx)("div",{className:"date-cal-grid",children:l.map((function(n){var r=n.month()===Wn.month(),t=n.format("YYYY-MM-DD")===In,a=n.format("YYYY-MM-DD")===s,c=n.isAfter(e,"day"),l=["date-cal-day",!r&&"is-other-month",t&&"is-selected",a&&"is-today",c&&"is-disabled"].filter(Boolean).join(" ");return(0,P.jsx)("button",{type:"button",className:l,disabled:c,onClick:function(){return i(n)},"aria-current":a?"date":void 0,"aria-pressed":t,children:n.date()},n.format("YYYY-MM-DD"))}))}),(0,P.jsxs)("div",{className:"date-cal-presets",children:[(0,P.jsx)("button",{type:"button",className:"date-cal-preset",onClick:function(){return i(e)},children:"Today"}),(0,P.jsx)("button",{type:"button",className:"date-cal-preset",onClick:function(){return i(e.subtract(1,"day"))},children:"Yesterday"}),(0,P.jsx)("button",{type:"button",className:"date-cal-preset",onClick:function(){return i(e.subtract(7,"day"))},children:"\u22127 days"})]})]})]})}()]})}),(0,P.jsx)("div",{id:"clock",children:ys})]}),(m||"live"===K)&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)("div",{id:"strat-row",children:[(0,P.jsxs)("button",{className:"sbt ".concat("kitchens"===O?"active":""),onClick:function(){V.info("View mode changed: By Location"),T("kitchens"),ft(null),Ve(null),$e(null)},children:[(0,P.jsx)("span",{className:"sbt-icon",children:(0,P.jsx)(E.c7Z,{})})," By Location"]}),(0,P.jsxs)("button",{className:"sbt ".concat("zones"===O?"active":""),onClick:function(){V.info("View mode changed: By Zone"),T("zones"),ft(null),Ve(null),$e(null)},children:[(0,P.jsx)("span",{className:"sbt-icon",children:(0,P.jsx)(E.PKO,{})})," By Zone"]}),(0,P.jsxs)("button",{className:"sbt ".concat("riders"===O?"active":""),onClick:function(){V.info("View mode changed: By Rider"),T("riders"),ft(null),Ve(null),$e(null)},children:[(0,P.jsx)("span",{className:"sbt-icon",children:(0,P.jsx)(E.MCF,{})})," By Rider"]}),!m&&(0,P.jsxs)("button",{className:"sbt ".concat("all"===O?"active":""),onClick:function(){V.info("View mode changed: All Active Routes"),T("all"),ft(null),Ve(null),$e(null)},children:[(0,P.jsx)("span",{className:"sbt-icon",children:(0,P.jsx)(E.zNX,{})}),"Active"]}),!m&&(0,P.jsxs)("button",{type:"button",className:"sbt sbt-rider-info ".concat("rider-info"===O?"active":""),onClick:function(){T("rider-info"),ft(null),Ve(null),$e(null)},title:"Live GPS / battery / status snapshot for a rider",children:[(0,P.jsx)("span",{className:"sbt-icon",children:(0,P.jsx)(E.eJU,{})})," Rider Info"]})]}),Br&&"rider-info"!==O&&(0,P.jsxs)("div",{id:"batch-row",children:[(0,P.jsx)("span",{className:"batch-label",children:"Batch"}),(0,P.jsx)("div",{className:"batch-scroll",children:Ys.map((function(e){var s,n=Ir===e.id;return(0,P.jsxs)("button",{ref:n?Kr:null,className:"batch-btn batch-slot ".concat(n?"active":""),onClick:function(){Hr(e.id),ft(null),Ve(null),$e(null)},title:"".concat(e.label," (").concat(e.range,")"),children:[(0,P.jsx)("span",{className:"batch-btn-label",children:e.label}),(0,P.jsx)("span",{className:"batch-btn-count",children:null!==(s=st[e.id])&&void 0!==s?s:0})]},e.id)}))})]}),"rider-info"===O?(0,P.jsxs)("div",{className:"rider-info-mode",children:[(0,P.jsxs)("div",{className:"ri-sidebar",children:[(0,P.jsxs)("div",{className:"ri-sb-head",children:[(0,P.jsx)("div",{className:"ri-sb-title",children:"Riders"}),(0,P.jsxs)("div",{className:"ri-sb-sub",children:[et.length," ",1===et.length?"rider":"riders"," today"]})]}),(0,P.jsxs)("div",{className:"ri-search",children:[(0,P.jsx)(E.vU7,{className:"ri-search-icon"}),(0,P.jsx)("input",{type:"text",className:"ri-search-input",placeholder:"Search by name or ID",value:tn,onChange:function(e){return an(e.target.value)}})]}),function(){var e=tn.trim().toLowerCase(),s=et.filter((function(s){return!e||(String(s.riderName||"").toLowerCase().includes(e)||String(s.id).includes(e))}));return 0===s.length?(0,P.jsx)("div",{className:"ri-empty",children:tn?'No riders match "'.concat(tn,'"'):"No riders have orders today"}):(0,P.jsx)("div",{className:"ri-rider-list",children:s.map((function(e){var s=String(en)===String(e.id);return(0,P.jsxs)("button",{type:"button",className:"ri-rider-item ".concat(s?"active":""),onClick:function(){return sn(e.id)},children:[(0,P.jsx)("span",{className:"ri-rider-dot",style:{background:Se(e.id)}}),(0,P.jsxs)("span",{className:"ri-rider-info-block",children:[(0,P.jsx)("span",{className:"ri-rider-name",children:e.riderName}),(0,P.jsxs)("span",{className:"ri-rider-meta",children:["#",e.id]})]}),(0,P.jsx)("span",{className:"ri-rider-arrow",children:"\u2192"})]},e.id)}))})}()]}),(0,P.jsx)("div",{className:"ri-main",children:null==en?(0,P.jsxs)("div",{className:"ri-placeholder",children:[(0,P.jsx)("div",{className:"ri-placeholder-icon",children:(0,P.jsx)(E.eJU,{})}),(0,P.jsx)("div",{className:"ri-placeholder-title",children:"Pick a rider"}),(0,P.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,P.jsxs)(P.Fragment,{children:[dn&&!ln&&(0,P.jsx)("div",{className:"ri-loading",children:"Loading rider snapshot\u2026"}),on&&(0,P.jsxs)("div",{className:"ri-error",children:["Couldn't load this rider's log. ",(null===un||void 0===un?void 0:un.message)||""]}),ln&&function(){var e=ln,s=parseFloat(e.latitude),n=parseFloat(e.longitude),r=Number.isFinite(s)&&Number.isFinite(n),t=parseInt(String(e.battery||"").replace("%",""),10),i=Number.isFinite(t)&&t<=20,a=parseFloat(e.speed),c=String(e.status||"").toLowerCase();return(0,P.jsxs)("div",{className:"ri-snapshot",children:[(0,P.jsxs)("div",{className:"ri-snap-head",children:[(0,P.jsx)("div",{className:"ri-snap-name",children:e.username||"Rider #".concat(e.userid)}),(0,P.jsxs)("div",{className:"ri-snap-meta",children:[(0,P.jsxs)("span",{children:["#",e.userid]}),e.status&&(0,P.jsx)("span",{className:"ri-status ri-status-".concat(c),children:e.status}),(0,P.jsxs)("span",{className:"ri-live ".concat(dn?"is-refetching":""),children:[(0,P.jsx)("span",{className:"ri-live-dot"}),dn?"Updating\u2026":"Live"]})]}),e.logdate&&(0,P.jsxs)("div",{className:"ri-snap-time",children:[(0,P.jsx)(E.dKE,{})," Last seen ",e.logdate]})]}),(0,P.jsxs)("div",{className:"ri-snap-grid",children:[(0,P.jsxs)("div",{className:"ri-stat ".concat(i?"ri-stat-warn":""),children:[(0,P.jsx)("div",{className:"ri-stat-icon",children:(0,P.jsx)(E.f9F,{})}),(0,P.jsxs)("div",{className:"ri-stat-body",children:[(0,P.jsx)("div",{className:"ri-stat-label",children:"Battery"}),(0,P.jsxs)("div",{className:"ri-stat-value",children:[e.battery||"\u2014",e.is_charging&&(0,P.jsx)("span",{className:"ri-stat-tag",children:"Charging"})]})]})]}),(0,P.jsxs)("div",{className:"ri-stat",children:[(0,P.jsx)("div",{className:"ri-stat-icon",children:(0,P.jsx)(E.YPA,{})}),(0,P.jsxs)("div",{className:"ri-stat-body",children:[(0,P.jsx)("div",{className:"ri-stat-label",children:"Connection"}),(0,P.jsx)("div",{className:"ri-stat-value",children:e.connection||"\u2014"})]})]}),(0,P.jsxs)("div",{className:"ri-stat",children:[(0,P.jsx)("div",{className:"ri-stat-icon",children:(0,P.jsx)(E.x$F,{})}),(0,P.jsxs)("div",{className:"ri-stat-body",children:[(0,P.jsx)("div",{className:"ri-stat-label",children:"GPS Accuracy"}),(0,P.jsx)("div",{className:"ri-stat-value",children:e.accuracy?"".concat(e.accuracy," m"):"\u2014"})]})]}),(0,P.jsxs)("div",{className:"ri-stat",children:[(0,P.jsx)("div",{className:"ri-stat-icon",children:(0,P.jsx)(E.A_X,{})}),(0,P.jsxs)("div",{className:"ri-stat-body",children:[(0,P.jsx)("div",{className:"ri-stat-label",children:"Location Service"}),(0,P.jsx)("div",{className:"ri-stat-value",children:e.location_service||"\u2014"})]})]}),(0,P.jsxs)("div",{className:"ri-stat",children:[(0,P.jsx)("div",{className:"ri-stat-icon",children:(0,P.jsx)(E.JKp,{})}),(0,P.jsxs)("div",{className:"ri-stat-body",children:[(0,P.jsx)("div",{className:"ri-stat-label",children:"Speed"}),(0,P.jsx)("div",{className:"ri-stat-value",children:Number.isFinite(a)?"".concat(a.toFixed(2)," km/h"):"\u2014"})]})]}),(0,P.jsxs)("div",{className:"ri-stat",children:[(0,P.jsx)("div",{className:"ri-stat-icon",children:(0,P.jsx)(E.DTb,{})}),(0,P.jsxs)("div",{className:"ri-stat-body",children:[(0,P.jsx)("div",{className:"ri-stat-label",children:"Heading"}),(0,P.jsx)("div",{className:"ri-stat-value",children:null!=e.heading?"".concat(e.heading,"\xb0"):"\u2014"})]})]}),(0,P.jsxs)("div",{className:"ri-stat",children:[(0,P.jsx)("div",{className:"ri-stat-icon",children:(0,P.jsx)(E.NUu,{})}),(0,P.jsxs)("div",{className:"ri-stat-body",children:[(0,P.jsx)("div",{className:"ri-stat-label",children:"App State"}),(0,P.jsx)("div",{className:"ri-stat-value",children:e.is_background?"Background":"Foreground"})]})]}),(0,P.jsxs)("div",{className:"ri-stat",children:[(0,P.jsx)("div",{className:"ri-stat-icon",children:(0,P.jsx)(E.ByW,{})}),(0,P.jsxs)("div",{className:"ri-stat-body",children:[(0,P.jsx)("div",{className:"ri-stat-label",children:"Current Order"}),(0,P.jsx)("div",{className:"ri-stat-value",children:e.orderid||"\u2014"})]})]})]}),r&&(0,P.jsxs)("div",{className:"ri-map-section",children:[(0,P.jsxs)("div",{className:"ri-coords-label",children:[(0,P.jsx)(E.$0r,{})," ",s.toFixed(6),", ",n.toFixed(6)]}),(0,P.jsx)("div",{className:"ri-map",children:(0,P.jsxs)(v.h,{center:[s,n],zoom:13,scrollWheelZoom:!1,style:{height:"100%",width:"100%"},children:[(0,P.jsx)(f.I,{url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",attribution:"\xa9 OpenStreetMap contributors"}),(0,P.jsxs)(p.J,{position:[s,n],children:[(0,P.jsx)(x.u,{direction:"top",offset:[0,-10],permanent:!0,className:"ri-area-banner",children:(null===hn||void 0===hn?void 0:hn.area)||"Locating area\u2026"}),(0,P.jsxs)(j.G,{children:[(0,P.jsx)("div",{style:{fontWeight:700,marginBottom:2},children:e.username||"Rider #".concat(e.userid)}),(null===hn||void 0===hn?void 0:hn.area)&&(0,P.jsx)("div",{style:{fontSize:12,color:"#0f172a",marginBottom:4},children:hn.area}),(0,P.jsx)("div",{style:{fontSize:11,color:"#64748b"},children:e.logdate?"Last seen ".concat(e.logdate):"".concat(s.toFixed(6),", ").concat(n.toFixed(6))})]})]})]},"".concat(e.userid,"-").concat(s,"-").concat(n))})]})]})}()]})})]}):(0,P.jsxs)("div",{id:"body",className:"".concat(br?"sidebar-collapsed":""," ").concat(er?"compare-mode":""," ").concat(er&&Fr?"compare-data-collapsed":"").trim(),children:[(0,P.jsx)("button",{type:"button",className:"sidebar-toggle-tab".concat(br?" is-collapsed":""),onClick:function(){return yr((function(e){return!e}))},title:br?"Show sidebar":"Hide sidebar","aria-label":br?"Show sidebar":"Hide sidebar",children:br?(0,P.jsx)(E.FNi,{}):(0,P.jsx)(E.G1X,{})}),er&&ot&&(0,P.jsx)("button",{type:"button",className:"compare-data-toggle-tab".concat(Fr?" is-collapsed":""),onClick:function(){return Ar((function(e){return!e}))},title:Fr?"Show details panel":"Hide details panel","aria-label":Fr?"Show details panel":"Hide details panel",children:Fr?(0,P.jsx)(E.G1X,{}):(0,P.jsx)(E.FNi,{})}),(0,P.jsxs)("div",{id:"sidebar",children:[!ot&&(0,P.jsxs)("div",{className:"sb-header",children:[(0,P.jsxs)("div",{className:"sb-header-top",children:[(0,P.jsxs)("div",{className:"sb-header-title",children:[(0,P.jsx)("span",{className:"sb-title-bar","aria-hidden":"true"}),(0,P.jsx)("span",{className:"sb-title-text",children:"RIDER DISPATCH"})]}),(0,P.jsxs)("span",{className:"sb-header-scope",title:Nt.label,children:[(0,P.jsx)("span",{className:"sb-scope-dot"}),Nt.label]})]}),(0,P.jsxs)("div",{className:"sb-header-tiles",children:[(0,P.jsxs)("div",{className:"sb-tile sb-tile-orders",children:[(0,P.jsx)("span",{className:"sb-tile-icon",children:(0,P.jsx)(E.ByW,{})}),(0,P.jsxs)("div",{className:"sb-tile-body",children:[(0,P.jsx)("div",{className:"sb-tile-value",children:Nt.orders}),(0,P.jsx)("div",{className:"sb-tile-label",children:1===Nt.orders?"Order":"Orders"})]})]}),(0,P.jsxs)("div",{className:"sb-tile sb-tile-riders",children:[(0,P.jsx)("span",{className:"sb-tile-icon",children:(0,P.jsx)(E.pbk,{})}),(0,P.jsxs)("div",{className:"sb-tile-body",children:[(0,P.jsx)("div",{className:"sb-tile-value",children:Nt.riders}),(0,P.jsx)("div",{className:"sb-tile-label",children:1===Nt.riders?"Rider":"Riders"})]})]})]})]}),ot&&!ut||Ue?(0,P.jsxs)("div",{id:"route-detail",children:[(0,P.jsxs)("button",{className:"rd-back",onClick:function(){ft(null),Ve(null)},children:["\u2190 Back to ",Qe?Qe.name:"list"]}),ot?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)("div",{className:"rd-rider-name",style:{color:ot.color},children:ot.riderName}),function(){var e=ut?(0,z.P0)(ot.orders):null,s=ut?e?[e]:[]:ot.orders,n=s.reduce((function(e,s){return e+parseFloat(s.kms||0)}),0),r=s.reduce((function(e,s){return e+parseFloat(s.actualkms||0)}),0);return(0,P.jsxs)("div",{className:"rd-stats-grid",children:[(0,P.jsxs)("div",{className:"rd-stat rd-stat-orders",children:[(0,P.jsx)("div",{className:"rd-stat-icon",children:(0,P.jsx)(E.ByW,{})}),(0,P.jsx)("div",{className:"rd-stat-value",children:s.length}),(0,P.jsx)("div",{className:"rd-stat-label",children:"Orders"})]}),(0,P.jsxs)("div",{className:"rd-stat rd-stat-distance",children:[(0,P.jsx)("div",{className:"rd-stat-icon",children:(0,P.jsx)(E.v93,{})}),(0,P.jsxs)("div",{className:"rd-stat-value",children:[n.toFixed(1),(0,P.jsx)("span",{className:"rd-stat-unit",children:"km"})]}),(0,P.jsx)("div",{className:"rd-stat-label",children:"Planned KMs"})]}),(0,P.jsxs)("div",{className:"rd-stat rd-stat-riderkms",children:[(0,P.jsx)("div",{className:"rd-stat-icon",children:(0,P.jsx)(E.JKp,{})}),(0,P.jsxs)("div",{className:"rd-stat-value",children:[r.toFixed(1),(0,P.jsx)("span",{className:"rd-stat-unit",children:"km"})]}),(0,P.jsx)("div",{className:"rd-stat-label",children:"Actual KMs"})]})]})}(),function(){var e=ut?(0,z.P0)(ot.orders):null,s=ut?e?[e]:[]:ot.orders;if(ut&&0===s.length)return(0,P.jsx)("div",{className:"trip-empty-note",style:{padding:"14px 4px",color:"#94a3b8",fontSize:13},children:"No active delivery right now."});var n={};s.forEach((function(e){var s=e.trip_number||1;n[s]||(n[s]=[]),n[s].push(e)}));var r=(0,t.Z)(ot.orders).sort((function(e,s){var n=e.trip_number||1,r=s.trip_number||1;return n!==r?n-r:(e.step||0)-(s.step||0)})).find((function(e){var s=String(e.orderstatus||"").toLowerCase();return!z.Q6.has(s)&&!z.us.has(s)})),i=r?r.orderid:null,a=function(e){var s=e.deliverytime||e.expecteddeliverytime;if(!s)return Number.MAX_SAFE_INTEGER;var n=S()(s);return n.isValid()?n.valueOf():Number.MAX_SAFE_INTEGER},c="time"===ls,d=null;return Object.entries(n).sort((function(e,s){var n=(0,l.Z)(e,1)[0],r=(0,l.Z)(s,1)[0];return Number(n)-Number(r)})).map((function(e){var s=(0,l.Z)(e,2),n=s[0],r=s[1],o=c?(0,t.Z)(r).sort((function(e,s){var n=a(e)-a(s);return 0!==n?n:(e.step||0)-(s.step||0)})):r;return(0,P.jsxs)("div",{className:"trip-block",children:[(0,P.jsxs)("div",{className:"trip-header",style:{background:"".concat(ot.color,"12"),borderColor:"".concat(ot.color,"30")},children:[(0,P.jsxs)("span",{className:"th-badge",style:{background:ot.color},children:["Trip ",n]}),(0,P.jsxs)("span",{className:"trip-stats",children:[(0,P.jsxs)("span",{children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.$0r,{})}),r.length," stops"]}),(0,P.jsxs)("span",{children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.v93,{})}),r.reduce((function(e,s){return e+parseFloat(s.actualkms||s.kms||0)}),0).toFixed(1)," km"]})]}),(0,P.jsxs)("div",{className:"trip-sort-toggle",role:"group","aria-label":"Sort stops by","data-mode":c?"time":"planned",children:[(0,P.jsxs)("button",{type:"button",className:"trip-sort-pill ".concat(c?"":"is-active"),"aria-pressed":!c,onClick:function(){return ds("planned")},title:"Sort stops by planned step (dispatched order)",children:[(0,P.jsx)(E.f_H,{"aria-hidden":"true"}),(0,P.jsx)("span",{children:"Planned"})]}),(0,P.jsxs)("button",{type:"button",className:"trip-sort-pill ".concat(c?"is-active":""),"aria-pressed":c,onClick:function(){return ds("time")},title:"Sort stops by completion time (which delivery was done first)",children:[(0,P.jsx)(E.dKE,{"aria-hidden":"true"}),(0,P.jsx)("span",{children:"By time"})]})]})]}),(0,P.jsx)("div",{className:"zone-order-grid",children:o.map((function(e,s){var r=(e.kitchen_key||e.pickupcustomer||"Unknown").toLowerCase().trim(),t=null!==d&&r!==d;d=r;var a=ss&&ss.orderid===e.orderid,l=i&&e.orderid===i,o=parseFloat(e.droplat||e.deliverylat),m=parseFloat(e.droplon||e.deliverylong),p=Number.isFinite(o)&&Number.isFinite(m),h=(0,z.Cl)(e.orderstatus),v=Lt(ot.id,e),f=c&&!e.deliverytime;return(0,P.jsxs)(u.Fragment,{children:[t&&(0,P.jsxs)("div",{className:"kitchen-transition",children:[(0,P.jsx)("span",{className:"kt-ico",children:(0,P.jsx)(E.x82,{})})," Switch to ",(0,P.jsx)("strong",{children:e.pickupcustomer})]}),(0,P.jsxs)("div",{className:"zone-order-card ".concat(p?"clickable":""," ").concat(a?"active":""," ").concat(l?"going-on":""," ").concat(f?"is-pending-time":""),role:p?"button":void 0,tabIndex:p?0:void 0,onClick:p?function(){return ns(a?null:{orderid:e.orderid,lat:o,lon:m})}:void 0,onKeyDown:p?function(s){"Enter"!==s.key&&" "!==s.key||(s.preventDefault(),ns(a?null:{orderid:e.orderid,lat:o,lon:m}))}:void 0,title:p?a?"Click to show full trip":"Show ".concat(e.deliverycustomer||"order #".concat(e.orderid)," on map"):void 0,children:[(0,P.jsxs)("div",{className:"zone-order-card-head",children:[(0,P.jsx)("div",{className:"zone-order-num",children:e.step||s+1}),(0,P.jsx)("div",{className:"zone-order-id-block",children:(0,P.jsxs)("div",{className:"zone-order-id",children:["Order #",e.orderid]})}),function(){var s=Ne(e.deliverytime),n=Ne(e.expecteddeliverytime),r=!z.Q6.has(String(e.orderstatus||"").toLowerCase())&&null!==v;return e.orderstatus||s||n||r?(0,P.jsxs)("div",{className:"zone-order-status-stack",children:[e.orderstatus&&(0,P.jsx)("span",{className:"zone-order-status",style:{background:h.bg,color:h.fg},children:h.label}),(s||n)&&(0,P.jsxs)("span",{className:"zone-order-time ".concat(s?"":"is-expected"),title:s?"Delivered at ".concat(s):"Expected at ".concat(n),children:[(0,P.jsx)(E.dKE,{}),s||n]}),r&&(0,P.jsxs)("span",{className:"zone-order-est-drop",title:"Estimated distance to drop location",children:[(0,P.jsx)(E.x$F,{}),Dt(v)]})]}):null}()]}),(0,P.jsxs)("div",{className:"zone-order-customer",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.gNp,{})}),e.deliverycustomer||"\u2014"]}),e.pickupcustomer&&(0,P.jsxs)("div",{className:"zone-order-line",title:"Kitchen: ".concat(e.pickupcustomer),children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.TkG,{})}),e.pickupcustomer]}),(e.deliverysuburb||e.deliveryaddress)&&(0,P.jsxs)("div",{className:"zone-order-line",title:e.deliveryaddress||e.deliverysuburb,children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.$0r,{})}),e.deliverysuburb||X(e.deliveryaddress)]}),e.ordernotes&&(0,P.jsxs)("div",{className:"zone-order-line zone-order-notes",title:e.ordernotes,children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.hKf,{})}),e.ordernotes]}),(0,P.jsxs)("div",{className:"zone-order-stats",children:[(0,P.jsxs)("span",{className:"zone-order-chip",title:"Distance",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.v93,{})}),e.actualkms||e.kms||0," km"]}),e.ordertype&&(0,P.jsx)("span",{className:"zone-order-chip zone-order-type type-".concat(String(e.ordertype).toLowerCase()),children:e.ordertype}),(0,P.jsxs)("span",{className:"zone-order-chip zone-order-trip",children:["T",e.trip_number||n," \xb7 S",e.step||s+1]})]})]})]},e.orderid)}))})]},n)}))}()]}):(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)("div",{className:"rd-rider-name",style:{color:"#f59e0b"},children:Ue.kitchenName}),(0,P.jsxs)("div",{className:"rd-rider-sub",children:[(0,P.jsxs)("span",{children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.ByW,{})}),Ue.orders.length," orders"]}),(0,P.jsxs)("span",{children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.pbk,{})}),Ue.riders.size," riders"]})]}),(0,P.jsxs)("div",{className:"zone-detail-section",children:[(0,P.jsxs)("div",{className:"zone-section-label",children:["Orders ",(0,P.jsxs)("span",{className:"section-count",children:["(",Ue.orders.length,")"]})]}),0===Ue.orders.length?(0,P.jsx)("div",{className:"zone-suburb-panel-empty",children:"No orders for this kitchen."}):(0,P.jsx)("div",{className:"zone-order-grid",children:Ue.orders.map((function(e,s){var n=parseFloat(e.droplat||e.deliverylat),r=parseFloat(e.droplon||e.deliverylong),i=Number.isFinite(n)&&Number.isFinite(r),a=ss&&ss.orderid===e.orderid,c=(0,z.Cl)(e.orderstatus),l=e.rider_id||e.userid,d=l?at.find((function(e){return String(e.id)===String(l)})):null,o=function(){if(!d)return null;var e=(0,t.Z)(d.orders).sort((function(e,s){var n=e.trip_number||1,r=s.trip_number||1;return n!==r?n-r:(e.step||0)-(s.step||0)})).find((function(e){var s=String(e.orderstatus||"").toLowerCase();return!z.Q6.has(s)&&!z.us.has(s)}));return e?e.orderid:null}(),u=o&&e.orderid===o,m=l?Lt(l,e):null;return(0,P.jsxs)("div",{className:"zone-order-card ".concat(i?"clickable":""," ").concat(a?"active":""," ").concat(u?"going-on":""),role:i?"button":void 0,tabIndex:i?0:void 0,onClick:i?function(){return ns(a?null:{orderid:e.orderid,lat:n,lon:r})}:void 0,children:[(0,P.jsxs)("div",{className:"zone-order-card-head",children:[(0,P.jsx)("div",{className:"zone-order-num",children:e.step||s+1}),(0,P.jsxs)("div",{className:"zone-order-id-block",children:[(0,P.jsxs)("div",{className:"zone-order-id",children:["Order #",e.orderid]}),(0,P.jsxs)("div",{className:"zone-order-rider",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.pbk,{})}),e.rider_name||e.ridername||"Unassigned"]})]}),function(){var s=Ne(e.deliverytime),n=Ne(e.expecteddeliverytime),r=!z.Q6.has(String(e.orderstatus||"").toLowerCase())&&null!==m;return e.orderstatus||s||n||r?(0,P.jsxs)("div",{className:"zone-order-status-stack",children:[e.orderstatus&&(0,P.jsx)("span",{className:"zone-order-status",style:{background:c.bg,color:c.fg},children:c.label}),(s||n)&&(0,P.jsxs)("span",{className:"zone-order-time ".concat(s?"":"is-expected"),title:s?"Delivered at ".concat(s):"Expected at ".concat(n),children:[(0,P.jsx)(E.dKE,{}),s||n]}),r&&(0,P.jsxs)("span",{className:"zone-order-est-drop",title:"Estimated distance to drop location",children:[(0,P.jsx)(E.x$F,{}),Dt(m)]})]}):null}()]}),(0,P.jsxs)("div",{className:"zone-order-customer",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.gNp,{})}),e.deliverycustomer||"\u2014"]}),e.pickupcustomer&&(0,P.jsxs)("div",{className:"zone-order-line",title:"Kitchen: ".concat(e.pickupcustomer),children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.TkG,{})}),e.pickupcustomer]}),(e.deliverysuburb||e.deliveryaddress)&&(0,P.jsxs)("div",{className:"zone-order-line",title:e.deliveryaddress||e.deliverysuburb,children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.$0r,{})}),e.deliverysuburb||X(e.deliveryaddress)]}),e.ordernotes&&(0,P.jsxs)("div",{className:"zone-order-line zone-order-notes",title:e.ordernotes,children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.hKf,{})}),e.ordernotes]}),(0,P.jsxs)("div",{className:"zone-order-stats",children:[(0,P.jsxs)("span",{className:"zone-order-chip",title:"Distance",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.v93,{})}),e.actualkms||e.kms||0," km"]}),e.ordertype&&(0,P.jsx)("span",{className:"zone-order-chip zone-order-type type-".concat(String(e.ordertype).toLowerCase()),children:e.ordertype}),(0,P.jsxs)("span",{className:"zone-order-chip zone-order-trip",children:["T",e.trip_number||"-"," \xb7 S",e.step||s+1]})]})]},e.orderid)}))})]})]})]}):Qe?(0,P.jsxs)("div",{id:"route-detail",children:[(0,P.jsx)("button",{className:"rd-back",onClick:function(){return $e(null)},children:"\u2190 Back to zones"}),(0,P.jsx)("div",{className:"rd-rider-name",style:{color:"#3b82f6"},children:Qe.name}),(0,P.jsx)("div",{className:"rd-rider-sub",children:(0,P.jsxs)("span",{children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.ByW,{})}),Qe.totalOrders," ",1===Qe.totalOrders?"order":"orders"]})}),(0,P.jsxs)("div",{className:"zone-detail-section",children:[(0,P.jsxs)("div",{className:"zone-section-label",children:["Orders ",(0,P.jsxs)("span",{className:"section-count",children:["(",Qe.orders.length,")"]})]}),0===Qe.orders.length?(0,P.jsx)("div",{className:"zone-suburb-panel-empty",children:"No orders in this zone."}):(0,P.jsx)("div",{className:"zone-order-grid",children:Qe.orders.map((function(e,s){var n=parseFloat(e.droplat||e.deliverylat),r=parseFloat(e.droplon||e.deliverylong),i=Number.isFinite(n)&&Number.isFinite(r),a=ss&&ss.orderid===e.orderid,c=(0,z.Cl)(e.orderstatus),l=e.rider_id||e.userid,d=l?at.find((function(e){return String(e.id)===String(l)})):null,o=function(){if(!d)return null;var e=(0,t.Z)(d.orders).sort((function(e,s){var n=e.trip_number||1,r=s.trip_number||1;return n!==r?n-r:(e.step||0)-(s.step||0)})).find((function(e){var s=String(e.orderstatus||"").toLowerCase();return!z.Q6.has(s)&&!z.us.has(s)}));return e?e.orderid:null}(),u=o&&e.orderid===o,m=l?Lt(l,e):null;return(0,P.jsxs)("div",{className:"zone-order-card ".concat(i?"clickable":""," ").concat(a?"active":""," ").concat(u?"going-on":""),role:i?"button":void 0,tabIndex:i?0:void 0,onClick:i?function(){return ns(a?null:{orderid:e.orderid,lat:n,lon:r})}:void 0,children:[(0,P.jsxs)("div",{className:"zone-order-card-head",children:[(0,P.jsx)("div",{className:"zone-order-num",children:e.step||s+1}),(0,P.jsxs)("div",{className:"zone-order-id-block",children:[(0,P.jsxs)("div",{className:"zone-order-id",children:["Order #",e.orderid]}),(0,P.jsxs)("div",{className:"zone-order-rider",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.pbk,{})}),e.rider_name||e.ridername||"Unassigned"]})]}),function(){var s=Ne(e.deliverytime),n=Ne(e.expecteddeliverytime),r=!z.Q6.has(String(e.orderstatus||"").toLowerCase())&&null!==m;return e.orderstatus||s||n||r?(0,P.jsxs)("div",{className:"zone-order-status-stack",children:[e.orderstatus&&(0,P.jsx)("span",{className:"zone-order-status",style:{background:c.bg,color:c.fg},children:c.label}),(s||n)&&(0,P.jsxs)("span",{className:"zone-order-time ".concat(s?"":"is-expected"),title:s?"Delivered at ".concat(s):"Expected at ".concat(n),children:[(0,P.jsx)(E.dKE,{}),s||n]}),r&&(0,P.jsxs)("span",{className:"zone-order-est-drop",title:"Estimated distance to drop location",children:[(0,P.jsx)(E.x$F,{}),Dt(m)]})]}):null}()]}),(0,P.jsxs)("div",{className:"zone-order-customer",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.gNp,{})}),e.deliverycustomer||"\u2014"]}),e.pickupcustomer&&(0,P.jsxs)("div",{className:"zone-order-line",title:"Kitchen: ".concat(e.pickupcustomer),children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.TkG,{})}),e.pickupcustomer]}),(e.deliverysuburb||e.deliveryaddress)&&(0,P.jsxs)("div",{className:"zone-order-line",title:e.deliveryaddress||e.deliverysuburb,children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.$0r,{})}),e.deliverysuburb||X(e.deliveryaddress)]}),e.ordernotes&&(0,P.jsxs)("div",{className:"zone-order-line zone-order-notes",title:e.ordernotes,children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.hKf,{})}),e.ordernotes]}),(0,P.jsxs)("div",{className:"zone-order-stats",children:[(0,P.jsxs)("span",{className:"zone-order-chip",title:"Distance",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.v93,{})}),e.actualkms||e.kms||0," km"]}),e.ordertype&&(0,P.jsx)("span",{className:"zone-order-chip zone-order-type type-".concat(String(e.ordertype).toLowerCase()),children:e.ordertype}),(0,P.jsxs)("span",{className:"zone-order-chip zone-order-trip",children:["T",e.trip_number||"-"," \xb7 S",e.step||s+1]})]})]},e.orderid)}))})]})]}):(0,P.jsxs)("div",{id:"riders-panel",children:[!ut&&(0,P.jsx)("div",{className:"ph",children:"zones"===O?"Zone dispatch":"kitchens"===O?"Kitchen dispatch":"all"===O?"Active rider dispatch":"Rider dispatch"}),(0,P.jsx)("div",{id:"rider-cards",children:0!==lt.length||Vr?"zones"===O?tt.map((function(e,s){var n=e.statusCounts.delivered||0;return(0,P.jsxs)("div",{className:"rcard zone-card",onClick:function(){return $e(e)},style:{animationDelay:"".concat(.05*s,"s")},children:[(0,P.jsxs)("div",{className:"zone-card-header",children:[(0,P.jsx)("div",{className:"zone-card-emoji",children:(0,P.jsx)(E.PKO,{})}),(0,P.jsxs)("div",{className:"zone-card-titles",children:[(0,P.jsx)("div",{className:"zone-card-name",children:e.name}),(0,P.jsxs)("div",{className:"zone-card-sub",children:[e.activeRidersCount," ",1===e.activeRidersCount?"rider":"riders"," \xb7 ",e.totalOrders," ",1===e.totalOrders?"order":"orders"]})]}),(0,P.jsx)("span",{className:"zone-card-arrow","aria-hidden":"true",children:"\u2192"})]}),e.totalOrders>0&&(0,P.jsxs)("div",{className:"zone-progress-row",children:[(0,P.jsx)("div",{className:"zone-status-bar",title:Object.entries(e.statusCounts).map((function(e){var s=(0,l.Z)(e,2),n=s[0],r=s[1];return"".concat((0,z.Cl)(n).label,": ").concat(r)})).join(" \xb7 "),children:Object.entries(e.statusCounts).map((function(s){var n=(0,l.Z)(s,2),r=n[0],t=n[1],i=(0,z.Cl)(r),a=t/e.totalOrders*100;return(0,P.jsx)("div",{className:"zone-status-seg",style:{width:"".concat(a,"%"),background:i.bg}},r)}))}),(0,P.jsxs)("div",{className:"zone-progress-label",children:[n,"/",e.totalOrders]})]}),(0,P.jsxs)("div",{className:"zone-stat-pills",children:[(0,P.jsxs)("span",{className:"zone-stat-pill",title:"Areas covered",children:[(0,P.jsx)("span",{className:"zone-stat-icon",children:(0,P.jsx)(E.$0r,{})}),(0,P.jsx)("span",{className:"zone-stat-value",children:e.suburbs.length}),(0,P.jsx)("span",{className:"zone-stat-label",children:1===e.suburbs.length?"area":"areas"})]}),(0,P.jsxs)("span",{className:"zone-stat-pill",title:"Total distance",children:[(0,P.jsx)("span",{className:"zone-stat-icon",children:(0,P.jsx)(E.v93,{})}),(0,P.jsx)("span",{className:"zone-stat-value",children:e.totalKms.toFixed(1)}),(0,P.jsx)("span",{className:"zone-stat-label",children:"km"})]}),(0,P.jsxs)("span",{className:"zone-stat-pill",title:"Kitchens",children:[(0,P.jsx)("span",{className:"zone-stat-icon",children:(0,P.jsx)(E.TkG,{})}),(0,P.jsx)("span",{className:"zone-stat-value",children:e.kitchens.length}),(0,P.jsx)("span",{className:"zone-stat-label",children:1===e.kitchens.length?"kitchen":"kitchens"})]})]}),e.suburbs.length>0&&(0,P.jsxs)("div",{className:"zone-card-suburbs",children:[(0,P.jsx)("span",{className:"zone-card-suburbs-text",children:e.suburbs.slice(0,3).map((function(e){return e.name})).join(" \xb7 ")}),e.suburbs.length>3&&(0,P.jsxs)("span",{className:"zone-card-suburbs-more",children:["+",e.suburbs.length-3]})]})]},e.id)})):"kitchens"===O?ct.map((function(e,s){return(0,P.jsxs)("div",{className:"rcard",onClick:function(){return Ve(e)},style:{animationDelay:"".concat(.05*s,"s")},children:[(0,P.jsxs)("div",{className:"rcard-top",children:[(0,P.jsx)("div",{className:"rcard-emo",style:{background:"#f59e0b18",borderColor:"#f59e0b50",color:"#f59e0b"},children:(0,P.jsx)(E.TkG,{})}),(0,P.jsxs)("div",{className:"rcard-info",children:[(0,P.jsx)("div",{className:"rcard-name",children:e.kitchenName}),(0,P.jsxs)("div",{className:"rcard-zone",children:[e.riders.size," ",1===e.riders.size?"rider":"riders"]})]}),(0,P.jsx)("div",{className:"rcard-badge",style:{background:"#f59e0b18",color:"#f59e0b"},children:e.orders.length})]}),(0,P.jsx)("div",{className:"bar-bg",children:(0,P.jsx)("div",{className:"bar-fg",style:{width:"".concat(Math.min(100,e.orders.length/20*100),"%"),background:"#f59e0b"}})}),(0,P.jsxs)("div",{className:"rcard-meta",children:[(0,P.jsxs)("span",{children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.v93,{})}),e.orders.reduce((function(e,s){return e+parseFloat(s.actualkms||s.kms||0)}),0).toFixed(1)," km"]}),(0,P.jsxs)("span",{children:[e.riders.size," riders"]})]}),(0,P.jsx)("div",{className:"step-ids",children:Array.from(e.riders).slice(0,10).map((function(e){var s;return(0,P.jsx)("span",{className:"step-id",style:{color:Rt(e)},children:null===(s=at.find((function(s){return s.id===e})))||void 0===s?void 0:s.riderName.split(" ")[0]},e)}))})]},e.id)})):ut?(0,P.jsx)(Z,{visibleRiders:ht,riders:at,focusedStop:ss,handleRiderFocus:ft,setFocusedStop:ns,calculateEstMeters:Lt,getRiderColor:Rt,formatMeters:Dt,isLoading:Br&&Vr&&0===ht.length}):ht.map((function(e,s){var n,r=e.orders.length,t=e.orders.filter((function(e){return z.Q6.has(String(e.orderstatus||"").toLowerCase())})).length,i=r>0&&t>=r,a=e.orders.find((function(e){var s=String(e.orderstatus||"").toLowerCase();return!z.Q6.has(s)&&!z.us.has(s)})),c=a?Lt(e.id,a):null,l=e.gpsOnly||0===r;return(0,P.jsxs)("div",{className:"rcard".concat(l?" is-gps-only":""),onClick:l?void 0:function(){return ft(e)},style:{animationDelay:"".concat(.05*s,"s")},children:[(0,P.jsxs)("div",{className:"rcard-top",children:[(0,P.jsx)("div",{className:"rcard-emo",style:{background:"".concat(e.color,"18"),borderColor:"".concat(e.color,"50"),color:e.color},children:(0,P.jsx)(E.pbk,{})}),(0,P.jsxs)("div",{className:"rcard-info",children:[(0,P.jsx)("div",{className:"rcard-name",children:e.riderName}),(0,P.jsx)("div",{className:"rcard-zone",children:l?"Live GPS \xb7 no active delivery":"".concat((null===(n=e.orders[0])||void 0===n?void 0:n.zone_name)||vn||"Local"," \xb7 ").concat(new Set(e.orders.map((function(e){return e.trip_number||1}))).size," trips")})]}),l?(0,P.jsxs)("div",{className:"rcard-badge rcard-badge-live",title:"Rider is live on GPS with no active delivery",children:[(0,P.jsx)("span",{className:"rcard-live-dot"})," LIVE"]}):(0,P.jsxs)("div",{className:"rcard-badge ".concat(i?"is-done":""),style:i?void 0:{background:"".concat(e.color,"18"),color:e.color},title:"".concat(t," delivered of ").concat(r," total"),children:[t,"/",r]})]}),!l&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)("div",{className:"bar-bg",children:(0,P.jsx)("div",{className:"bar-fg",style:{width:"".concat(Math.min(100,r/15*100),"%"),background:e.color}})}),(0,P.jsxs)("div",{className:"rcard-meta",children:[(0,P.jsxs)("span",{children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.v93,{})}),e.orders.reduce((function(e,s){return e+parseFloat(s.actualkms||s.kms||0)}),0).toFixed(1)," km"]}),null!==c&&(0,P.jsxs)("span",{className:"rcard-est-meters",title:"Estimated distance to next drop location",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(E.x$F,{})}),Dt(c)," to drop"]})]}),(0,P.jsx)("div",{className:"step-ids",children:e.orders.slice(0,15).map((function(e){return(0,P.jsxs)("span",{className:"step-id",children:["S",e.step]},e.orderid)}))})]})]},e.id)})):function(){var e,s=null===(e=Ys.find((function(e){return e.id===Ir})))||void 0===e?void 0:e.label,n=Br&&Xr.length>0;return(0,P.jsxs)("div",{className:"empty-slot",children:[(0,P.jsx)("div",{className:"empty-slot-icon",children:(0,P.jsx)(E.ByW,{})}),(0,P.jsx)("div",{className:"empty-slot-title",children:s?"No orders in ".concat(s):"No orders"}),(0,P.jsx)("div",{className:"empty-slot-sub",children:n?"".concat(Xr.length," order").concat(1===Xr.length?"":"s"," exist in other slots today"):"No deliveries found for this date"})]})}()})]})]}),(0,P.jsxs)("div",{id:"map-wrap",className:"".concat("kitchens"===O?"view-mode-kitchens":""," ").concat(er?"compare-split":"").trim(),children:[(0,P.jsxs)(v.h,{center:[11.022,76.982],zoom:12,scrollWheelZoom:!0,style:{height:"100%",width:"100%"},zoomControl:!1,renderer:Rr.current,inertia:!0,inertiaDeceleration:2400,inertiaMaxSpeed:2e3,wheelDebounceTime:20,wheelPxPerZoomLevel:80,zoomSnap:.25,children:[(0,P.jsx)(f.I,{url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",attribution:"\xa9 OpenStreetMap contributors"}),(0,P.jsx)(g.L,{position:"bottomright"}),er&&(0,P.jsx)(ve,{targetRef:Pr}),(0,P.jsx)(_e,{focusedItem:Ct||(ot||Ue)&&ss||ot||Ue||Qe,viewMode:O,orders:mt,kitchens:ct,locationKey:As,extraPoints:vt,flyTo:is}),ct.filter((function(e){return Number.isFinite(e.lat)&&Number.isFinite(e.lon)})).filter((function(e){return!ot||e.riders.has(ot.id)})).map((function(e,s){return(0,P.jsx)(p.J,{position:[e.lat,e.lon],icon:Pt(e.kitchenName,(null===Ue||void 0===Ue?void 0:Ue.id)===e.id),zIndexOffset:(null===Ue||void 0===Ue?void 0:Ue.id)===e.id?4e3:2e3,eventHandlers:{click:function(){return Ve(e)},mouseover:function(e){return e.target.openPopup()},mouseout:function(e){return e.target.closePopup()}},children:(0,P.jsxs)(j.G,{className:"kitchen-popup",maxWidth:220,minWidth:200,autoPan:!0,autoPanPadding:[20,20],children:[(0,P.jsx)("div",{className:"kp-header",children:"KITCHEN"}),(0,P.jsx)("div",{className:"kp-name",children:e.kitchenName}),(0,P.jsxs)("div",{className:"kp-stat",children:[(0,P.jsx)("span",{className:"kp-stat-lbl",children:"Orders"}),(0,P.jsx)("span",{className:"kp-stat-val",children:e.orders.length})]})]})},"k-".concat(s))})),function(){if(er&&ot&&"actual"===tr)return null;var e=mt;if(Qe&&(e=Qe.orders),Ue&&(e=Ue.orders),ot&&(e=ot.orders),e=e.filter(ee),ut)if(ot){var s=(0,z.P0)(ot.orders),n=s?String(s.orderid):null;e=n?e.filter((function(e){return String(e.orderid)===n})):[]}else{var r=new Set(ht.map((function(e){return(0,z.P0)(e.orders)})).filter(Boolean).map((function(e){return String(e.orderid)})));e=e.filter((function(e){return r.has(String(e.orderid))}))}var t=er&&ot?new Map(St.map((function(e){return[String(e.deliveryid),e.sequenceStep]}))):null;return e.map((function(s,n){var r,i=s.rider_id,a=!i||Oe.has(i),c=Rt(i);if(t&&i===ot.id&&null!=s.deliveryid){var l=t.get(String(s.deliveryid));l&&(c=(0,z.di)(l-1),r=l)}var d=!!ot||!!Ue,o=(0,z.Cl)(s.orderstatus),u="delivered"===String(s.orderstatus||"").toLowerCase(),m=k&&String(k)===String(s.orderid),h=s.orderstatus?'<svg class="cmark-flag" viewBox="0 0 18 22" xmlns="http://www.w3.org/2000/svg">\n <line x1="1.5" y1="0" x2="1.5" y2="22" stroke="#0f172a" stroke-width="1.6" stroke-linecap="round"/>\n <polygon points="2,1 17,1 13.5,5.5 17,10 2,10" fill="'.concat(o.bg,'" stroke="#0f172a" stroke-width="0.6" stroke-linejoin="round"/>\n ').concat(u?'<polyline points="5,5.5 7,7.5 11,3.5" fill="none" stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>':"","\n </svg>"):"",v=d?function(){var n=r||s.step||e.indexOf(s)+1,t=32;return b().divIcon({className:"",iconSize:[t,t],iconAnchor:[16,16],popupAnchor:[0,-28],html:'<div class="cmark is-rider-focused'.concat(m?" pulse":"",'" style="background:').concat(c,";width:").concat(t,"px;height:").concat(t,"px;font-size:").concat(n>9?12:14,"px;opacity:").concat(a?1:.75,'">').concat(n>0?n:"").concat(h,"</div>")})}():b().divIcon({className:"",iconSize:[24,30],iconAnchor:[2,30],popupAnchor:[10,-25],html:'<div class="cmark'.concat(m?" pulse":"",'" style="width:24px;height:30px;opacity:').concat(a?1:.75,'">').concat(h,"</div>")});return(0,P.jsx)(p.J,{position:[parseFloat(s.droplat||s.deliverylat),parseFloat(s.droplon||s.deliverylong)],icon:v,zIndexOffset:i?100:0,ref:function(e){e?os.current[String(s.orderid)]=e:delete os.current[String(s.orderid)]},eventHandlers:{click:function(){var e=String(s.orderid);us.current.has(e)?(us.current.delete(e),js(null)):(us.current.add(e),js(s))}}},"".concat(s.orderid,"-").concat(d?"num":"flag"))}))}(),function(){var e=er&&ot&&"actual"===tr;if(An)return e?[]:zn.map((function(e,s){return(0,P.jsx)(h.a,{positions:[e.from,e.to],pathOptions:{color:e.color,weight:6,opacity:.9,lineJoin:"round",lineCap:"round"}},s)}));var s=[],n=Qe?new Set(Qe.riders.map((function(e){return String(e.rider_id)}))):null;return e||ht.forEach((function(e){var r=Oe.has(e.id);if((!ot||ot.id===e.id)&&(!Ue||Ue.riders.has(e.id))&&(!n||n.has(String(e.id)))){var i=ut?(0,z.P0)(e.orders):null,a=ut?i?[i]:[]:e.orders;if(!ut||0!==a.length){var c={};a.forEach((function(e){var s=e.trip_number||1;c[s]||(c[s]=[]),c[s].push(e)})),Object.entries(c).forEach((function(n){var i=(0,l.Z)(n,2),a=i[0],c=i[1],d=Ue?c.filter((function(e){return(e.pickupcustomer||e.kitchen_key||"Unknown").toLowerCase().trim()===Ue.id})):c;if(0!==d.length){var o="".concat(e.id,"-").concat(a),m=jn[o],p=(0,t.Z)(d).sort((function(e,s){return(e.step||0)-(s.step||0)})),v=r?1:.1,f="kitchens"===O||Ue?7:6,x=er&&ot&&e.id===ot.id;if(!x){var j=[],g=!1;if(p.forEach((function(e){if(null!=e.deliveryid&&""!==e.deliveryid&&0!==e.deliveryid){var s=String(e.deliveryid),n=kn[s],r=kt.get(s),i=null;if(Array.isArray(n)&&n.length>=2?i=n:r&&r.coords.length>=2&&(i=r.coords.map((function(e){return[e.lat,e.lng]}))),i)if(g=!0,0===j.length)j.push.apply(j,(0,t.Z)(i));else{var a=j[j.length-1],c=i[0],l=Math.abs(a[0]-c[0])<1e-5&&Math.abs(a[1]-c[1])<1e-5;j.push.apply(j,(0,t.Z)(l?i.slice(1):i))}}})),g&&j.length>=2)return void s.push((0,P.jsxs)(u.Fragment,{children:[(0,P.jsx)(h.a,{positions:j,pathOptions:{color:"#ffffff",weight:f+4,opacity:.5*v,lineJoin:"round",lineCap:"round"}}),(0,P.jsx)(h.a,{positions:j,pathOptions:{color:e.color,weight:f,opacity:v,lineJoin:"round",lineCap:"round"}})]},"".concat(e.id,"-").concat(a,"-actual")))}var N=ut?p[0]:null,b=null;if(ut&&N){var y=Zr.find((function(s){return String(s.id)===String(e.id)})),k=y&&Number.isFinite(y.lat)&&Number.isFinite(y.lon)?[y.lat,y.lon]:re(N)?[$(se(N)),$(ne(N))]:null,S=$(N.droplat||N.deliverylat),_=$(N.droplon||N.deliverylong);k&&Number.isFinite(S)&&Number.isFinite(_)&&(b=[k,[S,_]])}var w=ut?N?jn["".concat(e.id,"-active-").concat(N.orderid)]:void 0:m,F=Array.isArray(w)&&w.length>=2,A=!1===w;if(ut||F||A){var C=F?w:ut?b:ye(p);if(C&&!(C.length<2)){var E=er&&ot&&e.id===ot.id,M=A?"8 6":E&&"combined"===tr?"6 5":void 0;if(x){var R,L=new Map(St.map((function(e){return[String(e.deliveryid),e.sequenceStep]}))),D=p.filter(ee),Z=D.map((function(e){return[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]}));if(F)R=ge(C,Z);else{var q=C.length>Z.length;R=[];for(var T=0;T<Z.length;T++){var I=q?T:T-1,H=q?T+1:T;I<0||I>=C.length||H>=C.length?R.push([]):R.push([C[I],C[H]])}}var K="combined"===tr?5:0;return s.push((0,P.jsx)(h.a,{positions:C,pathOptions:{color:"#ffffff",weight:f+4,opacity:.5*v,lineJoin:"round",lineCap:"round",offset:K}},"".concat(e.id,"-").concat(a,"-halo"))),void R.forEach((function(n,r){if(n&&!(n.length<2)){var t=D[r],i=t?L.get(String(t.deliveryid)):null,c="combined"===tr?J:i?(0,z.di)(i-1):e.color,l=null!=Mr&&Mr===i,d=l?f+1.5:f,o=l?1:Mr?.5*v:v;s.push((0,P.jsx)(h.a,{positions:n,pathOptions:{color:c,weight:d,opacity:o,lineJoin:"round",lineCap:"round",dashArray:M,offset:K}},"".concat(e.id,"-").concat(a,"-step-").concat(r,"-").concat((null===t||void 0===t?void 0:t.deliveryid)||r)))}}))}s.push((0,P.jsxs)(u.Fragment,{children:[(0,P.jsx)(h.a,{positions:C,pathOptions:{color:"#ffffff",weight:f+4,opacity:.5*v,lineJoin:"round",lineCap:"round"}}),(0,P.jsx)(h.a,{positions:C,pathOptions:{color:e.color,weight:f,opacity:v,lineJoin:"round",lineCap:"round",dashArray:M}})]},"".concat(e.id,"-").concat(a)))}}}}))}}})),s}(),Zr.filter((function(e){return ut?"active"===e.status&&pt.has(String(e.id)):at.some((function(s){return String(s.id)===String(e.id)}))})).filter((function(e){return!ot||String(ot.id)===String(e.id)})).map((function(e){var s,n="active"===e.status,r=n?"#16a34a":"#dc2626",t=at.find((function(s){return String(s.id)===String(e.id)})),i=null===t||void 0===t||null===(s=t.orders)||void 0===s?void 0:s.slice().sort((function(e,s){var n=e.trip_number||1,r=s.trip_number||1;return n!==r?n-r:(e.step||0)-(s.step||0)})).find((function(e){var s=String(e.orderstatus||"").toLowerCase();return!z.Q6.has(s)&&!z.us.has(s)})),a=i?i.deliverysuburb||X(i.deliveryaddress):null,c=(e.username||"").replace(/[<>&"']/g,""),l=e.orderid?String(e.orderid).replace(/[<>&"']/g,""):"",d="".concat(ut?"bike":"pin","|").concat(r,"|").concat(c,"|").concat(l,"|").concat(n?1:0),u=ps.current.get(e.id);u&&u.sig===d||(u={sig:d,icon:ut?b().divIcon({className:"",iconSize:[160,44],iconAnchor:[22,22],popupAnchor:[0,-22],html:'<div class="live-rider-bike '.concat(n?"is-active":"is-idle",'" style="--pin-color:').concat(r,'">\n <span class="live-rider-bike-pulse"></span>\n <span class="live-rider-bike-badge">\n <svg viewBox="0 0 24 24" width="20" height="20" fill="#fff" aria-hidden="true"><path d="M19.44 9.03 15.41 5H11v2h3.59l2 2H5c-2.8 0-5 2.2-5 5s2.2 5 5 5c2.46 0 4.45-1.69 4.9-4h1.65l2.77-2.77c-.21.54-.32 1.14-.32 1.77 0 2.76 2.24 5 5 5s5-2.24 5-5c0-2.65-2.06-4.77-4.66-4.97ZM7.82 15C7.4 16.15 6.28 17 5 17c-1.63 0-3-1.37-3-3s1.37-3 3-3c1.28 0 2.4.85 2.82 2H5v2h2.82ZM19 17c-1.63 0-3-1.37-3-3s1.37-3 3-3 3 1.37 3 3-1.37 3-3 3Z"/></svg>\n </span>\n <span class="live-rider-bike-label">').concat(c).concat(l?" <span>#".concat(l,"</span>"):"","</span>\n </div>")}):b().divIcon({className:"",iconSize:[140,56],iconAnchor:[12,41],popupAnchor:[58,-40],html:'<div class="live-rider-pin" style="--pin-color:'.concat(r,'">\n <div class="live-rider-pin-marker"></div>\n <div class="live-rider-pin-label">').concat(c).concat(l?" <span>#".concat(l,"</span>"):"","</div>\n </div>")})},ps.current.set(e.id,u));var m=u.icon,h={click:function(s){var n=String(e.id);ms.current.has(n)?(ms.current.delete(n),s.target.closePopup()):(ms.current.add(n),s.target.openPopup());var r=at.find((function(e){return String(e.id)===n}));r&&ft(r)},popupclose:function(){ms.current.delete(String(e.id))}},v=ut?we:p.J,f=ut?{target:[e.lat,e.lon],duration:1200}:{position:[e.lat,e.lon]};return(0,P.jsx)(v,(0,o.Z)((0,o.Z)({},f),{},{icon:m,zIndexOffset:2500,eventHandlers:h,children:(0,P.jsxs)(j.G,{maxWidth:260,autoPan:!0,autoPanPadding:[20,20],className:"dispatch-popup live-rider-popup",children:[(0,P.jsx)("div",{className:"pu-hdr-live",children:(0,P.jsxs)("div",{className:"pu-hdr-left",children:[(0,P.jsx)("span",{className:"pu-live-indicator",style:{"--pulse-color":r},children:(0,P.jsx)("span",{className:"pu-live-dot"})}),(0,P.jsx)("span",{className:"pu-hdr-title",children:"LIVE GPS"})]})}),(0,P.jsxs)("div",{className:"pu-rider-profile",children:[(0,P.jsx)("div",{className:"pu-avatar",style:{backgroundColor:"".concat(r,"12"),color:r},children:(0,P.jsx)(E.MCF,{})}),(0,P.jsxs)("div",{className:"pu-rider-info-text",children:[(0,P.jsxs)("div",{className:"pu-rider-name-row",children:[(0,P.jsx)("span",{className:"pu-rider-name",children:e.username||"Rider #".concat(e.id)}),e.status&&(0,P.jsx)("span",{className:"pu-status-badge ".concat("active"===e.status.toLowerCase()?"active":"idle"),children:e.status})]}),(0,P.jsxs)("div",{className:"pu-rider-meta",children:["Rider ID: #",e.id]})]})]}),(0,P.jsxs)("div",{className:"pu-body-content",children:[e.orderid&&(0,P.jsxs)("div",{className:"pu-info-row",children:[(0,P.jsx)("span",{className:"pu-info-label",children:"Active Order"}),(0,P.jsxs)("span",{className:"pu-info-value pu-order-badge",children:["#",e.orderid]})]}),i&&(0,P.jsxs)("div",{className:"pu-info-row",children:[(0,P.jsx)("span",{className:"pu-info-label",children:"Next Stop"}),(0,P.jsxs)("span",{className:"pu-info-value",style:{color:"#4f46e5"},children:["#",i.step||"?"," \xb7 ",i.deliverycustomer||"\u2014"]})]}),a&&(0,P.jsxs)("div",{className:"pu-info-row",children:[(0,P.jsx)("span",{className:"pu-info-label",children:"Next Location"}),(0,P.jsx)("span",{className:"pu-info-value",title:i.deliveryaddress||a,children:a})]}),(null===i||void 0===i?void 0:i.pickupcustomer)&&(0,P.jsxs)("div",{className:"pu-info-row",children:[(0,P.jsx)("span",{className:"pu-info-label",children:"Pickup"}),(0,P.jsx)("span",{className:"pu-info-value",title:i.pickupcustomer,children:i.pickupcustomer})]}),e.contactno&&(0,P.jsxs)("div",{className:"pu-info-row",children:[(0,P.jsx)("span",{className:"pu-info-label",children:"Phone"}),(0,P.jsx)("a",{href:"tel:".concat(e.contactno),className:"pu-info-value pu-phone-link",children:e.contactno})]}),e.logdate&&(0,P.jsxs)("div",{className:"pu-info-row",children:[(0,P.jsx)("span",{className:"pu-info-label",children:"Last Seen"}),(0,P.jsxs)("span",{className:"pu-info-value pu-time-stamp",children:[(0,P.jsx)(E.dKE,{className:"inline-icon"})," ",S()(e.logdate).isValid()?S()(e.logdate).format("hh:mm:ss A"):e.logdate]})]}),(0,P.jsxs)("div",{className:"pu-info-row",children:[(0,P.jsx)("span",{className:"pu-info-label",children:"Position"}),(0,P.jsxs)("span",{className:"pu-info-value pu-coordinates",children:[e.lat.toFixed(5),", ",e.lon.toFixed(5)]})]})]})]})}),"live-".concat(e.id))})),er&&ot&&"planned"!==tr&&St.map((function(e,s){var n,r;if(0===e.coords.length)return null;var t=(0,z.di)(s),i="combined"===tr?Q:t,a=[e.coords[0].lat,e.coords[0].lng],c=[e.coords[e.coords.length-1].lat,e.coords[e.coords.length-1].lng],l=kn[e.deliveryid],d=Array.isArray(l)&&l.length>=2?l:e.coords.map((function(e){return[e.lat,e.lng]})),o=d,m=!0;if(An){var v=Dn[e.sequenceStep]||0;v<2?m=!1:o=d.slice(0,Math.min(v,d.length))}var f=Mr===e.sequenceStep,j=String(e.orderstatus||"").toLowerCase(),g=z.Q6.has(j),N=z.us.has(j),y=_t.find((function(s){return s.sequenceStep===e.sequenceStep})),k=!(null===y||void 0===y||!y.anomaly),_=null===ot||void 0===ot||null===(n=ot.orders)||void 0===n?void 0:n.find((function(s){return null!=s.deliveryid&&String(s.deliveryid)===String(e.deliveryid)})),w=(0,z.Cl)(e.orderstatus),F=(e.orderstatus&&'<svg class="cmark-flag" viewBox="0 0 18 22" xmlns="http://www.w3.org/2000/svg">\n <line x1="1.5" y1="0" x2="1.5" y2="22" stroke="#0f172a" stroke-width="1.6" stroke-linecap="round"/>\n <polygon points="2,1 17,1 13.5,5.5 17,10 2,10" fill="'.concat(w.bg,'" stroke="#0f172a" stroke-width="0.6" stroke-linejoin="round"/>\n ').concat(g?'<polyline points="5,5.5 7,7.5 11,3.5" fill="none" stroke="#fff" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>':"","\n </svg>"),["compare-step-pin"]);f&&F.push("is-focused"),g&&F.push("is-delivered"),N&&F.push("is-skipped"),k&&F.push("is-anomaly");var A='<div class="'.concat(F.join(" "),'" style="--pin-color:').concat(t,'">')+'<span class="compare-step-pin-num">'.concat(e.sequenceStep,"</span>")+(g?'<svg class="compare-step-pin-check" viewBox="0 0 12 12" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M2.5 6.5 L5 9 L9.5 3.5" stroke="white" stroke-width="2" fill="none" stroke-linecap="round" stroke-linejoin="round"/></svg>':"")+"</div>",C=b().divIcon({className:"",iconSize:[36,36],iconAnchor:[18,18],popupAnchor:[0,-22],html:A}),M=1===e.sequenceStep,R=M?b().divIcon({className:"",iconSize:[40,40],iconAnchor:[20,20],html:'<div class="compare-start-pin" style="--pin-color:'.concat(t,'">')+'<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg" aria-hidden="true"><path d="M19 6h-2c0-2.76-2.24-5-5-5S7 3.24 7 6H5c-1.1 0-2 .9-2 2v12c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2V8c0-1.1-.9-2-2-2zm-7-3c1.66 0 3 1.34 3 3H9c0-1.66 1.34-3 3-3zm0 10c-2.76 0-5-2.24-5-5h2c0 1.66 1.34 3 3 3s3-1.34 3-3h2c0 2.76-2.24 5-5 5z" fill="currentColor"/></svg></div>'}):null,L=function(s){s.originalEvent&&s.originalEvent.stopPropagation(),zr((function(s){return s===e.sequenceStep?null:e.sequenceStep})),_&&s.target&&"function"===typeof s.target.openPopup&&s.target.openPopup()},D="combined"===tr?-5:0;return(0,P.jsxs)(u.Fragment,{children:[m&&(0,P.jsx)(h.a,{positions:o,pathOptions:{color:"#ffffff",weight:f?11:9,opacity:f?.75:.55,lineJoin:"round",lineCap:"round",offset:D}}),m&&(0,P.jsx)(h.a,{positions:o,pathOptions:{color:i,weight:f?6.5:5,opacity:f?1:Mr?.55:.95,lineJoin:"round",lineCap:"round",offset:D}}),M&&(0,P.jsx)(p.J,{position:a,icon:R,zIndexOffset:f?900:100,eventHandlers:{click:function(s){s.originalEvent&&s.originalEvent.stopPropagation(),zr((function(s){return s===e.sequenceStep?null:e.sequenceStep}))}},children:(0,P.jsx)(x.u,{direction:"top",offset:[0,-12],opacity:1,className:"compare-tooltip",children:(0,P.jsxs)("div",{className:"cmp-tip",children:[(0,P.jsxs)("div",{className:"cmp-tip-header",children:[(0,P.jsx)("span",{className:"cmp-tip-step",style:{background:t},children:(0,P.jsx)(E.YD2,{})}),(0,P.jsxs)("div",{className:"cmp-tip-title-stack",children:[(0,P.jsx)("div",{className:"cmp-tip-title",children:e.pickupcustomer||"Pickup"}),(0,P.jsx)("div",{className:"cmp-tip-sub",children:null!==(r=e.coords[0])&&void 0!==r&&r.logdate?"Picked up \xb7 ".concat(S()(e.coords[0].logdate).format("hh:mm A")):"Rider trip origin"})]})]}),(0,P.jsx)("div",{className:"cmp-tip-action",children:"Click for step 1 details"})]})})}),(0,P.jsx)(p.J,{position:c,icon:C,zIndexOffset:f?1e3:200,eventHandlers:_?{mouseover:function(){hs.current&&(clearTimeout(hs.current),hs.current=null),js(_)},mouseout:function(){Mr!==e.sequenceStep&&(hs.current&&clearTimeout(hs.current),hs.current=setTimeout((function(){js((function(e){return e&&String(e.orderid)===String(_.orderid)?null:e})),hs.current=null}),200))},click:L}:{click:L},children:!_&&(0,P.jsx)(x.u,{direction:"top",offset:[0,-20],opacity:1,className:"compare-tooltip",children:function(){var s=(0,z.Cl)(e.orderstatus);return(0,P.jsxs)("div",{className:"cmp-tip",children:[(0,P.jsxs)("div",{className:"cmp-tip-header",children:[(0,P.jsx)("span",{className:"cmp-tip-step",style:{background:t},children:e.sequenceStep}),(0,P.jsxs)("div",{className:"cmp-tip-title-stack",children:[(0,P.jsx)("div",{className:"cmp-tip-title",children:e.deliverycustomer||"Step ".concat(e.sequenceStep)}),(0,P.jsx)("div",{className:"cmp-tip-sub",children:e.deliverytime?"Delivered ".concat(S()(e.deliverytime).format("hh:mm A")):"".concat(e.coords.length," GPS pings")})]}),e.orderstatus&&(0,P.jsx)("span",{className:"cmp-tip-tag",style:{background:s.bg,color:s.fg},children:s.label})]}),k&&(0,P.jsx)("div",{className:"cmp-tip-anomaly",children:"Deviation flagged \u2014 see details below"}),(0,P.jsx)("div",{className:"cmp-tip-action",children:f?"Click to deselect":"Click for details"})]})}()})})]},"actual-".concat(e.deliveryid))}))]}),er&&ot&&(0,P.jsxs)("div",{className:"compare-view-switcher",role:"group","aria-label":"Compare view layer",children:[(0,P.jsx)("button",{type:"button",className:"actual"===tr?"is-active":"",onClick:function(){return ir("actual")},title:"Show only the rider's actual GPS trail",children:"Actual"}),(0,P.jsx)("button",{type:"button",className:"planned"===tr?"is-active":"",onClick:function(){return ir("planned")},title:"Show only the dispatched planned route",children:"Planned"}),(0,P.jsx)("button",{type:"button",className:"combined"===tr?"is-active":"",onClick:function(){return ir("combined")},title:"Overlay planned (dashed) and actual (solid) on one map",children:"Combined"})]}),(0,P.jsx)("div",{id:"ov-tl"}),(0,P.jsx)("div",{id:"ov-br",children:(0,P.jsxs)("button",{className:"sbt ".concat(An?"active":""),onClick:function(){if(An)return Cn(!1),Pn([]),void Zn({});Cn(!0),Pn([]),Zn({});var e=er&&ot,s=e?new Map(St.map((function(e){return[String(e.deliveryid),e.sequenceStep]}))):null,n=[];if(at.forEach((function(r){if(Oe.has(r.id)&&(!ot||ot.id===r.id)&&(!Ue||Ue.riders.has(r.id))){var i=ut?(0,z.P0)(r.orders):null,a=i&&"active"===String(i.orderstatus||"").toLowerCase(),c=ut?a?[i]:[]:r.orders,d={};c.forEach((function(e){var s=e.trip_number||1;d[s]||(d[s]=[]),d[s].push(e)})),Object.entries(d).forEach((function(i){var a=(0,l.Z)(i,2),c=a[0],d=a[1],o=Ue?d.filter((function(e){return(e.pickupcustomer||e.kitchen_key||"Unknown").toLowerCase().trim()===Ue.id})):d;if(0!==o.length){var u=ut?"".concat(r.id,"-active-").concat(o[0].orderid):"".concat(r.id,"-").concat(c),m=jn[u],p=(0,t.Z)(o).sort((function(e,s){return(e.step||0)-(s.step||0)})),h=null;if(ut&&o[0]){var v=o[0],f=Zr.find((function(e){return String(e.id)===String(r.id)})),x=f&&Number.isFinite(f.lat)&&Number.isFinite(f.lon)?[f.lat,f.lon]:re(v)?[$(se(v)),$(ne(v))]:null,j=$(v.droplat||v.deliverylat),g=$(v.droplon||v.deliverylong);x&&Number.isFinite(j)&&Number.isFinite(g)&&(h=[x,[j,g]])}var N=ut?h||[]:ye(p),b="kitchens"===O||Ue,y=m||N;if(!(y.length<2)){var k=function(){return r.color};if(e&&r.id===ot.id){var S=p.filter(ee).map((function(e){return[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]})),_=m?ge(m,S):function(){for(var e=N.length>S.length,s=[],n=0;n<S.length;n++){var r=e?n:n-1,t=e?n+1:n;r<0||r>=N.length||t>=N.length?s.push([]):s.push([N[r],N[t]])}return s}(),w=[],F=0;_.forEach((function(e,s){for(var n=Math.max(0,((null===e||void 0===e?void 0:e.length)||0)-1),r=0;r<n;r++)w[F+r]=s;F+=n})),k=function(e){var n=w[e];if(null==n)return r.color;var t=p.filter(ee)[n],i=t?s.get(String(t.deliveryid)):null;return i?(0,z.di)(i-1):r.color}}for(var A=0;A<y.length-1;A++)n.push({from:y[A],to:y[A+1],color:k(A),delay:.05*(parseInt(r.id.slice(-3))||0)+40*parseInt(c)+A*(b?40:8)})}}}))}})),n.sort((function(e,s){return e.delay-s.delay})),n.forEach((function(e,s){setTimeout((function(){Pn((function(s){return[].concat((0,t.Z)(s),[e])})),s===n.length-1&&setTimeout((function(){Cn(!1),Zn({})}),1e3)}),e.delay)})),e&&St.length>0){var r=(0,t.Z)(St),i=r.map((function(e){var s=kn[e.deliveryid];return Array.isArray(s)&&s.length>=2?s:e.coords.map((function(e){return[e.lat,e.lng]}))})),a=n.length>0?n[n.length-1].delay:800*r.length,c=Math.max(a,600*r.length),d=c/Math.max(1,r.length),o=Date.now();requestAnimationFrame((function e(){if(qn.current){var s=Date.now()-o,n={};r.forEach((function(e,r){var t=i[r];if(t&&!(t.length<2)){var a=r*d;if(s>=a+d)n[e.sequenceStep]=t.length;else if(s>=a){var c=(s-a)/d;n[e.sequenceStep]=Math.max(2,Math.ceil(c*t.length))}}})),Zn(n),s<c+200&&requestAnimationFrame(e)}}))}},style:{boxShadow:"var(--shadow-lg)",background:An?"var(--accent)":"#fff"},children:[(0,P.jsx)("span",{children:An?"\u23f9":"\u25b6"})," ",An?"Stop":"Animate Routes"]})})]}),er&&ot&&(0,P.jsx)("div",{id:"compare-map-wrap",children:function(){var e=St.length,s=St.filter((function(e){return e.coords.length>0})).length,n=St.filter((function(e){return e.isLoading})).length,r=e>0?Math.round(s/e*100):0,t=e>0&&s===e&&0===n,i=null!=Mr?_t.find((function(e){return e.sequenceStep===Mr})):null;return(0,P.jsxs)("div",{className:"compare-header-v2",children:[(0,P.jsxs)("div",{className:"compare-header-row",children:[(0,P.jsxs)("div",{className:"compare-title",children:[(0,P.jsx)("span",{className:"compare-title-dot",style:{background:ot.color}}),(0,P.jsx)("span",{className:"compare-title-name",children:ot.riderName}),(0,P.jsx)("span",{className:"compare-title-badge",children:"ACTUAL vs PLANNED"})]}),(0,P.jsxs)("div",{className:"compare-header-tools",children:[null!=Mr&&(0,P.jsxs)("button",{type:"button",className:"compare-overall-btn",onClick:function(){return zr(null)},title:"Zoom out to the whole day",children:[(0,P.jsx)(E.zNX,{})," Overall"]}),(0,P.jsx)("button",{type:"button",className:"compare-timeline-toggle".concat(mr?" is-open":""),onClick:function(){return pr((function(e){return!e}))},title:mr?"Hide planned/actual timeline":"Show planned/actual timeline","aria-expanded":mr,children:(0,P.jsx)(E.Yc6,{})})]})]}),mr&&(0,P.jsxs)(P.Fragment,{children:[(0,P.jsxs)("div",{className:"compare-timeline-wrap",children:[(0,P.jsxs)("div",{className:"compare-timeline-container",children:[(0,P.jsxs)("div",{className:"compare-timeline-labels",children:[(0,P.jsx)("div",{className:"compare-timeline-label",children:"Planned"}),(0,P.jsx)("div",{className:"compare-timeline-label",children:"Actual"})]}),(0,P.jsxs)("div",{className:"compare-timeline-scrollable",children:[(0,P.jsx)("div",{className:"compare-timeline-track is-planned",children:Ft.map((function(e,s){var n,r=String(e.orderstatus||"").toLowerCase(),t=z.Q6.has(r),i=z.us.has(r),a=Mr===e.sequenceStep,c=e.isLoading&&0===e.coordsCount,l=!e.isLoading&&0===e.coordsCount,d=(null===(n=e.order)||void 0===n?void 0:n.step)||e.sequenceStep,o=(0,z.di)(d-1),m=["compare-step",a&&"is-focused",t&&"is-delivered",i&&"is-skipped",!t&&!i&&"is-pending",c&&"is-loading",l&&"is-no-data",e.anomaly&&"is-anomaly"].filter(Boolean).join(" ");return(0,P.jsxs)(u.Fragment,{children:[s>0&&(0,P.jsx)("span",{className:"compare-step-spacer"}),(0,P.jsxs)("button",{type:"button",className:m,style:{"--step-color":o},onClick:function(){return zr((function(s){return s===e.sequenceStep?null:e.sequenceStep}))},title:"Planned Step ".concat(d)+(e.deliverycustomer?" \xb7 ".concat(e.deliverycustomer):"")+(e.expectedTs?" \xb7 ".concat(e.expectedTs.format("hh:mm A")):"")+(e.anomaly?" \xb7 deviation flagged":""),children:[(0,P.jsx)("span",{className:"compare-step-circle",children:c?(0,P.jsx)("span",{className:"compare-step-spin"}):d}),e.expectedTs&&(0,P.jsx)("span",{className:"compare-step-tick",children:e.expectedTs.format("HH:mm")})]})]},"step-p-".concat(e.deliveryid))}))}),(0,P.jsx)("div",{className:"compare-timeline-track is-actual",children:At.map((function(e,s){var n,r=String(e.orderstatus||"").toLowerCase(),t=z.Q6.has(r),i=z.us.has(r),a=Mr===e.sequenceStep,c=e.isLoading&&0===e.coordsCount,l=!e.isLoading&&0===e.coordsCount,d=(null===(n=e.order)||void 0===n?void 0:n.step)||e.sequenceStep,o=(0,z.di)(d-1),m=["compare-step",a&&"is-focused",t&&"is-delivered",i&&"is-skipped",!t&&!i&&"is-pending",c&&"is-loading",l&&"is-no-data",e.anomaly&&"is-anomaly"].filter(Boolean).join(" ");return(0,P.jsxs)(u.Fragment,{children:[s>0&&(0,P.jsx)("span",{className:"compare-step-spacer"}),(0,P.jsxs)("button",{type:"button",className:m,style:{"--step-color":o},onClick:function(){return zr((function(s){return s===e.sequenceStep?null:e.sequenceStep}))},title:"Actual Visit ".concat(s+1," (Planned Step ").concat(d,")")+(e.deliverycustomer?" \xb7 ".concat(e.deliverycustomer):"")+(e.actualTs?" \xb7 ".concat(e.actualTs.format("hh:mm A")):"")+(e.anomaly?" \xb7 deviation flagged":""),children:[(0,P.jsx)("span",{className:"compare-step-circle",children:c?(0,P.jsx)("span",{className:"compare-step-spin"}):d}),e.actualTs&&(0,P.jsx)("span",{className:"compare-step-tick",children:e.actualTs.format("HH:mm")}),e.anomaly&&(0,P.jsx)("span",{className:"compare-step-flag",title:"Deviation flagged"})]})]},"step-a-".concat(e.deliveryid))}))})]})]}),(0,P.jsxs)("div",{className:"compare-progress-strip",children:[(0,P.jsx)("div",{className:"compare-progress-bar-wrap",children:(0,P.jsx)("div",{className:"compare-progress-bar-fill".concat(t?" is-done":""),style:{width:"".concat(r,"%")}})}),(0,P.jsx)("span",{className:"compare-progress-text",children:n>0?"Loading GPS\u2026 ".concat(s,"/").concat(e):"".concat(s,"/").concat(e," tracks")})]})]}),function(){var e="combined"===tr,s=i?(0,z.di)(i.sequenceStep-1):"linear-gradient(90deg, ".concat(z.XZ.slice(0,6).join(", "),")"),n=e?J:s,r=e?Q:s;return(0,P.jsxs)("div",{className:"compare-legend",children:[(0,P.jsxs)("span",{className:"compare-legend-item",children:[(0,P.jsx)("span",{className:"compare-legend-swatch is-step-color is-dashed",style:{background:n}}),"Planned (dashed)"]}),(0,P.jsxs)("span",{className:"compare-legend-item",children:[(0,P.jsx)("span",{className:"compare-legend-swatch is-step-color",style:{background:r}}),"Actual GPS (solid)"]}),(0,P.jsx)("span",{className:"compare-legend-note",children:"Kalman-smoothed GPS \xb7 OSRM road-snapped"})]})}()]})]})}()}),er&&ot&&(0,P.jsx)(R,{focusedRider:ot,compareDeltas:_t,compareSummary:wt,actualOrdered:At,focusedCompareStep:Mr,setFocusedCompareStep:zr,sequenceOpen:lr,setSequenceOpen:dr,expandedSeqGroups:fr,setExpandedSeqGroups:xr,onClose:function(){return sr(!1)}})]}),xs&&(0,P.jsx)("div",{className:"dispatch-popup-center",role:"dialog","aria-label":"Order ".concat(xs.orderid," details"),onMouseEnter:function(){hs.current&&(clearTimeout(hs.current),hs.current=null)},onMouseLeave:function(){(function(e){if(!e)return!1;if(us.current.has(String(e.orderid)))return!0;if(er&&ot&&null!=e.deliveryid){var s=St.find((function(s){return String(s.deliveryid)===String(e.deliveryid)}));if(s&&Mr===s.sequenceStep)return!0}return!1})(xs)||(hs.current&&clearTimeout(hs.current),hs.current=setTimeout((function(){js(null),hs.current=null}),200))},children:(0,P.jsxs)("div",{className:"dispatch-popup-card dispatch-popup",children:[(0,P.jsx)("button",{type:"button",className:"dispatch-popup-center-close","aria-label":"Close order details",onClick:function(){us.current.delete(String(xs.orderid)),js(null)},children:"\xd7"}),function(e){var s=(0,z.Cl)(e.orderstatus),n=e.rider_id||e.userid,r=z.Q6.has(String(e.orderstatus||"").toLowerCase())?null:Lt(n,e);return(0,P.jsxs)("div",{style:{height:"100%",width:"100%"},children:[(0,P.jsxs)("div",{className:"pu-header",children:[(0,P.jsxs)("div",{className:"pu-header-top",children:[(0,P.jsxs)("div",{className:"pu-id",children:["ORDER #",e.orderid]}),e.orderstatus&&(0,P.jsx)("span",{className:"pu-status-chip",style:{background:s.bg,color:s.fg},children:s.label})]}),(0,P.jsxs)("div",{className:"pu-rider",children:[(0,P.jsx)(E.pbk,{})," ",(0,P.jsx)("span",{children:e.rider_name||e.ridername||"Unassigned"})]}),(e.deliverycustomer||e.customername)&&(0,P.jsxs)("div",{className:"pu-customer",title:e.deliverycustomer||e.customername,children:[(0,P.jsx)(E.Vyx,{})," ",(0,P.jsx)("span",{children:e.deliverycustomer||e.customername})]}),null!=e.deliveryid&&(0,P.jsxs)("div",{className:"pu-delivery-id",children:["Delivery #",e.deliveryid]})]}),(0,P.jsxs)("div",{className:"pu-body",children:[be.some((function(s){return e[s.key]}))&&(0,P.jsxs)("div",{className:"pu-section",children:[(0,P.jsx)("div",{className:"pu-section-label",children:"Timeline"}),(0,P.jsx)("div",{className:"pu-timeline",children:be.map((function(s){var n=Ne(e[s.key]);return n?(0,P.jsxs)("div",{className:"pu-tl-row ".concat(s.final?"delivered":""),children:[(0,P.jsx)("span",{className:"pu-tl-dot"}),(0,P.jsx)("span",{className:"pu-tl-label",children:s.label}),(0,P.jsx)("span",{className:"pu-tl-time",children:n})]},s.key):null}))})]}),(0,P.jsxs)("div",{className:"pu-section",children:[(0,P.jsx)("div",{className:"pu-section-label",children:"Details"}),(0,P.jsxs)("div",{className:"pu-details-grid",children:[(e.pickupcustomer||e.locationname||e.pickuplocation)&&(0,P.jsxs)("div",{className:"pu-detail",children:[(0,P.jsx)("div",{className:"pu-detail-icon",children:(0,P.jsx)(E.TkG,{})}),(0,P.jsxs)("div",{className:"pu-detail-body",children:[(0,P.jsx)("div",{className:"pu-detail-label",children:"Pickup"}),(0,P.jsx)("div",{className:"pu-detail-value",title:e.pickupcustomer||e.locationname||e.pickuplocation,children:e.pickupcustomer||e.locationname||e.pickuplocation})]})]}),(e.deliverysuburb||e.deliveryaddress)&&(0,P.jsxs)("div",{className:"pu-detail",children:[(0,P.jsx)("div",{className:"pu-detail-icon",children:(0,P.jsx)(E.c7Z,{})}),(0,P.jsxs)("div",{className:"pu-detail-body",children:[(0,P.jsx)("div",{className:"pu-detail-label",children:"Drop"}),(0,P.jsx)("div",{className:"pu-detail-value",title:e.deliveryaddress||e.deliverysuburb,children:e.deliverysuburb||X(e.deliveryaddress)})]})]}),e.zone_name&&(0,P.jsxs)("div",{className:"pu-detail",children:[(0,P.jsx)("div",{className:"pu-detail-icon",children:(0,P.jsx)(E.PKO,{})}),(0,P.jsxs)("div",{className:"pu-detail-body",children:[(0,P.jsx)("div",{className:"pu-detail-label",children:"Zone"}),(0,P.jsx)("div",{className:"pu-detail-value",title:e.zone_name,children:e.zone_name})]})]}),(e.rider_id||e.userid)&&(0,P.jsxs)("div",{className:"pu-detail",children:[(0,P.jsx)("div",{className:"pu-detail-icon",children:(0,P.jsx)(E.pbk,{})}),(0,P.jsxs)("div",{className:"pu-detail-body",children:[(0,P.jsx)("div",{className:"pu-detail-label",children:"Rider ID"}),(0,P.jsxs)("div",{className:"pu-detail-value",children:["#",e.rider_id||e.userid]})]})]}),null!=e.step&&(0,P.jsxs)("div",{className:"pu-detail",children:[(0,P.jsx)("div",{className:"pu-detail-icon",children:(0,P.jsx)(E.x$F,{})}),(0,P.jsxs)("div",{className:"pu-detail-body",children:[(0,P.jsx)("div",{className:"pu-detail-label",children:"Step"}),(0,P.jsxs)("div",{className:"pu-detail-value",children:[null!=e.trip_number&&e.trip_number>1?"Trip ".concat(e.trip_number," \xb7 "):"","#",e.step]})]})]})]}),(null!=e.actualkms||null!=e.riderkms||null!==r)&&(0,P.jsxs)("div",{className:"pu-distance-row",children:[null!=e.actualkms&&""!==e.actualkms&&(0,P.jsxs)("div",{className:"pu-distance-chip",children:[(0,P.jsx)("span",{className:"pu-distance-icon",children:(0,P.jsx)(E.v93,{})}),(0,P.jsx)("span",{className:"pu-distance-label",children:"Actual"}),(0,P.jsxs)("span",{className:"pu-distance-value",children:[e.actualkms," km"]})]}),null!=e.riderkms&&""!==e.riderkms&&(0,P.jsxs)("div",{className:"pu-distance-chip",children:[(0,P.jsx)("span",{className:"pu-distance-icon",children:(0,P.jsx)(E.MCF,{})}),(0,P.jsx)("span",{className:"pu-distance-label",children:"Rider"}),(0,P.jsxs)("span",{className:"pu-distance-value",children:[parseFloat(e.riderkms).toFixed(2)," km"]})]}),null!==r&&(0,P.jsxs)("div",{className:"pu-distance-chip pu-est-meters",title:"Estimated distance to drop location",children:[(0,P.jsx)("span",{className:"pu-distance-icon",children:(0,P.jsx)(E.x$F,{})}),(0,P.jsx)("span",{className:"pu-distance-label",children:"Est. to Drop"}),(0,P.jsx)("span",{className:"pu-distance-value",children:Dt(r)})]})]})]})]})]})}(xs)]})})]}),!m&&"analysis"===K&&(0,P.jsxs)("div",{id:"dispatch-analysis",children:[(0,P.jsx)("div",{className:"da-picker-row",children:Ae.map((function(e){var s,n=G[e.key],r=pe===e.key,t=!1===(null===n||void 0===n||null===(s=n.data)||void 0===s?void 0:s.success),i=t?"#fee2e2":n?"".concat(e.color,"22"):"#f1f5f9",a=t?"#dc2626":n?e.color:"#64748b",c=r?"Loading\u2026":t?"! Failed":n?"\u2713 ".concat(n.fetchedAt):"Fetch",l=Pe===e.key;return(0,P.jsxs)("button",{type:"button",className:"da-picker ".concat(n?"has-data":""," ").concat(r?"is-loading":""," ").concat(l?"is-active":""),onClick:function(){return!r&&De(e.key)},style:{borderColor:l?e.color:t?"#fecaca":n?e.border:"#e2e8f0",background:t?"#fef2f2":n?e.bg:"#ffffff",boxShadow:l?"0 0 0 2px ".concat(e.color,"33"):void 0},disabled:r,children:[(0,P.jsxs)("div",{className:"da-picker-head",children:[(0,P.jsx)("div",{className:"da-picker-badge",style:{background:"".concat(e.color,"22"),color:e.color},children:e.label[0]}),(0,P.jsxs)("div",{className:"da-picker-meta",children:[(0,P.jsx)("div",{className:"da-picker-name",children:e.label}),(0,P.jsx)("div",{className:"da-picker-range",children:e.timeRange})]}),(0,P.jsx)("span",{className:"da-picker-status",style:{background:i,color:a},children:c})]}),(0,P.jsx)("div",{className:"da-picker-sub",children:e.sub})]},e.key)}))}),function(){var e,s,n,r;if(!Pe)return(0,P.jsx)("div",{className:"da-empty",children:"Pick a batch above to view its efficiency analysis."});var t=Ae.find((function(e){return e.key===Pe})),i=G[Pe],a=pe===Pe;if(a&&!i)return(0,P.jsxs)("div",{className:"da-empty",children:["Loading ",t.label," batch\u2026"]});if(!i)return null;var c,l,d=i.data||{};if(!1===d.success)return(0,P.jsxs)("div",{className:"da-result-card da-result-card-error",style:{borderColor:"#fecaca",borderTopColor:"#ef4444"},children:[(0,P.jsxs)("div",{className:"da-result-head",children:[(0,P.jsxs)("div",{children:[(0,P.jsxs)("div",{className:"da-result-title",children:[t.label," Batch"]}),(0,P.jsxs)("div",{className:"da-result-sub",children:[t.timeRange," \xb7 Fetched at ",i.fetchedAt]})]}),(0,P.jsx)("button",{type:"button",className:"da-result-refresh",title:"Retry",onClick:function(){return De(Pe)},disabled:a,style:{background:"#fee2e2",color:"#dc2626"},children:(0,P.jsx)(E.la_,{})})]}),(0,P.jsxs)("div",{className:"da-error",children:[(0,P.jsxs)("div",{className:"da-error-title",children:[(0,P.jsx)(E.wr$,{}),(0,P.jsx)("span",{children:(null===d||void 0===d||null===(c=d.error)||void 0===c?void 0:c.code)||"Request failed"})]}),(0,P.jsx)("div",{className:"da-error-msg",children:(null===d||void 0===d||null===(l=d.error)||void 0===l?void 0:l.message)||"The server returned an error."}),(null===d||void 0===d?void 0:d.request_id)&&(0,P.jsxs)("div",{className:"da-error-meta",children:["request_id: ",d.request_id]})]})]});var u=d.fleet_summary||{},m=Array.isArray(d.rider_timelines)?d.rider_timelines:[],p=Array.isArray(d.substitution_opportunities)?d.substitution_opportunities:[],h=d.top_recommendation,v=!(!h||!h.idle_rider_name&&!h.idle_rider_id),f=!!(h&&h.action&&"none"!==h.action&&v),x=d.window||{},j=[{label:"Total Orders",value:Ce(u.total_orders)},{label:"Total Riders",value:Ce(u.total_riders)},{label:"Avg Orders/Rider",value:null!==(e=u.orders_per_rider_avg)&&void 0!==e?e:"\u2014"},{label:"Fleet Start",value:u.fleet_start||"\u2014"},{label:"Fleet Done",value:u.fleet_done||"\u2014"},{label:"Duration",value:null!=u.total_duration_minutes?"".concat(u.total_duration_minutes," min"):"\u2014"}];return(0,P.jsxs)("div",{className:"da-detail",children:[(0,P.jsxs)("div",{className:"da-detail-head",style:{borderTopColor:t.color,background:t.bg},children:[(0,P.jsxs)("div",{children:[(0,P.jsxs)("div",{className:"da-detail-title",children:[t.label," Batch",(0,P.jsxs)("span",{className:"da-detail-sub-inline",children:[d.date?" \xb7 ".concat(d.date):"",x.from&&x.to?" \xb7 ".concat(x.from," \u2013 ").concat(x.to):""]})]}),(0,P.jsxs)("div",{className:"da-detail-sub",children:["Fetched at ",i.fetchedAt," \xb7 Input deliveries: ",null!==(s=d.input_delivery_count)&&void 0!==s?s:"\u2014"]})]}),(0,P.jsx)("button",{type:"button",className:"da-result-refresh",title:"Refresh",onClick:function(){U((function(e){var s=(0,o.Z)({},e);return delete s[Pe],s})),Le.mutate({batch:Pe,tenantId:916})},disabled:a,style:{background:"".concat(t.color,"22"),color:t.color},children:(0,P.jsx)(E.la_,{})})]}),(0,P.jsxs)("div",{className:"da-section",children:[(0,P.jsx)("div",{className:"da-section-label",children:"Fleet Summary"}),(0,P.jsx)("div",{className:"da-metric-grid da-metric-grid-3",children:j.map((function(e){return(0,P.jsxs)("div",{className:"da-metric",children:[(0,P.jsx)("div",{className:"da-metric-label",children:e.label}),(0,P.jsx)("div",{className:"da-metric-value",children:e.value})]},e.label)}))})]}),f?(0,P.jsxs)("div",{className:"da-section",children:[(0,P.jsx)("div",{className:"da-section-label",children:"Top Recommendation"}),(0,P.jsxs)("div",{className:"da-rec",children:[(0,P.jsxs)("div",{className:"da-rec-head",children:[(0,P.jsxs)("div",{className:"da-rec-action",children:[(0,P.jsx)(E.YgO,{}),(0,P.jsx)("span",{children:(h.action||"recommendation").replaceAll("_"," ")})]}),null!=h.fleet_improvement_minutes&&(0,P.jsxs)("span",{className:"da-rec-improve",style:h.fleet_improvement_minutes>0?{background:"#dcfce7",color:"#166534"}:{background:"#f1f5f9",color:"#475569"},children:[h.fleet_improvement_minutes>0?"\u2191":"\u2022"," Fleet improves by ",h.fleet_improvement_minutes," min"]})]}),(0,P.jsxs)("div",{className:"da-rec-line",children:[(0,P.jsx)("strong",{children:h.idle_rider_name||"Rider ".concat(h.idle_rider_id)}),h.primary_kitchen&&(0,P.jsxs)(P.Fragment,{children:[" \xb7 primary kitchen ",(0,P.jsx)("strong",{children:h.primary_kitchen})]}),h.second_kitchen&&(0,P.jsxs)(P.Fragment,{children:[" \u2192 also serve ",(0,P.jsx)("strong",{children:h.second_kitchen})," after ",h.second_kitchen_dispatch_after||"\u2014"]})]}),h.description&&(0,P.jsx)("div",{className:"da-rec-desc",children:h.description}),(null===(n=h.activate_when)||void 0===n||null===(r=n.rules)||void 0===r?void 0:r.length)>0&&(0,P.jsxs)("div",{className:"da-rec-rules",children:[(0,P.jsxs)("div",{className:"da-rec-rules-head",children:["Activate when (",h.activate_when.condition||"AND","):"]}),h.activate_when.rules.map((function(e,s){return(0,P.jsxs)("div",{className:"da-rec-rule",children:[(0,P.jsxs)("code",{children:[e.field," ",e.operator," ",e.value]}),e.reason&&(0,P.jsxs)("span",{className:"da-rec-rule-why",children:[" \u2014 ",e.reason]})]},s)}))]})]})]}):(0,P.jsxs)("div",{className:"da-section",children:[(0,P.jsx)("div",{className:"da-section-label",children:"Top Recommendation"}),(0,P.jsx)("div",{className:"da-rec da-rec-empty",children:(0,P.jsxs)("div",{className:"da-rec-action",children:[(0,P.jsx)(E.YgO,{}),(0,P.jsx)("span",{children:"Fleet is balanced, no reassignment needed right now."})]})})]}),m.length>0&&(0,P.jsxs)("div",{className:"da-section",children:[(0,P.jsxs)("div",{className:"da-section-label",children:["Rider Timelines ",(0,P.jsxs)("span",{className:"da-section-count",children:["(",m.length,")"]})]}),(0,P.jsx)("div",{className:"da-timeline-list",children:m.map((function(e){var s="active"===String(e.status||"").toLowerCase();return(0,P.jsxs)("div",{className:"da-timeline-card",children:[(0,P.jsxs)("div",{className:"da-timeline-top",children:[(0,P.jsxs)("div",{className:"da-timeline-name",children:[(0,P.jsx)(E.pbk,{style:{color:t.color}}),(0,P.jsx)("span",{children:e.name}),(0,P.jsxs)("span",{className:"da-timeline-id",children:["#",e.userid]})]}),(0,P.jsx)("span",{className:"da-pill ".concat(s?"is-active":"is-idle"),children:e.status})]}),(0,P.jsxs)("div",{className:"da-timeline-mid",children:[e.kitchen&&(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(E.TkG,{})," ",e.kitchen]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(E.ByW,{})," ",e.order_count," orders"]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(E.dKE,{})," ",e.started_at," \u2192 ",e.finished_at]}),(0,P.jsxs)("span",{className:"da-chip",style:e.idle_minutes>30?{background:"#fef3c7",color:"#92400e"}:void 0,children:[(0,P.jsx)(E.Vqd,{})," ",e.idle_minutes," min idle"]})]})]},e.userid)}))})]}),p.length>0&&(0,P.jsxs)("div",{className:"da-section",children:[(0,P.jsxs)("div",{className:"da-section-label",children:["Substitution Opportunities ",(0,P.jsxs)("span",{className:"da-section-count",children:["(",p.length,")"]})]}),(0,P.jsx)("div",{className:"da-sub-list",children:p.map((function(e,s){var n,r=e.idle_rider||{},t=e.most_relieved_rider||{},i=null!==(n=e.fleet_improvement_minutes)&&void 0!==n?n:0;return(0,P.jsxs)("div",{className:"da-sub-card",children:[(0,P.jsxs)("div",{className:"da-sub-head",children:[(0,P.jsxs)("div",{className:"da-sub-title",children:[(0,P.jsx)("strong",{children:r.name||"Rider ".concat(r.userid)})," ","covers ",(0,P.jsx)("strong",{children:e.target_kitchen})]}),(0,P.jsxs)("span",{className:"da-sub-improve",style:i>0?{background:"#dcfce7",color:"#166534"}:{background:"#f1f5f9",color:"#475569"},children:["Fleet ",i>0?"\u2191":"\u2022"," ",i," min"]})]}),(0,P.jsxs)("div",{className:"da-sub-meta",children:[(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(E.v93,{})," ",e.travel_to_kitchen_km," km"]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(E.Vqd,{})," ",e.travel_to_kitchen_minutes," min travel"]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(E.dKE,{})," arrives ",e.arrive_at_kitchen]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(E.ByW,{})," ",e.total_orders_transferred," orders"]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(E.v93,{})," +",e.extra_km_for_idle_rider," km for idle rider"]})]}),t.name&&(0,P.jsxs)("div",{className:"da-sub-relieved",children:[(0,P.jsx)(E.gSd,{}),"Most relieved: ",(0,P.jsx)("strong",{children:t.name})," ","(",t.original_finish," \u2192 ",t.new_finish,", saves"," ",t.time_saved_minutes," min)"]}),Array.isArray(e.orders_to_transfer)&&e.orders_to_transfer.length>0&&(0,P.jsxs)("div",{className:"da-sub-transfers",children:[(0,P.jsx)("div",{className:"da-sub-transfers-head",children:"Orders transferred"}),e.orders_to_transfer.map((function(e){var s,n=null!==(s=e.improvement_minutes)&&void 0!==s?s:0;return(0,P.jsxs)("div",{className:"da-transfer-row",children:[(0,P.jsxs)("span",{className:"da-transfer-id",children:["#",e.deliveryid]}),(0,P.jsxs)("span",{className:"da-transfer-from",children:["from ",e.from_rider_name]}),(0,P.jsxs)("span",{className:"da-transfer-time",children:[e.original_delivery_time," \u2192 ",e.estimated_delivery_time]}),(0,P.jsxs)("span",{className:"da-transfer-imp",style:n>0?{background:"#dcfce7",color:"#166534"}:n<0?{background:"#fee2e2",color:"#991b1b"}:{background:"#f1f5f9",color:"#475569"},children:[n>0?"+":"",n," min"]})]},e.deliveryid)}))]})]},s)}))})]})]})}()]})]})}},29127:function(e,s,n){n.d(s,{Cl:function(){return i},P0:function(){return d},Q6:function(){return a},XZ:function(){return o},di:function(){return u},us:function(){return c},xw:function(){return m}});var r=n(93433),t={created:{label:"Created",bg:"#3b82f6",fg:"#fff"},pending:{label:"Pending",bg:"#f59e0b",fg:"#fff"},accepted:{label:"Accepted",bg:"#8b5cf6",fg:"#fff"},arrived:{label:"Arrived",bg:"#ea580c",fg:"#fff"},picked:{label:"Picked",bg:"#0ea5e9",fg:"#fff"},active:{label:"Active",bg:"#0ea5e9",fg:"#fff"},delivered:{label:"Delivered",bg:"#22c55e",fg:"#fff"},skipped:{label:"Skipped",bg:"#94a3b8",fg:"#fff"},cancelled:{label:"Cancelled",bg:"#ef4444",fg:"#fff"}},i=function(e){return t[String(e||"").toLowerCase()]||{label:e||"Unknown",bg:"#64748b",fg:"#fff"}},a=new Set(["delivered"]),c=new Set(["cancelled","skipped"]),l=function(e){return"active"===String((null===e||void 0===e?void 0:e.orderstatus)||"").toLowerCase()},d=function(e){return Array.isArray(e)&&e.length&&(0,r.Z)(e).sort((function(e,s){var n=e.trip_number||1,r=s.trip_number||1;return n!==r?n-r:(e.step||0)-(s.step||0)})).find(l)||null},o=["#2563eb","#dc2626","#16a34a","#ea580c","#9333ea","#0891b2","#ca8a04","#db2777","#0f766e","#7c3aed","#65a30d","#0284c7","#b91c1c","#15803d","#a16207","#86198f"],u=function(e){return o[(e%o.length+o.length)%o.length]},m=function(e){if(null==e)return"";var s=["th","st","nd","rd"],n=e%100;return e+(s[(n-20)%10]||s[n]||s[0])}}}]);