1 line
152 KiB
JavaScript
1 line
152 KiB
JavaScript
"use strict";(self.webpackChunkmantis_material_react=self.webpackChunkmantis_material_react||[]).push([[9436],{23447:function(e,n,s){s.r(n),s.d(n,{default:function(){return Ce}});var r=s(45987),t=s(93433),a=s(74165),i=s(15861),c=s(4942),l=s(29439),d=s(37762),o=s(1413),u=s(47313),m=s(84536),p=s(39062),h=s(98817),v=s(74580),f=s(88153),x=s(73999),j=s(93854),g=s(45158),N=s(87248),b=s.n(N);s(63331);b().PolylineOffset={translatePoint:function(e,n,s){return b().point(e.x+n*Math.cos(s),e.y+n*Math.sin(s))},offsetPointLine:function(e,n){var s=e.length;if(s<2)throw new Error("Line should be defined by at least 2 points");for(var r,t=e[0],a=Math.PI/2,i=[],c=1;c<s;c++){r=e[c];var l=Math.atan2(r.y-t.y,r.x-t.x);i.push({offsetAngle:l-a,original:[t,r],offset:[this.translatePoint(t,n,l-a),this.translatePoint(r,n,l-a)]}),t=r}return i},intersection:function(e,n,s,r){var t=this.segmentAsVector(e,n),a=this.segmentAsVector(s,r),i=-a.x*t.y+t.x*a.y;if(0===i)return null;var c=(-t.y*(e.x-s.x)+t.x*(e.y-s.y))/i,l=(a.x*(e.y-s.y)-a.y*(e.x-s.x))/i;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,n){return b().point(n.x-e.x,n.y-e.y)},joinLineSegments:function(e){var n=[],s=e[0].offset;n.push(s[0]);for(var r=1;r<e.length;r++){var t=e[r].offset,a=this.intersection(s[0],s[1],t[0],t[1]);a?n.push(a):n.push(s[1]),s=t}return n.push(s[1]),n},offsetPoints:function(e,n){if(!e||e.length<2)return e;var s=this.offsetPointLine(e,n);return this.joinLineSegments(s)},offsetLatLngs:function(e,n,s){var r=n.map((function(n){return e.latLngToLayerPoint(n)}));return this.offsetPoints(r,s).map((function(n){return e.layerPointToLatLng(n)}))}};var y=b().Polyline.prototype._projectLatlngs;b().Polyline.prototype._projectLatlngs=function(e,n,s){var r=this,t=this.options.offset;if(!t||"number"!==typeof t)return y.call(this,e,n,s);if(e[0]instanceof b().LatLng){for(var a=e.map((function(e){return r._map.latLngToLayerPoint(e)})),i=b().PolylineOffset.offsetPoints(a,t),c=0;c<i.length;c++)s.extend(i[c]);n.push(i)}else for(var l=0;l<e.length;l++)this._projectLatlngs(e[l],n,s)};var k=s(10658),S=s.n(k),_=s(50581),w=s(41962),F=s(25963),A=s(71559),E=s(56573),C=s(22539),M=s(71049),z=s(29127),P=s(46417);var R=function(e){var n=e.focusedRider,s=e.compareDeltas,r=e.compareSummary,t=e.actualOrdered,a=e.focusedCompareStep,i=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,a=e.onTime+e.late,i=s.filter((function(e){return e.anomaly})),c=s.filter((function(e){return z.Q6.has(String(e.orderstatus||"").toLowerCase())})).length,d=s.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=s.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=s.filter((function(e){return e.actualTs})),x=f.reduce((function(e,n){return!e||n.actualTs.isBefore(e)?n.actualTs:e}),null),j=f.reduce((function(e,n){return!e||n.actualTs.isAfter(e)?n.actualTs:e}),null),g=x&&j?Math.max(0,j.diff(x,"minute")):0,N=s.length>1?Math.round(g/(s.length-1)):0,b=g>0?(e.actualKm/(g/60)).toFixed(1):null,y=s.filter((function(e){return!e.isLoading&&e.coordsCount>0})),k=y.filter((function(e){return null!=e.timeDeltaMin&&!e.anomaly})).sort((function(e,n){return e.timeDeltaMin-n.timeDeltaMin}))[0]||null,S=y.filter((function(e){return e.anomaly})).sort((function(e,n){var s=Math.abs(e.kmDeltaPct||0)+(e.timeDeltaMin>0?e.timeDeltaMin:0);return Math.abs(n.kmDeltaPct||0)+(n.timeDeltaMin>0?n.timeDeltaMin:0)-s}))[0]||null,_=t.filter((function(e,n){var s,r=null===(s=e.order)||void 0===s?void 0:s.step;return null!=r&&r!==n+1})),w=[];_.forEach((function(e){var n,s=null===(n=e.order)||void 0===n?void 0:n.step,r=t.findIndex((function(n){return n.sequenceStep===e.sequenceStep}))+1,a=r-s,i=w[w.length-1];i&&i.delta===a&&i.lastActualPos+1===r?(i.items.push({d:e,planned:s,actualPos:r,delta:a}),i.lastActualPos=r):w.push({delta:a,items:[{d:e,planned:s,actualPos:r,delta:a}],lastActualPos:r})}));var F={};n.orders.forEach((function(e){var n=e.trip_number||1;F[n]||(F[n]=[]),F[n].push(e)}));var A=Object.entries(F).sort((function(e,n){var s=(0,l.Z)(e,1)[0],r=(0,l.Z)(n,1)[0];return Number(s)-Number(r)})).map((function(e){var n=(0,l.Z)(e,2),s=n[0],r=n[1];return{tNum:s,count:r.length,actualKm:r.reduce((function(e,n){return e+parseFloat(n.actualkms||n.kms||0)}),0),delivered:r.filter((function(e){return z.Q6.has(String(e.orderstatus||"").toLowerCase())})).length}}));return{sum:e,totalSteps:a,deviations:i,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}}),[n,s,r,t]),v=null!=a?s.find((function(e){return e.sequenceStep===a})):null,f=function(e){i((function(n){return n===e?null:e}))},x=function(e){var n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1],s=e.d,r=e.planned,t=e.actualPos,i=e.delta;return(0,P.jsxs)("li",{className:"cdp-seq-diff".concat(a===s.sequenceStep?" is-focused":"").concat(n?"":" is-nested"),onClick:function(){return f(s.sequenceStep)},children:[(0,P.jsx)("span",{className:"cdp-seq-diff-num",style:{background:(0,z.di)((r||s.sequenceStep)-1)},children:r||s.sequenceStep}),(0,P.jsxs)("div",{className:"cdp-seq-diff-body",children:[(0,P.jsx)("div",{className:"cdp-seq-diff-title",children:s.deliverycustomer||"Step ".concat(r||s.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:i>0?"+".concat(i):"".concat(i)})]},"diff-".concat(s.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,E=h.activeMin,M=h.avgPerStop,R=h.avgSpeed,L=h.bestStep,D=h.worstStep,Z=h.outOfOrderSteps,O=h.seqRuns,q=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:n.color}}),(0,P.jsxs)("div",{className:"cdp-head-text",children:[(0,P.jsx)("div",{className:"cdp-rider-name",children:n.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)(C.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,"/",s.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)(C.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)(C.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)(C.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)(C.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"})]})]})]}),s.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)(C.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)(C.Yc6,{})})]}),c&&(0,P.jsx)("div",{className:"cdp-seq",children:Z.length>0?(0,P.jsx)("ul",{className:"cdp-seq-diffs",children:O.map((function(e,n){if(1===e.items.length)return x(e.items[0]);var s=e.items[0],r=e.items[e.items.length-1],t=o.has(n),i=e.delta>0?"+".concat(e.delta):"".concat(e.delta),c=e.items.some((function(e){return e.d.sequenceStep===a}));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=n,void m((function(n){var s=new Set(n);return s.has(e)?s.delete(e):s.add(e),s}));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)((s.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:i})]}),(0,P.jsxs)("div",{className:"cdp-seq-diff-sub",children:["Planned ",(0,z.xw)(s.planned),"\u2013",(0,z.xw)(r.planned)," ","visited"," ",(0,P.jsxs)("strong",{children:[(0,z.xw)(s.actualPos),"\u2013",(0,z.xw)(r.actualPos)]})]})]}),(0,P.jsx)("span",{className:"cdp-seq-diff-tag",children:i}),(0,P.jsx)("span",{className:"cdp-seq-group-toggle".concat(t?" is-open":""),"aria-hidden":"true",children:(0,P.jsx)(C.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(n,"-").concat(s.d.sequenceStep))}))}):(0,P.jsxs)("div",{className:"cdp-seq-good",children:[(0,P.jsx)(C.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)(C.Vqd,{})}),(0,P.jsx)("span",{className:"cdp-section-title",children:"Timing"}),E>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)(C.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)(C.TSC,{})}),(0,P.jsx)("span",{className:"cdp-clock-duration-val",children:E>0?E>=60?"".concat(Math.floor(E/60),"h ").concat(E%60,"m"):"".concat(E,"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)(C.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)(C.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"})]})]}),s.length>0&&(0,P.jsxs)("div",{className:"cdp-timing-stat-viz cdp-stops-dots","aria-hidden":"true",children:[Array.from({length:Math.min(s.length,12)}).map((function(e,n){return(0,P.jsx)("span",{className:"cdp-stop-dot"},"dot-".concat(n))})),(0,P.jsxs)("span",{className:"cdp-timing-stat-viz-label",children:[s.length," stop",1===s.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)(C.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)(C.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)(C.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)(C.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"]})]})]})]})]})]}),q.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)(C.x82,{})}),(0,P.jsxs)("span",{className:"cdp-section-title",children:["Trips (",q.length,")"]})]}),(0,P.jsx)("div",{className:"cdp-trips",children:q.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)(C.v93,{}),e.actualKm.toFixed(1),"km"]})})]},"trip-".concat(e.tNum))}))})]}),v&&function(){var e=(0,z.di)(v.sequenceStep-1),n=null!=v.timeDeltaMin?v.timeDeltaMin>10?"is-over":v.timeDeltaMin<-2?"is-under":"":"",s=(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)(C.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 i(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:s.bg,color:s.fg},children:s.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(n),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)(C.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 n=(0,z.di)(e.sequenceStep-1),s=e.kmDelta>=0?"+":"";return(0,P.jsxs)("li",{className:"cdp-dev-item".concat(a===e.sequenceStep?" is-focused":""),onClick:function(){return f(e.sequenceStep)},children:[(0,P.jsx)("span",{className:"cdp-dev-num",style:{background:n},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:[s,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)(C.f_H,{})}),(0,P.jsxs)("span",{className:"cdp-section-title",children:["Steps (",s.length,")"]}),(0,P.jsxs)("span",{className:"cdp-section-sub",children:[b,"/",s.length," delivered"]})]}),(0,P.jsx)("ul",{className:"cdp-step-list",children:s.map((function(e){var n=(0,z.di)(e.sequenceStep-1),s=String(e.orderstatus||"").toLowerCase(),r=z.Q6.has(s),t=z.us.has(s),i=r&&!e.anomaly,c=a===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":"",i?"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:n},children:[e.sequenceStep,i&&(0,P.jsx)("span",{className:"cdp-step-check",children:(0,P.jsx)(C.ZSR,{})}),e.anomaly&&(0,P.jsx)("span",{className:"cdp-step-flag",children:(0,P.jsx)(C.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)(C.v93,{}),e.actualKm.toFixed(1),"km"]}),(0,P.jsxs)("span",{className:"cdp-step-delta ".concat(d),title:"Delivery time",children:[(0,P.jsx)(C.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=s(85281),D=s(62180),Z=function(e){var n=e.visibleRiders,s=e.riders,r=e.resetKey,t=e.focusedStop,a=e.handleRiderFocus,i=e.setFocusedStop,c=e.calculateEstMeters,d=e.getRiderColor,o=e.formatMeters,m=e.isLoading,p=n.map((function(e){return(0,z.P0)(e.orders)})).filter(Boolean).sort((function(e,n){var s,r;return(null!==(s=c(e.rider_id||e.userid,e))&&void 0!==s?s:1/0)-(null!==(r=c(n.rider_id||n.userid,n))&&void 0!==r?r:1/0)})),h=(0,u.useRef)(null),v=(0,u.useRef)(r);if((0,u.useEffect)((function(){var e={};n.forEach((function(n){(n.orders||[]).forEach((function(n){e[String(n.orderid)]={status:String(n.orderstatus||"").toLowerCase(),riderName:n.rider_name||n.ridername||"Rider",customer:n.deliverycustomer||n.customername||"Order #".concat(n.orderid)}}))}));var s=v.current!==r,t=h.current;null===t||s||Object.entries(e).forEach((function(e){var n=(0,l.Z)(e,2),s=n[0],r=n[1],a=t[s];a?("active"!==a.status&&"active"===r.status&&(0,D.y)("\ud83d\udef5 ".concat(r.riderName," is now delivering to ").concat(r.customer),"success",3e3),"active"===a.status&&"delivered"===r.status&&(0,D.y)("\ud83d\udccd ".concat(r.riderName," has reached ").concat(r.customer,"'s location"),"info",3e3)):"active"===r.status&&(0,D.y)("\ud83d\udef5 ".concat(r.riderName," is now delivering to ").concat(r.customer),"success",3e3)})),h.current=e,v.current=r}),[n,r]),m)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===p.length)return(0,P.jsxs)("div",{className:"empty-slot",children:[(0,P.jsx)("div",{className:"empty-slot-icon",children:(0,P.jsx)(C.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:p.map((function(e,n){var r=e.rider_id||e.userid,l=s.find((function(e){return String(e.id)===String(r)})),u=d(r),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=c(r,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&&t&&String(t.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(){l&&a(l),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)(C.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)(C.$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)(C.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)(C.x$F,{})}),o(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)(C.dKE,{})}),function(){var e=f/1e3/20*60;return e<1?"< 1 min":"".concat(Math.ceil(e)," min")}()]})]})})]})]},e.orderid)}))})},O=s(84506),q={DEBUG:0,INFO:1,WARN:2,ERROR:3},T=q.WARN,I=function(e,n){return"background: ".concat(e,"; color: ").concat(n,"; 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,n,s){if(!(q[e]<T)){var r=(0,O.Z)(n),a=r[0],i=r.slice(1),c="string"===typeof a,l="".concat("%c[NearlExpress]","%c ").concat(e),d=[H,s],o="ERROR"===e?Y:"WARN"===e?B:K;c?o.apply(void 0,["".concat(l,"%c ").concat(a)].concat(d,["color: inherit;"],(0,t.Z)(i))):o.apply(void 0,["".concat(l)].concat(d,[a],(0,t.Z)(i)))}},U={debug:function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];return G("DEBUG",n,I("#64748b","#ffffff"))},info:function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];return G("INFO",n,I("#10b981","#ffffff"))},warn:function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];return G("WARN",n,I("#f59e0b","#ffffff"))},error:function(){for(var e=arguments.length,n=new Array(e),s=0;s<e;s++)n[s]=arguments[s];G("ERROR",n,I("#ef4444","#ffffff"))}},V=U,W=["_ts"],J="#6366f1",Q="#10b981",X=function(e){var n=parseFloat(e);return Number.isFinite(n)?n:NaN},$=function(e){if(!e)return"";var n=String(e).trim();if(!n)return"";if(n.includes(",")){var s=n.split(",").map((function(e){return e.trim()})).filter(Boolean);return 0===s.length?n:s.length<=2?s.join(", "):s.slice(-2).join(", ")}var r=n.split(/\s+/).filter(Boolean),t=r.length>6?r.slice(-6).join(" "):n;return t.length>40?"".concat(t.slice(0,40).trim(),"\u2026"):t},ee=function(e){return Number.isFinite(X(e.droplat||e.deliverylat))&&Number.isFinite(X(e.droplon||e.deliverylong))},ne=function(e){return e.pickuplat||e.pickuplatitude||e.pickup_lat},se=function(e){return e.pickuplong||e.pickuplongitude||e.picklongitude||e.pickup_lon},re=function(e){return Number.isFinite(X(ne(e)))&&Number.isFinite(X(se(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}],ae="dispatch.slots.v8",ie=["dispatch.slots.v1","dispatch.slots.v2","dispatch.slots.v3","dispatch.slots.v4","dispatch.slots.v5","dispatch.slots.v6","dispatch.slots.v7"],ce=function(e,n){return"Slot ".concat(e+1," \xb7 ").concat(le(n))},le=function(e){var n=Math.floor(e),s=Math.round(60*(e-n)),r=(n+11)%12+1,t=n>=12&&n<24?"PM":"AM";if(0===s)return"".concat(r," ").concat(t);var a=String(s).padStart(2,"0");return"".concat(r,":").concat(a," ").concat(t)},de=function(e,n){return n>=24?"After ".concat(le(e)):"".concat(le(e),"\u2013").concat(le(n))},oe=te.map((function(e,n){return(0,o.Z)((0,o.Z)({},e),{},{label:e.name||ce(n,e.startHour),range:de(e.startHour,e.endHour)})})),ue=function(e,n){var s,r=(0,d.Z)(n);try{for(r.s();!(s=r.n()).done;){var t=s.value;if(e>=t.startHour&&e<t.endHour)return t.id}}catch(a){r.e(a)}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,n){var s,r=me.find((function(e){return e.id===n}))||me[0],t=(0,d.Z)(r.keys);try{for(t.s();!(s=t.n()).done;){var a=s.value;if(null!==e&&void 0!==e&&e[a])return e[a]}}catch(i){t.e(i)}finally{t.f()}return null},he=function(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"all",s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:oe,r=pe(e,n);if(!r)return null;var t=String(r).trim();if(/^\d{4}-\d{2}-\d{2}$/.test(t))return null;var a=S()(r);return a.isValid()?ue(a.hour()+a.minute()/60,s):null};function ve(e){var n=e.targetRef,s=(0,m.Sx)();return(0,u.useEffect)((function(){return n.current=s,function(){n.current=null}}),[s]),null}function fe(e,n){var s=function(e){return e*Math.PI/180},r=s(e[0]),t=s(n[0]),a=s(n[0]-e[0]),i=s(n[1]-e[1]),c=Math.pow(Math.sin(a/2),2)+Math.cos(r)*Math.cos(t)*Math.pow(Math.sin(i/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 n=0,s=1;s<e.length;s++)n+=fe(e[s-1],e[s]);return n}function je(e){var n=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 s=null!=n.processNoise?n.processNoise:1e-9,r=null!=n.measurementNoise?n.measurementNoise:1e-7,t=function(e){return e._ts||(e.logdate?new Date(e.logdate).getTime():0)},a=function(n){for(var a=e[0][n],i=0,c=1,l=0,d=0,o=1,u=[a],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=a+i*v,x=i,j=v*v,g=j*v,N=c+v*(l+d)+j*o+g*v/4*s,b=l+v*o+g/2*s,y=d+v*o+g/2*s,k=o+j*s,S=e[p][n]-f,_=N+r,w=N/_,F=y/_;a=f+w*S,i=x+F*S,c=(1-w)*N,l=(1-w)*b,d=y-F*N,o=k-F*b,u.push(a)}return u},i=a("lat"),c=a("lng");return e.map((function(e,n){return{lat:i[n],lng:c[n],logdate:e.logdate,_ts:e._ts}}))}function ge(e,n){if(!Array.isArray(e)||e.length<2||!n||!n.length)return[];for(var s=n.map((function(n){for(var s=0,r=1/0,t=0;t<e.length;t++){var a=e[t][0]-n[0],i=e[t][1]-n[1],c=a*a+i*i;c<r&&(r=c,s=t)}return s})),r=1;r<s.length;r++)s[r]<s[r-1]&&(s[r]=s[r-1]);var t=[],a=0;return s.forEach((function(n){var s=Math.max(n,a);t.push(e.slice(a,s+1)),a=s})),t}var Ne=function(e){if(!e)return null;var n=S()(e);return n.isValid()?n.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 n=e.filter(ee);if(!n.length)return[];var s=e.find(re),r=[];return s&&r.push([X(ne(s)),X(se(s))]),n.forEach((function(e){return r.push([X(e.droplat||e.deliverylat),X(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 n=String(null!==e&&void 0!==e?e:"");if(!n)return ke[0];for(var s=0,r=0;r<n.length;r++)s=31*s+n.charCodeAt(r)>>>0;return ke[s%ke.length]},_e=function(e){var n=e.focusedItem,s=e.viewMode,r=e.orders,t=e.kitchens,a=e.locationKey,i=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!=a?"loc:".concat(a,"|"):"",c=function(e){var n,s=0,r=0,t=0,a=(0,d.Z)(e);try{for(a.s();!(n=a.n()).done;){var i=n.value;Number.isFinite(i[0])&&Number.isFinite(i[1])&&(s+=i[0],r+=i[1],t+=1)}}catch(c){a.e(c)}finally{a.f()}return 0===t?"0":"".concat((s/t).toFixed(1),",").concat((r/t).toFixed(1))};if(n){var l,o,u,m=null!==(l=null!==(o=null!==(u=n.id)&&void 0!==u?u:n.kitchenName)&&void 0!==o?o:n.name)&&void 0!==l?l:null!=n.lat?"".concat(n.lat,",").concat(n.lon):"item",p=n.orders?n.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"===s){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"===s){var x=(r||[]).map((function(e){return[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]})),j=i||[],g=x.concat(j);return"".concat(e,"a|").concat(g.length,"|").concat(c(g))}return"".concat(e,"m|").concat(s||"","|").concat(h.length,"|").concat(v)}),[n,s,r,t,a]);return(0,u.useEffect)((function(){if(o.current!==p){var e=[];n?n.orders&&n.orders.length?(e=n.orders.map((function(e){return[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]})),n.orders.forEach((function(n){return e.push([X(ne(n)),X(se(n))])}))):e=[[n.lat,n.lon]]:"kitchens"===s?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"===s?e=(e=(r||[]).map((function(e){return[parseFloat(e.droplat||e.deliverylat),parseFloat(e.droplon||e.deliverylong)]}))).concat(i||[]):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 a=e.filter((function(e){return Number.isFinite(e[0])&&Number.isFinite(e[1])}));if(a.length>0){var c=b().latLngBounds(a);c.isValid()&&(1===a.length||c.getNorthEast().equals(c.getSouthWest())?l.setView(a[0],15,{animate:!0,duration:.6}):l.flyToBounds(c,{padding:[60,60],duration:.6,maxZoom:16}),o.current=p)}else;}}),[p,n,s,r,t,i,l]),null},we=function(e){var n=e.target,s=e.icon,r=e.duration,t=void 0===r?950:r,a=e.zIndexOffset,i=e.eventHandlers,c=e.children,l=e.markerRef,d=(0,u.useRef)(null),o=(0,u.useRef)(null),m=(0,u.useRef)(n),h=(0,u.useRef)(null),v=Array.isArray(n)?Number(n[0]):NaN,f=Array.isArray(n)?Number(n[1]):NaN;return(0,u.useEffect)((function(){var e=d.current;if(e&&Number.isFinite(v)&&Number.isFinite(f)){var n=b().latLng(v,f),s=e.getLatLng();if(s){var r=n.lat-s.lat,a=n.lng-s.lng;if(!(Math.abs(r)<1e-6&&Math.abs(a)<1e-6)){var i=!1;try{i=s.distanceTo(n)>2e3}catch(x){i=!1}if(i)return e.setLatLng(n),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=s.lat,p=s.lng;return o.current=requestAnimationFrame((function n(s){var t=Math.min(1,(s-c)/u);e.setLatLng([m+r*t,p+a*t]),t<1&&(o.current=requestAnimationFrame(n))})),function(){o.current&&cancelAnimationFrame(o.current)}}e.setLatLng(n)}else e.setLatLng(n)}}),[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:s,zIndexOffset:a,eventHandlers:i,children:c})},Fe=function(e){var n=e.children;return(0,P.jsx)("span",{className:"ico-inline",style:{display:"inline-flex",alignItems:"center",verticalAlign:"-2px",marginRight:4},children:n})},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"}],Ee=function(e){if(null==e)return"\u2014";if("number"===typeof e)return e.toLocaleString("en-IN");var n=parseFloat(e);return Number.isFinite(n)?n.toLocaleString("en-IN"):String(e)},Ce=function(e){var n=e.data,s=e.embedded,m=void 0!==s&&s,N=e.selectedRiderId,y=e.onRiderSelect,k=e.pulseOrderId,L=null!==n&&void 0!==n&&n.zones&&n.zones.length>0?"zones":"riders",D=(0,u.useState)(L),O=(0,l.Z)(D,2),q=O[0],T=O[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],Ce=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 Ce(e.batch)},onSuccess:function(e,n){U((function(s){return(0,o.Z)((0,o.Z)({},s),{},(0,c.Z)({},n.batch,{data:e,fetchedAt:S()().format("HH:mm:ss")}))}))},onSettled:function(){return Ce(null)}}),De=function(e){Re(e);var n=G[e];n&&n.data&&!1!==n.data.success||Le.mutate({batch:e,tenantId:916})},Ze=(0,u.useState)(new Set),Oe=(0,l.Z)(Ze,2),qe=Oe[0],Te=Oe[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],Xe=Je[1],$e=(0,u.useState)(null),en=(0,l.Z)($e,2),nn=en[0],sn=en[1],rn=(0,u.useState)(null),tn=(0,l.Z)(rn,2),an=tn[0],cn=(tn[1],(0,u.useState)("planned")),ln=(0,l.Z)(cn,2),dn=ln[0],on=ln[1],un=(0,u.useRef)({}),mn=(0,u.useRef)(new Set),pn=(0,u.useRef)(new Set),hn=(0,u.useRef)(new Map),vn=((0,u.useRef)(null),(0,u.useRef)(null)),fn=(0,u.useState)(null),xn=(0,l.Z)(fn,2),jn=xn[0],gn=xn[1],Nn=void 0!==N,bn=(0,u.useState)(""),yn=(0,l.Z)(bn,2),kn=yn[0],Sn=yn[1],_n=(0,w.a)({queryKey:["appLocations"],queryFn:M.gO,staleTime:3e5}).data,wn="undefined"!==typeof window?localStorage.getItem("applocationid"):null,Fn=(0,u.useState)(null!=wn?Number(wn):0),An=(0,l.Z)(Fn,2),En=An[0],Cn=(An[1],(0,u.useState)(!1)),Mn=(0,l.Z)(Cn,2),zn=Mn[0],Pn=Mn[1],Rn=(0,u.useRef)(null),Ln=(0,u.useState)("assigned"),Dn=(0,l.Z)(Ln,2),Zn=Dn[0],On=(Dn[1],(0,u.useState)(!1)),qn=(0,l.Z)(On,2),Tn=qn[0],In=qn[1],Hn=(0,u.useRef)(null),Kn=(0,u.useState)((function(){if("undefined"===typeof window)return oe;try{var e=window.localStorage.getItem(ae);if(!e)return oe;var n=JSON.parse(e);return Array.isArray(n)&&n.length===te.length?n.map((function(e,n){var s=e.id||"slot-".concat(n+1),r=Number(e.startHour)||0,t=Number(e.endHour)||24,a=oe.find((function(e){return e.id===s}));return{id:s,startHour:r,endHour:t,label:(null===a||void 0===a?void 0:a.name)||ce(n,r),range:de(r,t)}})):oe}catch(s){return oe}})),Bn=(0,l.Z)(Kn,2),Yn=Bn[0],Gn=(Bn[1],Yn),Un=(0,u.useState)(!1),Vn=(0,l.Z)(Un,2),Wn=Vn[0],Jn=Vn[1],Qn=(0,u.useRef)(null);(0,u.useEffect)((function(){if("undefined"!==typeof window)try{ie.forEach((function(e){return window.localStorage.removeItem(e)}))}catch(e){}}),[]);var Xn=(0,u.useRef)(!1);(0,u.useEffect)((function(){if(Xn.current){if("undefined"!==typeof window)try{window.localStorage.setItem(ae,JSON.stringify(Yn.map((function(e){return{id:e.id,startHour:e.startHour,endHour:e.endHour}}))))}catch(e){}}else Xn.current=!0}),[Yn]),(0,u.useEffect)((function(){if(zn){var e=function(e){Rn.current&&!Rn.current.contains(e.target)&&Pn(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}}),[zn]),(0,u.useEffect)((function(){if(Tn){var e=function(e){Hn.current&&!Hn.current.contains(e.target)&&In(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}}),[Tn]),(0,u.useEffect)((function(){if(Wn){var e=function(e){Qn.current&&!Qn.current.contains(e.target)&&Jn(!1)};return document.addEventListener("mousedown",e),function(){return document.removeEventListener("mousedown",e)}}}),[Wn]);var $n=(0,u.useState)(null),es=(0,l.Z)($n,2),ns=es[0],ss=es[1],rs=(0,u.useState)(""),ts=(0,l.Z)(rs,2),as=ts[0],is=ts[1],cs=(0,w.a)({queryKey:["riderPeriodicLog",ns],queryFn:function(){return(0,M.hG)(ns)},enabled:"rider-info"===q&&null!=ns,refetchInterval:"rider-info"===q&&null!=ns&&15e3,refetchIntervalInBackground:!1,staleTime:5e3,refetchOnWindowFocus:!1}),ls=cs.data,ds=cs.isFetching,os=cs.isError,us=cs.error,ms=(0,u.useMemo)((function(){var e=parseFloat(null===ls||void 0===ls?void 0:ls.latitude),n=parseFloat(null===ls||void 0===ls?void 0:ls.longitude);return Number.isFinite(e)&&Number.isFinite(n)?{lat:e.toFixed(4),lon:n.toFixed(4)}:null}),[null===ls||void 0===ls?void 0:ls.latitude,null===ls||void 0===ls?void 0:ls.longitude]),ps=(0,w.a)({queryKey:["reverseGeocode",null===ms||void 0===ms?void 0:ms.lat,null===ms||void 0===ms?void 0:ms.lon],queryFn:function(){var e=(0,i.Z)((0,a.Z)().mark((function e(){var n,s,r,t;return(0,a.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,fetch("https://nominatim.openstreetmap.org/reverse?lat=".concat(ms.lat,"&lon=").concat(ms.lon,"&format=json&zoom=16&addressdetails=1"),{headers:{Accept:"application/json"}});case 2:if((n=e.sent).ok){e.next=5;break}return e.abrupt("return",null);case 5:return e.next=7,n.json();case 7:return s=e.sent,r=(null===s||void 0===s?void 0:s.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===s||void 0===s?void 0:s.display_name)||""});case 11:case"end":return e.stop()}}),e)})));return function(){return e.apply(this,arguments)}}(),enabled:"rider-info"===q&&!!ms,staleTime:3e5,refetchOnWindowFocus:!1,retry:1}),hs=ps.data,vs=(0,u.useMemo)((function(){if(!_n)return null;var e=_n.find((function(e){return String(e.applocationid)===String(En)}));return(null===e||void 0===e?void 0:e.locationname)||null}),[_n,En]),fs=(0,u.useState)({}),xs=(0,l.Z)(fs,2),js=xs[0],gs=xs[1],Ns=(0,u.useRef)({}),bs=(0,u.useState)({}),ys=(0,l.Z)(bs,2),ks=ys[0],Ss=ys[1],_s=(0,u.useRef)({}),ws=(0,u.useState)(!1),Fs=(0,l.Z)(ws,2),As=Fs[0],Es=Fs[1],Cs=(0,u.useState)([]),Ms=(0,l.Z)(Cs,2),zs=Ms[0],Ps=Ms[1],Rs=(0,u.useState)({}),Ls=(0,l.Z)(Rs,2),Ds=Ls[0],Zs=Ls[1],Os=(0,u.useRef)(!1),qs=(0,u.useState)(S()().format("YYYY-MM-DD")),Ts=(0,l.Z)(qs,2),Is=Ts[0],Hs=Ts[1],Ks=(0,u.useState)(!1),Bs=(0,l.Z)(Ks,2),Ys=Bs[0],Gs=Bs[1],Us=(0,u.useState)((function(){return S()(Is).isValid()?S()(Is).startOf("month"):S()().startOf("month")})),Vs=(0,l.Z)(Us,2),Ws=Vs[0],Js=Vs[1],Qs=(0,u.useRef)(null);(0,u.useEffect)((function(){if(Ys){var e=function(e){Qs.current&&(Qs.current.contains(e.target)||Gs(!1))},n=function(e){"Escape"===e.key&&Gs(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",n),function(){document.removeEventListener("mousedown",e),document.removeEventListener("keydown",n)}}}),[Ys]),(0,u.useEffect)((function(){if(Ys){var e=S()(Is);e.isValid()&&Js(e.startOf("month"))}}),[Ys,Is]);var Xs=(0,u.useState)(!1),$s=(0,l.Z)(Xs,2),er=$s[0],nr=$s[1],sr=(0,u.useState)("combined"),rr=(0,l.Z)(sr,2),tr=rr[0],ar=rr[1],ir=(0,u.useState)(!0),cr=(0,l.Z)(ir,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],Er=(0,u.useState)(null),Cr=(0,l.Z)(Er,2),Mr=Cr[0],zr=Cr[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"===q?1e3:15e3,Dr=(0,w.a)({queryKey:[En,Is,""],queryFn:M.N4,refetchInterval:Lr,refetchIntervalInBackground:!1,staleTime:1e3,refetchOnWindowFocus:!1}).data,Zr=(0,u.useMemo)((function(){return(Dr||[]).map((function(e){var n,s=parseFloat(null===e||void 0===e?void 0:e.latitude),r=parseFloat(null===e||void 0===e?void 0:e.longitude);return Number.isFinite(s)&&Number.isFinite(r)?{id:String(null!==(n=e.userid)&&void 0!==n?n:""),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:s,lon:r}:null})).filter(Boolean)}),[Dr]),Or=(0,u.useMemo)((function(){return new Set(Zr.filter((function(e){return"active"===e.status||"pending"===e.status})).map((function(e){return String(e.id)})))}),[Zr]),qr=(0,u.useState)((function(){var e=S()();return ue(e.hour()+e.minute()/60,oe)||oe[0].id})),Tr=(0,l.Z)(qr,2),Ir=Tr[0],Hr=Tr[1];(0,u.useEffect)((function(){var e;"all"!==Ir&&(Gn.some((function(e){return e.id===Ir}))||Hr((null===(e=Gn[0])||void 0===e?void 0:e.id)||"all"))}),[Gn,Ir]);var Kr=(0,u.useRef)(null),Br=!n,Yr="undefined"!==typeof window&&localStorage.getItem("userid")||0,Gr=(0,F.N)({queryKey:["dispatchDeliveries",En,Yr,"all",Is,Is,1e3,"",0,0,0],queryFn:M.p7,getNextPageParam:function(e){var n;return null!==(n=e.nextPage)&&void 0!==n?n:void 0},enabled:Br,refetchInterval:"all"===q&&15e3,refetchIntervalInBackground:!1}),Ur=Gr.data,Vr=Gr.isFetching,Wr=Gr.isError,Jr=Gr.fetchNextPage,Qr=Gr.hasNextPage,Xr=Gr.isFetchingNextPage;(0,u.useEffect)((function(){Br&&Qr&&!Xr&&Jr()}),[Br,Qr,Xr,Jr]);var $r=(0,u.useRef)({}),et=(0,u.useMemo)((function(){var e,n=((null===Ur||void 0===Ur?void 0:Ur.pages)||[]).flatMap((function(e){return e.rows||[]})),s=new Set,r=[],t=(0,d.Z)(n);try{for(t.s();!(e=t.n()).done;){var a=e.value,i=null!=a.orderid?String(a.orderid):null;i&&s.has(i)||(i&&s.add(i),r.push(a))}}catch(c){t.e(c)}finally{t.f()}return r}),[Ur]),nt=(0,u.useMemo)((function(){var e=new Map;return et.forEach((function(n){var s=String(n.userid||n.rider_id||"");s&&"unassigned"!==s&&"0"!==s&&(e.has(s)||e.set(s,{id:s,riderName:n.ridername||n.rider_name||n.username||"Rider ".concat(s)}))})),Array.from(e.values()).sort((function(e,n){return String(e.riderName).localeCompare(String(n.riderName))}))}),[et]),st=(0,u.useMemo)((function(){var e={all:et.length};return Gn.forEach((function(n){e[n.id]=0})),et.forEach((function(n){var s=he(n,Zn,Gn);s&&(e[s]=(e[s]||0)+1)})),e}),[et,Zn,Gn]),rt=(0,u.useMemo)((function(){return"all"===Ir?et:et.filter((function(e){return he(e,Zn,Gn)===Ir}))}),[et,Ir,Zn,Gn]),tt=(0,u.useMemo)((function(){if(!Br)return null;if(!rt.length)return{code:200,zone_summary:[],zones:[]};var e=function(e){return String(e||"").trim()},n={};rt.forEach((function(s){var r=e(s.deliverysuburb)||e(s.locationsuburb)||e(s.zone_name)||"Unzoned",t=r.toLowerCase(),a=String(s.userid||s.rider_id||"unassigned"),i=s.ridername||s.rider_name||s.username||("unassigned"===a?"Unassigned":"Rider ".concat(a));n[t]||(n[t]={zone_name:r,riders:{}}),n[t].riders[a]||(n[t].riders[a]={rider_id:a,rider_name:i,orders:[]}),n[t].riders[a].orders.push(s)}));var s=Object.values(n).map((function(e){var n=Object.values(e.riders).map((function(e){var n=(0,t.Z)(e.orders).sort((function(e,n){return S()(e.deliverydate||e.assigntime||0).valueOf()-S()(n.deliverydate||n.assigntime||0).valueOf()}));return(0,o.Z)((0,o.Z)({},e),{},{orders:n.map((function(e,n){return(0,o.Z)((0,o.Z)({},e),{},{trip_number:e.trip_number||1,step:e.step||n+1})}))})}));return{zone_name:e.zone_name,riders:n}}));return{code:200,zone_summary:s.map((function(e){var n=e.riders.flatMap((function(e){return e.orders})),s=n.filter((function(e){return e.userid||e.rider_id})).length;return{zone_name:e.zone_name,total_orders:n.length,assigned_orders:s,unassigned_orders_count:n.length-s,active_riders_count:e.riders.filter((function(e){return"unassigned"!==e.rider_id})).length,total_delivery_kms:n.reduce((function(e,n){return e+parseFloat(n.actualkms||n.kms||0)}),0),total_profit:n.reduce((function(e,n){return e+parseFloat(n.profit||0)}),0)}})),zones:s}}),[Br,rt]),at=(0,u.useMemo)((function(){var e=n||tt||{zones:[],zone_summary:[]},s=e.zones||[],r={};(e.zone_summary||[]).forEach((function(e){r[e.zone_name]=e}));var t=function(e,n){var s={};return e.forEach((function(e){var r=n(e);r&&(s[r]=(s[r]||0)+1)})),Object.entries(s).map((function(e){var n=(0,l.Z)(e,2);return{name:n[0],count:n[1]}})).sort((function(e,n){return n.count-e.count}))};return s.map((function(e){var n,s,a,i,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 n=String(e.orderstatus||"unknown").toLowerCase();m[n]=(m[n]||0)+1})),{id:e.zone_name,name:e.zone_name,riders:e.riders||[],orders:l,totalOrders:null!==(n=c.total_orders)&&void 0!==n?n:l.length,activeRidersCount:null!==(s=c.active_riders_count)&&void 0!==s?s:d,totalKms:null!==(a=c.total_delivery_kms)&&void 0!==a?a:l.reduce((function(e,n){return e+parseFloat(n.actualkms||n.kms||0)}),0),totalProfit:null!==(i=c.total_profit)&&void 0!==i?i:l.reduce((function(e,n){return e+parseFloat(n.profit||0)}),0),suburbs:o,kitchens:u,statusCounts:m}}))}),[n,tt]),it=(0,u.useMemo)((function(){var e=[];((n||tt||{zones:[],zone_summary:[]}).zones||[]).forEach((function(n){(n.riders||[]).forEach((function(s){s.orders.forEach((function(r){e.push((0,o.Z)((0,o.Z)({},r),{},{zone_name:n.zone_name,rider_name:s.rider_name,rider_id:s.rider_id}))}))}))}));var s={};e.forEach((function(e){var n=e.rider_id||e.userid||"unknown";s[n]||(s[n]={id:n,riderName:e.rider_name||e.username||e.rider||n,orders:[],color:ke[Object.keys(s).length%ke.length]}),s[n].orders.push(e)}));var r={};e.forEach((function(e){var n=e.pickupcustomer||e.kitchen_key||"Unknown",s=n.toLowerCase().trim();r[s]?!Number.isFinite(r[s].lat)&&re(e)&&(r[s].lat=X(ne(e)),r[s].lon=X(se(e))):r[s]={id:s,kitchenName:n,lat:X(ne(e)),lon:X(se(e)),orders:[],riders:new Set},r[s].orders.push(e),e.rider_id&&r[s].riders.add(e.rider_id)}));var a=e.reduce((function(e,n){return e+parseFloat(n.actualkms||n.kms||0)}),0),i=e.reduce((function(e,n){return e+parseFloat(n.profit||0)}),0);return{riders:Object.values(s).map((function(e){return(0,o.Z)((0,o.Z)({},e),{},{orders:(0,t.Z)(e.orders).sort((function(e,n){var s=e.trip_number||1,r=n.trip_number||1;return s!==r?s-r:(e.step||0)-(n.step||0)}))})})).sort((function(e,n){return n.orders.length-e.orders.length})),kitchens:Object.values(r).sort((function(e,n){return n.orders.length-e.orders.length})),allOrders:e,stats:{totalOrders:e.length,totalKms:a,totalProfit:i,totalRiders:Object.keys(s).length}}}),[n,tt]),ct=it.riders,lt=it.kitchens,dt=it.allOrders,ot=it.stats,ut=Nn?N&&ct.find((function(e){return e.id===N}))||null:Ke,mt="all"===q,pt=(0,u.useMemo)((function(){return mt?dt.filter((function(e){return Or.has(String(e.rider_id||e.userid||""))})):dt}),[mt,dt,Or]),ht=(0,u.useMemo)((function(){return new Set((mt?pt:[]).filter(z.Y_).map((function(e){return String(e.rider_id||e.userid||"")})))}),[mt,pt]),vt=(0,u.useMemo)((function(){return mt?ct.filter((function(e){return ht.has(String(e.id))})):ct}),[mt,ct,ht]),ft=(0,u.useMemo)((function(){if(!mt)return $r.current={},[];var e=new Set(["delivered","cancelled","skipped","complete","completed"]);rt.forEach((function(n){var s=String(n.orderid),r=String(n.orderstatus||"").toLowerCase();"active"===r?$r.current[s]=n:e.has(r)&&delete $r.current[s]}));var n=Object.values($r.current);if(!n.length)return[];var s=Object.fromEntries(ct.map((function(e){return[e.id,e]}))),r={};return n.forEach((function(e){var n=String(e.rider_id||e.userid||"");if(n&&"unassigned"!==n&&"0"!==n){var t,a;if(!r[n])r[n]={id:n,riderName:(null===(t=s[n])||void 0===t?void 0:t.riderName)||e.rider_name||e.ridername||e.username||"Rider ".concat(n),orders:[],color:(null===(a=s[n])||void 0===a?void 0:a.color)||Se(n)};r[n].orders.some((function(n){return String(n.orderid)===String(e.orderid)}))||r[n].orders.push(e)}})),Object.values(r)}),[mt,rt,ct]),xt=(0,u.useMemo)((function(){return mt?Zr.filter((function(e){return("active"===e.status||"pending"===e.status)&&ht.has(String(e.id))})).map((function(e){return[e.lat,e.lon]})):[]}),[mt,Zr,ht]);(0,u.useEffect)((function(){$r.current={}}),[Is,En,Ir,Zn]);var jt=(0,u.useCallback)((function(e){y&&y(e?e.id:null),Nn||Be(e),sn(null)}),[Nn,y]),gt=(0,u.useRef)(null);(0,u.useEffect)((function(){var e=ut?ut.id:null;e!==gt.current&&(ut?V.info("Focused rider changed to: ".concat(ut.riderName," (").concat(ut.orders.length," orders)")):V.info("Focused rider reset to: None"),gt.current=e)}),[ut]),(0,u.useEffect)((function(){nn?V.info("Focused order updated: ID ".concat(nn.orderid)):V.debug("Focused order selection cleared")}),[nn]);var Nt=(0,u.useRef)(0);(0,u.useEffect)((function(){dt&&dt.length!==Nt.current&&(V.info("Orders database updated: ".concat(dt.length," orders actively tracked")),Nt.current=dt.length)}),[dt]);var bt=(0,u.useRef)(0);(0,u.useEffect)((function(){Zr&&Zr.length!==bt.current&&(V.info("Live riders list updated: ".concat(Zr.length," active riders mapped")),bt.current=Zr.length)}),[Zr]);var yt=(0,u.useMemo)((function(){if(ut)return{orders:ut.orders.length,riders:1,km:ut.orders.reduce((function(e,n){return e+parseFloat(n.actualkms||n.kms||0)}),0),profit:ut.orders.reduce((function(e,n){return e+parseFloat(n.profit||0)}),0),label:"Focused Rider"};if(Ue)return{orders:Ue.orders.length,riders:Ue.riders.size,km:Ue.orders.reduce((function(e,n){return e+parseFloat(n.actualkms||n.kms||0)}),0),profit:Ue.orders.reduce((function(e,n){return e+parseFloat(n.profit||0)}),0),label:"Focused Kitchen"};if(mt){var e=ft.flatMap((function(e){return e.orders}));return{orders:e.length,riders:ft.length,km:e.reduce((function(e,n){return e+parseFloat(n.actualkms||n.kms||0)}),0),profit:e.reduce((function(e,n){return e+parseFloat(n.profit||0)}),0),label:"Active Fleet"}}return{orders:ot.totalOrders,riders:ot.totalRiders,km:ot.totalKms,profit:ot.totalProfit,label:"Total Fleet"}}),[ut,Ue,mt,ft,ot]),kt=((0,u.useMemo)((function(){return mt?ft.reduce((function(e,n){return e+n.orders.length}),0):0}),[mt,ft]),(0,u.useMemo)((function(){var e;e=ut?ut.orders:Ue?Ue.orders:Qe?Qe.orders:dt;var n=new Set;return(e||[]).forEach((function(e){null!=e.deliveryid&&""!==e.deliveryid&&0!==e.deliveryid&&n.add(String(e.deliveryid))})),Array.from(n)}),[dt,ut,Ue,Qe])),St=(0,A.h)({queries:kt.map((function(e){return{queryKey:["deliveryLogs",e],queryFn:function(){var n=(0,i.Z)((0,a.Z)().mark((function n(){var s,t,i,c,l,d,o;return(0,a.Z)().wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,E.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 i=n.sent,c=[null===i||void 0===i||null===(s=i.data)||void 0===s?void 0:s.details,null===i||void 0===i||null===(t=i.data)||void 0===t?void 0:t.data,null===i||void 0===i?void 0:i.data,i],l=c.find((function(e){return Array.isArray(e)}))||[],d=l.map((function(e){var n,s,r,t=null!==e&&void 0!==e&&e.logdate?S()(e.logdate):null;return{lat:parseFloat(null!==(n=null===e||void 0===e?void 0:e.latitude)&&void 0!==n?n:null===e||void 0===e?void 0:e.lat),lng:parseFloat(null!==(s=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!==s?s: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,n){return e._ts-n._ts})),o=je(d),n.abrupt("return",o.map((function(e){e._ts;return(0,r.Z)(e,W)})));case 8:case"end":return n.stop()}}),n)})));return function(){return n.apply(this,arguments)}}(),enabled:!0,staleTime:3e5,refetchOnWindowFocus:!1,retry:1}}))}),_t=(0,u.useMemo)((function(){var e=new Map;return kt.forEach((function(n,s){var r=St[s];e.set(n,{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}),[kt,St]),wt=(0,u.useMemo)((function(){if(!ut)return[];var e=function(e){var n=e.deliverytime||e.expecteddeliverytime;if(!n)return Number.MAX_SAFE_INTEGER;var s=S()(n);return s.isValid()?s.valueOf():Number.MAX_SAFE_INTEGER};return ut.orders.filter((function(e){return null!=e.deliveryid&&""!==e.deliveryid&&0!==e.deliveryid})).sort((function(n,s){var r=e(n)-e(s);return 0!==r?r:(n.step||0)-(s.step||0)})).map((function(e,n){var s=_t.get(String(e.deliveryid));return{sequenceStep:n+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===s||void 0===s||!s.isLoading),isError:!(null===s||void 0===s||!s.isError),coords:(null===s||void 0===s?void 0:s.coords)||[]}}))}),[ut,_t]),Ft=(0,u.useMemo)((function(){return ut?wt.map((function(e){var n=ut.orders.find((function(n){return String(n.deliveryid)===String(e.deliveryid)})),s=parseFloat((null===n||void 0===n?void 0:n.kms)||0)||0,r=ks[e.deliveryid],t=0;Array.isArray(r)&&r.length>=2?t=xe(r):null!=(null===n||void 0===n?void 0:n.actualkms)&&""!==n.actualkms?t=parseFloat(n.actualkms)||0:e.coords.length>=2&&(t=xe(e.coords.map((function(e){return[e.lat,e.lng]}))));var a=t-s,i=s>0?a/s*100:null,c=null!==n&&void 0!==n&&n.expecteddeliverytime?S()(n.expecteddeliverytime):null,l=null!==n&&void 0!==n&&n.deliverytime?S()(n.deliverytime):null,d=null!==c&&void 0!==c&&c.isValid()&&null!==l&&void 0!==l&&l.isValid()?l.diff(c,"minute"):null,o=s>0&&t>1.25*s||null!=d&&d>15;return{sequenceStep:e.sequenceStep,deliveryid:e.deliveryid,orderid:e.orderid,order:n,plannedKm:s,actualKm:t,kmDelta:a,kmDeltaPct:i,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===n||void 0===n?void 0:n.pickupcustomer,isLoading:e.isLoading,coordsCount:e.coords.length}})):[]}),[wt,ut,ks]),At=(0,u.useMemo)((function(){if(0===Ft.length)return{plannedKm:0,actualKm:0,kmDeltaPct:null,anomalies:0,late:0,onTime:0};var e=Ft.filter((function(e){return!e.isLoading&&e.coordsCount>0})),n=e.reduce((function(e,n){return e+n.plannedKm}),0),s=e.reduce((function(e,n){return e+n.actualKm}),0);return{plannedKm:n,actualKm:s,kmDeltaPct:n>0?(s-n)/n*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}}),[Ft]),Et=(0,u.useMemo)((function(){return(0,t.Z)(Ft).sort((function(e,n){var s,r;return((null===(s=e.order)||void 0===s?void 0:s.step)||e.sequenceStep)-((null===(r=n.order)||void 0===r?void 0:r.step)||n.sequenceStep)}))}),[Ft]),Ct=(0,u.useMemo)((function(){return(0,t.Z)(Ft).sort((function(e,n){return e.sequenceStep-n.sequenceStep}))}),[Ft]),Mt=(0,u.useMemo)((function(){if(!er||!Mr||!ut)return null;var e=wt.find((function(e){return e.sequenceStep===Mr}));if(!e)return null;var n=ut.orders.find((function(n){return String(n.deliveryid)===String(e.deliveryid)}));return n?{orders:[n],id:"cmp-step-".concat(Mr,"-").concat(n.orderid)}:null}),[er,Mr,ut,wt]);(0,u.useEffect)((function(){zr(null),xr(new Set),ar("combined")}),[er,null===ut||void 0===ut?void 0:ut.id]),(0,u.useEffect)((function(){!ut&&er&&nr(!1)}),[ut,er]),(0,u.useEffect)((function(){jr.current&&ut&&(jr.current=!1,nr(!0))}),[ut]),(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 zt=(0,u.useCallback)(function(){var e=(0,i.Z)((0,a.Z)().mark((function e(n,s,r){var t,i,l,d,u,m;return(0,a.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t="".concat(n,"-").concat(s),void 0===Ns.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 Ns.current[t]=null,gs((function(e){return(0,o.Z)((0,o.Z)({},e),{},(0,c.Z)({},t,null))})),i=r.map((function(e){return"".concat(e[1],",").concat(e[0])})).join(";"),l="https://router.project-osrm.org/route/v1/driving/".concat(i,"?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]]})),Ns.current[t]=m,gs((function(e){return(0,o.Z)((0,o.Z)({},e),{},(0,c.Z)({},t,m))}))):(Ns.current[t]=!1,gs((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),Ns.current[t]=!1,gs((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(n,s,r){return e.apply(this,arguments)}}(),[]);(0,u.useEffect)((function(){Ns.current={},gs({}),_s.current={},Ss({})}),[Is,Ir]);var Pt=(0,u.useCallback)(function(){var e=(0,i.Z)((0,a.Z)().mark((function e(n,s){var r,t,i,l,d,u,m,p,h,v,f,x,j,g,N;return(0,a.Z)().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(void 0===_s.current[n]){e.next=2;break}return e.abrupt("return");case 2:if(Array.isArray(s)&&!(s.length<2)){e.next=4;break}return e.abrupt("return");case 4:return _s.current[n]=null,Ss((function(e){return(0,o.Z)((0,o.Z)({},e),{},(0,c.Z)({},n,null))})),r=function(e){_s.current[n]=e,Ss((function(s){return(0,o.Z)((0,o.Z)({},s),{},(0,c.Z)({},n,e))}))},t=function(){_s.current[n]=!1,Ss((function(e){return(0,o.Z)((0,o.Z)({},e),{},(0,c.Z)({},n,!1))}))},i=function(e,n){if(e.length<=n)return e;var s=Math.ceil(e.length/n),r=e.filter((function(e,n){return n%s===0})),t=e[e.length-1];return r[r.length-1]!==t&&r.push(t),r},e.prev=9,l=i(s,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 n;return((null===(n=e.geometry)||void 0===n?void 0:n.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=i(s,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(n,s){return e.apply(this,arguments)}}(),[]);(0,u.useEffect)((function(){_t.forEach((function(e,n){if(n&&e&&!(e.coords.length<2)){var s=e.coords.map((function(e){return[e.lat,e.lng]}));Pt(n,s)}}))}),[_t,Pt]),(0,u.useEffect)((function(){Os.current=As}),[As]),(0,u.useEffect)((function(){if(!m){var e=function(){var e=new Date;Sn([e.getHours(),e.getMinutes(),e.getSeconds()].map((function(e){return String(e).padStart(2,"0")})).join(":"))},n=setInterval(e,1e3);return e(),function(){return clearInterval(n)}}}),[m]),(0,u.useEffect)((function(){Te(new Set(ct.map((function(e){return e.id}))))}),[ct]),(0,u.useEffect)((function(){ct.forEach((function(e){if(qe.has(e.id)&&(!ut||ut.id===e.id)){var n={};if(e.orders.forEach((function(e){var s=e.trip_number||1;n[s]||(n[s]=[]),n[s].push(e)})),Object.entries(n).forEach((function(n){var s=(0,l.Z)(n,2),r=s[0],a=s[1],i=(0,t.Z)(a).sort((function(e,n){return(e.step||0)-(n.step||0)})),c=ye(i);c.length>=2&&zt(e.id,r,c)})),mt){var s=(0,z.P0)(e.orders);if(s){var r=Zr.find((function(n){return String(n.id)===String(e.id)})),a=r&&Number.isFinite(r.lat)&&Number.isFinite(r.lon)?[r.lat,r.lon]:re(s)?[X(ne(s)),X(se(s))]:null,i=X(s.droplat||s.deliverylat),c=X(s.droplon||s.deliverylong);a&&Number.isFinite(i)&&Number.isFinite(c)&&zt(e.id,"active-".concat(s.orderid),[a,[i,c]])}}}}))}),[ct,qe,ut,mt,Zr,zt]);var Rt=(0,u.useRef)(null);(0,u.useEffect)((function(){if(Br){var e=function(){var e=S()();return e.hour()+e.minute()/60};null===Rt.current&&(Rt.current=e());var n=setInterval((function(){var n=e(),s=ue(Rt.current,Gn),r=ue(n,Gn);Rt.current=n,r&&r!==s&&Hr((function(e){return e===s?r:e}))}),3e4);return function(){return clearInterval(n)}}}),[Br,Gn]),(0,u.useEffect)((function(){sn(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 Lt=function(e){var n=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return b().divIcon({className:"",iconSize:n?[56,56]:[46,46],iconAnchor:n?[28,28]:[23,23],popupAnchor:[0,n?-30:-24],html:'<div class="kitchen-mark'.concat(n?" is-focused":"",'">').concat((e||"K").charAt(0).toUpperCase(),"</div>")})},Dt=function(e){var n;return(null===(n=ct.find((function(n){return String(n.id)===String(e)})))||void 0===n?void 0:n.color)||"#475569"},Zt=function(e,n){if(!e||!n||!ee(n))return null;var s=Zr.find((function(n){return String(n.id)===String(e)}));if(!s)return null;var r=X(n.droplat||n.deliverylat),t=X(n.droplon||n.deliverylong);if(!Number.isFinite(r)||!Number.isFinite(t))return null;var a=fe([s.lat,s.lon],[r,t]);return Math.round(1e3*a)},Ot=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 ",et.length?"\xb7 ".concat(et.length," loaded"):""]}),!Vr&&!Wr&&(0,P.jsxs)("span",{className:"live-status live-status-ready",children:[(0,P.jsx)("span",{className:"live-dot ready"})," ",rt.length," orders",(0,P.jsxs)("span",{className:"live-status-sub",children:[" / ",et.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"),n=e.format("YYYY-MM-DD"),s=S()(Is),r=Is===n,t=s.isAfter(e,"day"),a=function(n){if(n){var s=n.format("YYYY-MM-DD");s!==Is?n.isAfter(e,"day")||(Hs(s),jt(null),Ve(null),Xe(null),Gs(!1)):Gs(!1)}},i=Ws.startOf("month"),c=i.subtract(i.day(),"day"),l=Array.from({length:42},(function(e,n){return c.add(n,"day")})),d=!Ws.add(1,"month").startOf("month").isAfter(e,"month");return(0,P.jsxs)("div",{className:"date-chip".concat(r?" is-today":"").concat(Ys?" is-open":""),ref:Qs,children:[(0,P.jsx)("button",{type:"button",className:"date-chip-nav",onClick:function(){return a(s.subtract(1,"day"))},"aria-label":"Previous day",title:"Previous day",children:(0,P.jsx)(C.G1X,{})}),(0,P.jsxs)("button",{type:"button",className:"date-chip-main",onClick:function(){return Gs((function(e){return!e}))},"aria-haspopup":"dialog","aria-expanded":Ys,children:[(0,P.jsx)("span",{className:"date-chip-icon","aria-hidden":"true",children:(0,P.jsx)(C.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:s.isValid()?s.format("ddd, MMM D, YYYY"):"\u2014"})]}),(0,P.jsx)("span",{className:"date-chip-chevron".concat(Ys?" is-open":""),"aria-hidden":"true",children:(0,P.jsx)(C.Yc6,{})})]}),(0,P.jsx)("button",{type:"button",className:"date-chip-nav",onClick:function(){r||t||a(s.add(1,"day"))},disabled:r||t,"aria-label":"Next day",title:r?"You're viewing today":"Next day",children:(0,P.jsx)(C.FNi,{})}),Ys&&(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 Js((function(e){return e.subtract(1,"month")}))},"aria-label":"Previous month",children:(0,P.jsx)(C.G1X,{})}),(0,P.jsx)("div",{className:"date-cal-title",children:Ws.format("MMMM YYYY")}),(0,P.jsx)("button",{type:"button",className:"date-cal-nav",onClick:function(){var n=Ws.add(1,"month");n.startOf("month").isAfter(e,"month")||Js(n)},disabled:!d,"aria-label":"Next month",children:(0,P.jsx)(C.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(s){var r=s.month()===Ws.month(),t=s.format("YYYY-MM-DD")===Is,i=s.format("YYYY-MM-DD")===n,c=s.isAfter(e,"day"),l=["date-cal-day",!r&&"is-other-month",t&&"is-selected",i&&"is-today",c&&"is-disabled"].filter(Boolean).join(" ");return(0,P.jsx)("button",{type:"button",className:l,disabled:c,onClick:function(){return a(s)},"aria-current":i?"date":void 0,"aria-pressed":t,children:s.date()},s.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 a(e)},children:"Today"}),(0,P.jsx)("button",{type:"button",className:"date-cal-preset",onClick:function(){return a(e.subtract(1,"day"))},children:"Yesterday"}),(0,P.jsx)("button",{type:"button",className:"date-cal-preset",onClick:function(){return a(e.subtract(7,"day"))},children:"\u22127 days"})]})]})]})}()]})}),(0,P.jsx)("div",{id:"clock",children:kn})]}),(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"===q?"active":""),onClick:function(){V.info("View mode changed: By Location"),T("kitchens"),jt(null),Ve(null),Xe(null)},children:[(0,P.jsx)("span",{className:"sbt-icon",children:(0,P.jsx)(C.c7Z,{})})," By Location"]}),(0,P.jsxs)("button",{className:"sbt ".concat("zones"===q?"active":""),onClick:function(){V.info("View mode changed: By Zone"),T("zones"),jt(null),Ve(null),Xe(null)},children:[(0,P.jsx)("span",{className:"sbt-icon",children:(0,P.jsx)(C.PKO,{})})," By Zone"]}),(0,P.jsxs)("button",{className:"sbt ".concat("riders"===q?"active":""),onClick:function(){V.info("View mode changed: By Rider"),T("riders"),jt(null),Ve(null),Xe(null)},children:[(0,P.jsx)("span",{className:"sbt-icon",children:(0,P.jsx)(C.MCF,{})})," By Rider"]}),!m&&(0,P.jsxs)("button",{className:"sbt ".concat("all"===q?"active":""),onClick:function(){V.info("View mode changed: All Active Routes"),T("all"),jt(null),Ve(null),Xe(null)},children:[(0,P.jsx)("span",{className:"sbt-icon",children:(0,P.jsx)(C.zNX,{})}),"Active"]}),!m&&(0,P.jsxs)("button",{type:"button",className:"sbt sbt-rider-info ".concat("rider-info"===q?"active":""),onClick:function(){T("rider-info"),jt(null),Ve(null),Xe(null)},title:"Live GPS / battery / status snapshot for a rider",children:[(0,P.jsx)("span",{className:"sbt-icon",children:(0,P.jsx)(C.eJU,{})})," Rider Info"]})]}),Br&&"rider-info"!==q&&(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:Gn.map((function(e){var n,s=Ir===e.id;return(0,P.jsxs)("button",{ref:s?Kr:null,className:"batch-btn batch-slot ".concat(s?"active":""),onClick:function(){Hr(e.id),jt(null),Ve(null),Xe(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!==(n=st[e.id])&&void 0!==n?n:0})]},e.id)}))})]}),"rider-info"===q?(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:[nt.length," ",1===nt.length?"rider":"riders"," today"]})]}),(0,P.jsxs)("div",{className:"ri-search",children:[(0,P.jsx)(C.vU7,{className:"ri-search-icon"}),(0,P.jsx)("input",{type:"text",className:"ri-search-input",placeholder:"Search by name or ID",value:as,onChange:function(e){return is(e.target.value)}})]}),function(){var e=as.trim().toLowerCase(),n=nt.filter((function(n){return!e||(String(n.riderName||"").toLowerCase().includes(e)||String(n.id).includes(e))}));return 0===n.length?(0,P.jsx)("div",{className:"ri-empty",children:as?'No riders match "'.concat(as,'"'):"No riders have orders today"}):(0,P.jsx)("div",{className:"ri-rider-list",children:n.map((function(e){var n=String(ns)===String(e.id);return(0,P.jsxs)("button",{type:"button",className:"ri-rider-item ".concat(n?"active":""),onClick:function(){return ss(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==ns?(0,P.jsxs)("div",{className:"ri-placeholder",children:[(0,P.jsx)("div",{className:"ri-placeholder-icon",children:(0,P.jsx)(C.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:[ds&&!ls&&(0,P.jsx)("div",{className:"ri-loading",children:"Loading rider snapshot\u2026"}),os&&(0,P.jsxs)("div",{className:"ri-error",children:["Couldn't load this rider's log. ",(null===us||void 0===us?void 0:us.message)||""]}),ls&&function(){var e=ls,n=parseFloat(e.latitude),s=parseFloat(e.longitude),r=Number.isFinite(n)&&Number.isFinite(s),t=parseInt(String(e.battery||"").replace("%",""),10),a=Number.isFinite(t)&&t<=20,i=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(ds?"is-refetching":""),children:[(0,P.jsx)("span",{className:"ri-live-dot"}),ds?"Updating\u2026":"Live"]})]}),e.logdate&&(0,P.jsxs)("div",{className:"ri-snap-time",children:[(0,P.jsx)(C.dKE,{})," Last seen ",e.logdate]})]}),(0,P.jsxs)("div",{className:"ri-snap-grid",children:[(0,P.jsxs)("div",{className:"ri-stat ".concat(a?"ri-stat-warn":""),children:[(0,P.jsx)("div",{className:"ri-stat-icon",children:(0,P.jsx)(C.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)(C.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)(C.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)(C.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)(C.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(i)?"".concat(i.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)(C.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)(C.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)(C.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)(C.$0r,{})," ",n.toFixed(6),", ",s.toFixed(6)]}),(0,P.jsx)("div",{className:"ri-map",children:(0,P.jsxs)(v.h,{center:[n,s],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:[n,s],children:[(0,P.jsx)(x.u,{direction:"top",offset:[0,-10],permanent:!0,className:"ri-area-banner",children:(null===hs||void 0===hs?void 0:hs.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===hs||void 0===hs?void 0:hs.area)&&(0,P.jsx)("div",{style:{fontSize:12,color:"#0f172a",marginBottom:4},children:hs.area}),(0,P.jsx)("div",{style:{fontSize:11,color:"#64748b"},children:e.logdate?"Last seen ".concat(e.logdate):"".concat(n.toFixed(6),", ").concat(s.toFixed(6))})]})]})]},"".concat(e.userid,"-").concat(n,"-").concat(s))})]})]})}()]})})]}):(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)(C.FNi,{}):(0,P.jsx)(C.G1X,{})}),er&&ut&&(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)(C.G1X,{}):(0,P.jsx)(C.FNi,{})}),(0,P.jsxs)("div",{id:"sidebar",children:[!ut&&(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:yt.label,children:[(0,P.jsx)("span",{className:"sb-scope-dot"}),yt.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)(C.ByW,{})}),(0,P.jsxs)("div",{className:"sb-tile-body",children:[(0,P.jsx)("div",{className:"sb-tile-value",children:yt.orders}),(0,P.jsx)("div",{className:"sb-tile-label",children:1===yt.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)(C.pbk,{})}),(0,P.jsxs)("div",{className:"sb-tile-body",children:[(0,P.jsx)("div",{className:"sb-tile-value",children:yt.riders}),(0,P.jsx)("div",{className:"sb-tile-label",children:1===yt.riders?"Rider":"Riders"})]})]})]})]}),ut&&!mt||Ue?(0,P.jsxs)("div",{id:"route-detail",children:[(0,P.jsxs)("button",{className:"rd-back",onClick:function(){jt(null),Ve(null)},children:["\u2190 Back to ",Qe?Qe.name:"list"]}),ut?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)("div",{className:"rd-rider-name",style:{color:ut.color},children:ut.riderName}),function(){var e=mt?(0,z.P0)(ut.orders):null,n=mt?e?[e]:[]:ut.orders,s=n.reduce((function(e,n){return e+parseFloat(n.kms||0)}),0),r=n.reduce((function(e,n){return e+parseFloat(n.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)(C.ByW,{})}),(0,P.jsx)("div",{className:"rd-stat-value",children:n.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)(C.v93,{})}),(0,P.jsxs)("div",{className:"rd-stat-value",children:[s.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)(C.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:"Trip KMs"})]})]})}(),function(){var e=mt?(0,z.P0)(ut.orders):null,n=mt?e?[e]:[]:ut.orders;if(mt&&0===n.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 s={};n.forEach((function(e){var n=e.trip_number||1;s[n]||(s[n]=[]),s[n].push(e)}));var r=(0,t.Z)(ut.orders).sort((function(e,n){var s=e.trip_number||1,r=n.trip_number||1;return s!==r?s-r:(e.step||0)-(n.step||0)})).find((function(e){var n=String(e.orderstatus||"").toLowerCase();return!z.Q6.has(n)&&!z.us.has(n)})),a=r?r.orderid:null,i=function(e){var n=e.deliverytime||e.expecteddeliverytime;if(!n)return Number.MAX_SAFE_INTEGER;var s=S()(n);return s.isValid()?s.valueOf():Number.MAX_SAFE_INTEGER},c="time"===dn,d=null;return Object.entries(s).sort((function(e,n){var s=(0,l.Z)(e,1)[0],r=(0,l.Z)(n,1)[0];return Number(s)-Number(r)})).map((function(e){var n=(0,l.Z)(e,2),s=n[0],r=n[1],o=c?(0,t.Z)(r).sort((function(e,n){var s=i(e)-i(n);return 0!==s?s:(e.step||0)-(n.step||0)})):r;return(0,P.jsxs)("div",{className:"trip-block",children:[(0,P.jsxs)("div",{className:"trip-header",style:{background:"".concat(ut.color,"12"),borderColor:"".concat(ut.color,"30")},children:[(0,P.jsxs)("span",{className:"th-badge",style:{background:ut.color},children:["Trip ",s]}),(0,P.jsxs)("span",{className:"trip-stats",children:[(0,P.jsxs)("span",{children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(C.$0r,{})}),r.length," stops"]}),(0,P.jsxs)("span",{children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(C.v93,{})}),r.reduce((function(e,n){return e+parseFloat(n.actualkms||n.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 on("planned")},title:"Sort stops by planned step (dispatched order)",children:[(0,P.jsx)(C.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 on("time")},title:"Sort stops by completion time (which delivery was done first)",children:[(0,P.jsx)(C.dKE,{"aria-hidden":"true"}),(0,P.jsx)("span",{children:"By time"})]})]})]}),(0,P.jsx)("div",{className:"zone-order-grid",children:o.map((function(e,n){var r=(e.kitchen_key||e.pickupcustomer||"Unknown").toLowerCase().trim(),t=null!==d&&r!==d;d=r;var i=nn&&nn.orderid===e.orderid,l=a&&e.orderid===a,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=Zt(ut.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)(C.x82,{})})," Switch to ",(0,P.jsx)("strong",{children:e.pickupcustomer})]}),(0,P.jsxs)("div",{className:"zone-order-card ".concat(p?"clickable":""," ").concat(i?"active":""," ").concat(l?"going-on":""," ").concat(f?"is-pending-time":""),role:p?"button":void 0,tabIndex:p?0:void 0,onClick:p?function(){return sn(i?null:{orderid:e.orderid,lat:o,lon:m})}:void 0,onKeyDown:p?function(n){"Enter"!==n.key&&" "!==n.key||(n.preventDefault(),sn(i?null:{orderid:e.orderid,lat:o,lon:m}))}:void 0,title:p?i?"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||n+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 n=Ne(e.deliverytime),s=Ne(e.expecteddeliverytime),r=!z.Q6.has(String(e.orderstatus||"").toLowerCase())&&null!==v;return e.orderstatus||n||s||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}),(n||s)&&(0,P.jsxs)("span",{className:"zone-order-time ".concat(n?"":"is-expected"),title:n?"Delivered at ".concat(n):"Expected at ".concat(s),children:[(0,P.jsx)(C.dKE,{}),n||s]}),r&&(0,P.jsxs)("span",{className:"zone-order-est-drop",title:"Estimated distance to drop location",children:[(0,P.jsx)(C.x$F,{}),Ot(v)]})]}):null}()]}),(0,P.jsxs)("div",{className:"zone-order-customer",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(C.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)(C.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)(C.$0r,{})}),e.deliverysuburb||$(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)(C.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)(C.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||s," \xb7 S",e.step||n+1]})]})]})]},e.orderid)}))})]},s)}))}()]}):(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)(C.ByW,{})}),Ue.orders.length," orders"]}),(0,P.jsxs)("span",{children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(C.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,n){var s=parseFloat(e.droplat||e.deliverylat),r=parseFloat(e.droplon||e.deliverylong),a=Number.isFinite(s)&&Number.isFinite(r),i=nn&&nn.orderid===e.orderid,c=(0,z.Cl)(e.orderstatus),l=e.rider_id||e.userid,d=l?ct.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,n){var s=e.trip_number||1,r=n.trip_number||1;return s!==r?s-r:(e.step||0)-(n.step||0)})).find((function(e){var n=String(e.orderstatus||"").toLowerCase();return!z.Q6.has(n)&&!z.us.has(n)}));return e?e.orderid:null}(),u=o&&e.orderid===o,m=l?Zt(l,e):null;return(0,P.jsxs)("div",{className:"zone-order-card ".concat(a?"clickable":""," ").concat(i?"active":""," ").concat(u?"going-on":""),role:a?"button":void 0,tabIndex:a?0:void 0,onClick:a?function(){return sn(i?null:{orderid:e.orderid,lat:s,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||n+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)(C.pbk,{})}),e.rider_name||e.ridername||"Unassigned"]})]}),function(){var n=Ne(e.deliverytime),s=Ne(e.expecteddeliverytime),r=!z.Q6.has(String(e.orderstatus||"").toLowerCase())&&null!==m;return e.orderstatus||n||s||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}),(n||s)&&(0,P.jsxs)("span",{className:"zone-order-time ".concat(n?"":"is-expected"),title:n?"Delivered at ".concat(n):"Expected at ".concat(s),children:[(0,P.jsx)(C.dKE,{}),n||s]}),r&&(0,P.jsxs)("span",{className:"zone-order-est-drop",title:"Estimated distance to drop location",children:[(0,P.jsx)(C.x$F,{}),Ot(m)]})]}):null}()]}),(0,P.jsxs)("div",{className:"zone-order-customer",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(C.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)(C.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)(C.$0r,{})}),e.deliverysuburb||$(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)(C.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)(C.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||n+1]})]})]},e.orderid)}))})]})]})]}):Qe?(0,P.jsxs)("div",{id:"route-detail",children:[(0,P.jsx)("button",{className:"rd-back",onClick:function(){return Xe(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)(C.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,n){var s=parseFloat(e.droplat||e.deliverylat),r=parseFloat(e.droplon||e.deliverylong),a=Number.isFinite(s)&&Number.isFinite(r),i=nn&&nn.orderid===e.orderid,c=(0,z.Cl)(e.orderstatus),l=e.rider_id||e.userid,d=l?ct.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,n){var s=e.trip_number||1,r=n.trip_number||1;return s!==r?s-r:(e.step||0)-(n.step||0)})).find((function(e){var n=String(e.orderstatus||"").toLowerCase();return!z.Q6.has(n)&&!z.us.has(n)}));return e?e.orderid:null}(),u=o&&e.orderid===o,m=l?Zt(l,e):null;return(0,P.jsxs)("div",{className:"zone-order-card ".concat(a?"clickable":""," ").concat(i?"active":""," ").concat(u?"going-on":""),role:a?"button":void 0,tabIndex:a?0:void 0,onClick:a?function(){return sn(i?null:{orderid:e.orderid,lat:s,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||n+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)(C.pbk,{})}),e.rider_name||e.ridername||"Unassigned"]})]}),function(){var n=Ne(e.deliverytime),s=Ne(e.expecteddeliverytime),r=!z.Q6.has(String(e.orderstatus||"").toLowerCase())&&null!==m;return e.orderstatus||n||s||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}),(n||s)&&(0,P.jsxs)("span",{className:"zone-order-time ".concat(n?"":"is-expected"),title:n?"Delivered at ".concat(n):"Expected at ".concat(s),children:[(0,P.jsx)(C.dKE,{}),n||s]}),r&&(0,P.jsxs)("span",{className:"zone-order-est-drop",title:"Estimated distance to drop location",children:[(0,P.jsx)(C.x$F,{}),Ot(m)]})]}):null}()]}),(0,P.jsxs)("div",{className:"zone-order-customer",children:[(0,P.jsx)(Fe,{children:(0,P.jsx)(C.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)(C.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)(C.$0r,{})}),e.deliverysuburb||$(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)(C.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)(C.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||n+1]})]})]},e.orderid)}))})]})]}):(0,P.jsxs)("div",{id:"riders-panel",children:[!mt&&(0,P.jsx)("div",{className:"ph",children:"zones"===q?"Zone dispatch":"kitchens"===q?"Kitchen dispatch":"all"===q?"Active rider dispatch":"Rider dispatch"}),(0,P.jsx)("div",{id:"rider-cards",children:0!==dt.length||Vr?"zones"===q?at.map((function(e,n){var s=e.statusCounts.delivered||0;return(0,P.jsxs)("div",{className:"rcard zone-card",onClick:function(){return Xe(e)},style:{animationDelay:"".concat(.05*n,"s")},children:[(0,P.jsxs)("div",{className:"zone-card-header",children:[(0,P.jsx)("div",{className:"zone-card-emoji",children:(0,P.jsx)(C.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 n=(0,l.Z)(e,2),s=n[0],r=n[1];return"".concat((0,z.Cl)(s).label,": ").concat(r)})).join(" \xb7 "),children:Object.entries(e.statusCounts).map((function(n){var s=(0,l.Z)(n,2),r=s[0],t=s[1],a=(0,z.Cl)(r),i=t/e.totalOrders*100;return(0,P.jsx)("div",{className:"zone-status-seg",style:{width:"".concat(i,"%"),background:a.bg}},r)}))}),(0,P.jsxs)("div",{className:"zone-progress-label",children:[s,"/",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)(C.$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)(C.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)(C.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"===q?lt.map((function(e,n){return(0,P.jsxs)("div",{className:"rcard",onClick:function(){return Ve(e)},style:{animationDelay:"".concat(.05*n,"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)(C.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)(C.v93,{})}),e.orders.reduce((function(e,n){return e+parseFloat(n.actualkms||n.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 n;return(0,P.jsx)("span",{className:"step-id",style:{color:Dt(e)},children:null===(n=ct.find((function(n){return n.id===e})))||void 0===n?void 0:n.riderName.split(" ")[0]},e)}))})]},e.id)})):mt?(0,P.jsx)(Z,{visibleRiders:ft,riders:ct,resetKey:"".concat(Is,"|").concat(En,"|").concat(Ir),focusedStop:nn,handleRiderFocus:jt,setFocusedStop:sn,calculateEstMeters:Zt,getRiderColor:Dt,formatMeters:Ot,isLoading:Br&&Vr&&0===ft.length}):vt.map((function(e,n){var s,r=e.orders.length,t=e.orders.filter((function(e){return z.Q6.has(String(e.orderstatus||"").toLowerCase())})).length,a=r>0&&t>=r,i=e.orders.find((function(e){var n=String(e.orderstatus||"").toLowerCase();return!z.Q6.has(n)&&!z.us.has(n)})),c=i?Zt(e.id,i):null,l=e.gpsOnly||0===r;return(0,P.jsxs)("div",{className:"rcard".concat(l?" is-gps-only":""),onClick:l?void 0:function(){return jt(e)},style:{animationDelay:"".concat(.05*n,"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)(C.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===(s=e.orders[0])||void 0===s?void 0:s.zone_name)||vs||"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(a?"is-done":""),style:a?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)(C.v93,{})}),e.orders.reduce((function(e,n){return e+parseFloat(n.actualkms||n.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)(C.x$F,{})}),Ot(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,n=null===(e=Gn.find((function(e){return e.id===Ir})))||void 0===e?void 0:e.label,s=Br&&et.length>0;return(0,P.jsxs)("div",{className:"empty-slot",children:[(0,P.jsx)("div",{className:"empty-slot-icon",children:(0,P.jsx)(C.ByW,{})}),(0,P.jsx)("div",{className:"empty-slot-title",children:n?"No orders in ".concat(n):"No orders"}),(0,P.jsx)("div",{className:"empty-slot-sub",children:s?"".concat(et.length," order").concat(1===et.length?"":"s"," exist in other slots today"):"No deliveries found for this date"})]})}()})]})]}),(0,P.jsxs)("div",{id:"map-wrap",className:"".concat("kitchens"===q?"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:Mt||(ut||Ue)&&nn||ut||Ue||Qe,viewMode:q,orders:pt,kitchens:lt,locationKey:En,extraPoints:xt,flyTo:an}),lt.filter((function(e){return Number.isFinite(e.lat)&&Number.isFinite(e.lon)})).filter((function(e){return!ut||e.riders.has(ut.id)})).map((function(e,n){return(0,P.jsx)(p.J,{position:[e.lat,e.lon],icon:Lt(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(n))})),function(){if(er&&ut&&"actual"===tr)return null;var e=dt;Qe&&(e=Qe.orders),Ue&&(e=Ue.orders),ut&&(e=ut.orders),e=e.filter(ee);var n=er&&ut?new Map(wt.map((function(e){return[String(e.deliveryid),e.sequenceStep]}))):null;return e.map((function(s,r){var t,a=s.rider_id,i=!a||qe.has(a),c=Dt(a);if(n&&a===ut.id&&null!=s.deliveryid){var l=n.get(String(s.deliveryid));l&&(c=(0,z.di)(l-1),t=l)}var d=!!ut||!!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=t||s.step||e.indexOf(s)+1,r=32;return b().divIcon({className:"",iconSize:[r,r],iconAnchor:[16,16],popupAnchor:[0,-28],html:'<div class="cmark is-rider-focused'.concat(m?" pulse":"",'" style="background:').concat(c,";width:").concat(r,"px;height:").concat(r,"px;font-size:").concat(n>9?12:14,"px;opacity:").concat(i?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(i?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:a?100:0,ref:function(e){e?un.current[String(s.orderid)]=e:delete un.current[String(s.orderid)]},eventHandlers:{click:function(){var e=String(s.orderid);mn.current.has(e)?(mn.current.delete(e),gn(null)):(mn.current.add(e),gn(s))}}},"".concat(s.orderid,"-").concat(d?"num":"flag"))}))}(),function(){var e=er&&ut&&"actual"===tr;if(As)return e?[]:zs.map((function(e,n){return(0,P.jsx)(h.a,{positions:[e.from,e.to],pathOptions:{color:e.color,weight:6,opacity:.9,lineJoin:"round",lineCap:"round"}},n)}));var n=[],s=Qe?new Set(Qe.riders.map((function(e){return String(e.rider_id)}))):null;return e||vt.forEach((function(e){var r=qe.has(e.id);if((!ut||ut.id===e.id)&&(!Ue||Ue.riders.has(e.id))&&(!s||s.has(String(e.id)))){var a=mt?(0,z.P0)(e.orders):null,i=mt?a?[a]:[]:e.orders;if(!mt||0!==i.length){var c={};i.forEach((function(e){var n=e.trip_number||1;c[n]||(c[n]=[]),c[n].push(e)})),Object.entries(c).forEach((function(s){var a=(0,l.Z)(s,2),i=a[0],c=a[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(i),m=js[o],p=(0,t.Z)(d).sort((function(e,n){return(e.step||0)-(n.step||0)})),v=r?1:.1,f="kitchens"===q||Ue?7:6,x=er&&ut&&e.id===ut.id;if(!x){var j=[],g=!1;if(p.forEach((function(e){if(null!=e.deliveryid&&""!==e.deliveryid&&0!==e.deliveryid){var n=String(e.deliveryid),s=ks[n],r=_t.get(n),a=null;if(Array.isArray(s)&&s.length>=2?a=s:r&&r.coords.length>=2&&(a=r.coords.map((function(e){return[e.lat,e.lng]}))),a)if(g=!0,0===j.length)j.push.apply(j,(0,t.Z)(a));else{var i=j[j.length-1],c=a[0],l=Math.abs(i[0]-c[0])<1e-5&&Math.abs(i[1]-c[1])<1e-5;j.push.apply(j,(0,t.Z)(l?a.slice(1):a))}}})),g&&j.length>=2)return void n.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(i,"-actual")))}var N=mt?p[0]:null,b=null;if(mt&&N){var y=Zr.find((function(n){return String(n.id)===String(e.id)})),k=y&&Number.isFinite(y.lat)&&Number.isFinite(y.lon)?[y.lat,y.lon]:re(N)?[X(ne(N)),X(se(N))]:null,S=X(N.droplat||N.deliverylat),_=X(N.droplon||N.deliverylong);k&&Number.isFinite(S)&&Number.isFinite(_)&&(b=[k,[S,_]])}var w=mt?N?js["".concat(e.id,"-active-").concat(N.orderid)]:void 0:m,F=Array.isArray(w)&&w.length>=2,A=!1===w;if(mt||F||A){var E=F?w:mt?b:ye(p);if(E&&!(E.length<2)){var C=er&&ut&&e.id===ut.id,M=A?"8 6":C&&"combined"===tr?"6 5":void 0;if(x){var R,L=new Map(wt.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(E,Z);else{var O=E.length>Z.length;R=[];for(var T=0;T<Z.length;T++){var I=O?T:T-1,H=O?T+1:T;I<0||I>=E.length||H>=E.length?R.push([]):R.push([E[I],E[H]])}}var K="combined"===tr?5:0;return n.push((0,P.jsx)(h.a,{positions:E,pathOptions:{color:"#ffffff",weight:f+4,opacity:.5*v,lineJoin:"round",lineCap:"round",offset:K}},"".concat(e.id,"-").concat(i,"-halo"))),void R.forEach((function(s,r){if(s&&!(s.length<2)){var t=D[r],a=t?L.get(String(t.deliveryid)):null,c="combined"===tr?J:a?(0,z.di)(a-1):e.color,l=null!=Mr&&Mr===a,d=l?f+1.5:f,o=l?1:Mr?.5*v:v;n.push((0,P.jsx)(h.a,{positions:s,pathOptions:{color:c,weight:d,opacity:o,lineJoin:"round",lineCap:"round",dashArray:M,offset:K}},"".concat(e.id,"-").concat(i,"-step-").concat(r,"-").concat((null===t||void 0===t?void 0:t.deliveryid)||r)))}}))}n.push((0,P.jsxs)(u.Fragment,{children:[(0,P.jsx)(h.a,{positions:E,pathOptions:{color:"#ffffff",weight:f+4,opacity:.5*v,lineJoin:"round",lineCap:"round"}}),(0,P.jsx)(h.a,{positions:E,pathOptions:{color:e.color,weight:f,opacity:v,lineJoin:"round",lineCap:"round",dashArray:M}})]},"".concat(e.id,"-").concat(i)))}}}}))}}})),n}(),Zr.filter((function(e){return mt?("active"===e.status||"pending"===e.status)&&ht.has(String(e.id)):ct.some((function(n){return String(n.id)===String(e.id)}))})).filter((function(e){return!ut||String(ut.id)===String(e.id)})).map((function(e){var n,s="active"===e.status||"pending"===e.status,r=s?"#16a34a":"#dc2626",t=ct.find((function(n){return String(n.id)===String(e.id)})),a=null===t||void 0===t||null===(n=t.orders)||void 0===n?void 0:n.slice().sort((function(e,n){var s=e.trip_number||1,r=n.trip_number||1;return s!==r?s-r:(e.step||0)-(n.step||0)})).find((function(e){var n=String(e.orderstatus||"").toLowerCase();return!z.Q6.has(n)&&!z.us.has(n)})),i=a?a.deliverysuburb||$(a.deliveryaddress):null,c=(e.username||"").replace(/[<>&"']/g,""),l=e.orderid?String(e.orderid).replace(/[<>&"']/g,""):"",d="".concat(mt?"bike":"pin","|").concat(r,"|").concat(c,"|").concat(l,"|").concat(s?1:0),u=hn.current.get(e.id);u&&u.sig===d||(u={sig:d,icon:mt?b().divIcon({className:"",iconSize:[160,44],iconAnchor:[22,22],popupAnchor:[0,-22],html:'<div class="live-rider-bike '.concat(s?"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>")})},hn.current.set(e.id,u));var m=u.icon,h={click:function(n){var s=String(e.id);pn.current.has(s)?(pn.current.delete(s),n.target.closePopup()):(pn.current.add(s),n.target.openPopup());var r=ct.find((function(e){return String(e.id)===s}));r&&jt(r)},popupclose:function(){pn.current.delete(String(e.id))}},v=mt?we:p.J,f=mt?{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)(C.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]})]}),a&&(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:["#",a.step||"?"," \xb7 ",a.deliverycustomer||"\u2014"]})]}),i&&(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:a.deliveryaddress||i,children:i})]}),(null===a||void 0===a?void 0:a.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:a.pickupcustomer,children:a.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)(C.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&&ut&&"planned"!==tr&&wt.map((function(e,n){var s,r;if(0===e.coords.length)return null;var t=(0,z.di)(n),a="combined"===tr?Q:t,i=[e.coords[0].lat,e.coords[0].lng],c=[e.coords[e.coords.length-1].lat,e.coords[e.coords.length-1].lng],l=ks[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(As){var v=Ds[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=Ft.find((function(n){return n.sequenceStep===e.sequenceStep})),k=!(null===y||void 0===y||!y.anomaly),_=null===ut||void 0===ut||null===(s=ut.orders)||void 0===s?void 0:s.find((function(n){return null!=n.deliveryid&&String(n.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>",E=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(n){n.originalEvent&&n.originalEvent.stopPropagation(),zr((function(n){return n===e.sequenceStep?null:e.sequenceStep})),_&&n.target&&"function"===typeof n.target.openPopup&&n.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:a,weight:f?6.5:5,opacity:f?1:Mr?.55:.95,lineJoin:"round",lineCap:"round",offset:D}}),M&&(0,P.jsx)(p.J,{position:i,icon:R,zIndexOffset:f?900:100,eventHandlers:{click:function(n){n.originalEvent&&n.originalEvent.stopPropagation(),zr((function(n){return n===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)(C.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:E,zIndexOffset:f?1e3:200,eventHandlers:_?{mouseover:function(){vn.current&&(clearTimeout(vn.current),vn.current=null),gn(_)},mouseout:function(){Mr!==e.sequenceStep&&(vn.current&&clearTimeout(vn.current),vn.current=setTimeout((function(){gn((function(e){return e&&String(e.orderid)===String(_.orderid)?null:e})),vn.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 n=(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:n.bg,color:n.fg},children:n.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&&ut&&(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 ar("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 ar("planned")},title:"Show only the dispatched planned route",children:"Planned"}),(0,P.jsx)("button",{type:"button",className:"combined"===tr?"is-active":"",onClick:function(){return ar("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(As?"active":""),onClick:function(){if(As)return Es(!1),Ps([]),void Zs({});Es(!0),Ps([]),Zs({});var e=er&&ut,n=e?new Map(wt.map((function(e){return[String(e.deliveryid),e.sequenceStep]}))):null,s=[];if(ct.forEach((function(r){if(qe.has(r.id)&&(!ut||ut.id===r.id)&&(!Ue||Ue.riders.has(r.id))){var a=mt?(0,z.P0)(r.orders):null,i=a&&"active"===String(a.orderstatus||"").toLowerCase(),c=mt?i?[a]:[]:r.orders,d={};c.forEach((function(e){var n=e.trip_number||1;d[n]||(d[n]=[]),d[n].push(e)})),Object.entries(d).forEach((function(a){var i=(0,l.Z)(a,2),c=i[0],d=i[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=mt?"".concat(r.id,"-active-").concat(o[0].orderid):"".concat(r.id,"-").concat(c),m=js[u],p=(0,t.Z)(o).sort((function(e,n){return(e.step||0)-(n.step||0)})),h=null;if(mt&&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)?[X(ne(v)),X(se(v))]:null,j=X(v.droplat||v.deliverylat),g=X(v.droplon||v.deliverylong);x&&Number.isFinite(j)&&Number.isFinite(g)&&(h=[x,[j,g]])}var N=mt?h||[]:ye(p),b="kitchens"===q||Ue,y=m||N;if(!(y.length<2)){var k=function(){return r.color};if(e&&r.id===ut.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,n=[],s=0;s<S.length;s++){var r=e?s:s-1,t=e?s+1:s;r<0||r>=N.length||t>=N.length?n.push([]):n.push([N[r],N[t]])}return n}(),w=[],F=0;_.forEach((function(e,n){for(var s=Math.max(0,((null===e||void 0===e?void 0:e.length)||0)-1),r=0;r<s;r++)w[F+r]=n;F+=s})),k=function(e){var s=w[e];if(null==s)return r.color;var t=p.filter(ee)[s],a=t?n.get(String(t.deliveryid)):null;return a?(0,z.di)(a-1):r.color}}for(var A=0;A<y.length-1;A++)s.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)})}}}))}})),s.sort((function(e,n){return e.delay-n.delay})),s.forEach((function(e,n){setTimeout((function(){Ps((function(n){return[].concat((0,t.Z)(n),[e])})),n===s.length-1&&setTimeout((function(){Es(!1),Zs({})}),1e3)}),e.delay)})),e&&wt.length>0){var r=(0,t.Z)(wt),a=r.map((function(e){var n=ks[e.deliveryid];return Array.isArray(n)&&n.length>=2?n:e.coords.map((function(e){return[e.lat,e.lng]}))})),i=s.length>0?s[s.length-1].delay:800*r.length,c=Math.max(i,600*r.length),d=c/Math.max(1,r.length),o=Date.now();requestAnimationFrame((function e(){if(Os.current){var n=Date.now()-o,s={};r.forEach((function(e,r){var t=a[r];if(t&&!(t.length<2)){var i=r*d;if(n>=i+d)s[e.sequenceStep]=t.length;else if(n>=i){var c=(n-i)/d;s[e.sequenceStep]=Math.max(2,Math.ceil(c*t.length))}}})),Zs(s),n<c+200&&requestAnimationFrame(e)}}))}},style:{boxShadow:"var(--shadow-lg)",background:As?"var(--accent)":"#fff"},children:[(0,P.jsx)("span",{children:As?"\u23f9":"\u25b6"})," ",As?"Stop":"Animate Routes"]})})]}),er&&ut&&(0,P.jsx)("div",{id:"compare-map-wrap",children:function(){var e=wt.length,n=wt.filter((function(e){return e.coords.length>0})).length,s=wt.filter((function(e){return e.isLoading})).length,r=e>0?Math.round(n/e*100):0,t=e>0&&n===e&&0===s,a=null!=Mr?Ft.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:ut.color}}),(0,P.jsx)("span",{className:"compare-title-name",children:ut.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)(C.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)(C.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:Et.map((function(e,n){var s,r=String(e.orderstatus||"").toLowerCase(),t=z.Q6.has(r),a=z.us.has(r),i=Mr===e.sequenceStep,c=e.isLoading&&0===e.coordsCount,l=!e.isLoading&&0===e.coordsCount,d=(null===(s=e.order)||void 0===s?void 0:s.step)||e.sequenceStep,o=(0,z.di)(d-1),m=["compare-step",i&&"is-focused",t&&"is-delivered",a&&"is-skipped",!t&&!a&&"is-pending",c&&"is-loading",l&&"is-no-data",e.anomaly&&"is-anomaly"].filter(Boolean).join(" ");return(0,P.jsxs)(u.Fragment,{children:[n>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(n){return n===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:Ct.map((function(e,n){var s,r=String(e.orderstatus||"").toLowerCase(),t=z.Q6.has(r),a=z.us.has(r),i=Mr===e.sequenceStep,c=e.isLoading&&0===e.coordsCount,l=!e.isLoading&&0===e.coordsCount,d=(null===(s=e.order)||void 0===s?void 0:s.step)||e.sequenceStep,o=(0,z.di)(d-1),m=["compare-step",i&&"is-focused",t&&"is-delivered",a&&"is-skipped",!t&&!a&&"is-pending",c&&"is-loading",l&&"is-no-data",e.anomaly&&"is-anomaly"].filter(Boolean).join(" ");return(0,P.jsxs)(u.Fragment,{children:[n>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(n){return n===e.sequenceStep?null:e.sequenceStep}))},title:"Actual Visit ".concat(n+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:s>0?"Loading GPS\u2026 ".concat(n,"/").concat(e):"".concat(n,"/").concat(e," tracks")})]})]}),function(){var e="combined"===tr,n=a?(0,z.di)(a.sequenceStep-1):"linear-gradient(90deg, ".concat(z.XZ.slice(0,6).join(", "),")"),s=e?J:n,r=e?Q:n;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:s}}),"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&&ut&&(0,P.jsx)(R,{focusedRider:ut,compareDeltas:Ft,compareSummary:At,actualOrdered:Ct,focusedCompareStep:Mr,setFocusedCompareStep:zr,sequenceOpen:lr,setSequenceOpen:dr,expandedSeqGroups:fr,setExpandedSeqGroups:xr,onClose:function(){return nr(!1)}})]}),jn&&(0,P.jsx)("div",{className:"dispatch-popup-center",role:"dialog","aria-label":"Order ".concat(jn.orderid," details"),onMouseEnter:function(){vn.current&&(clearTimeout(vn.current),vn.current=null)},onMouseLeave:function(){(function(e){if(!e)return!1;if(mn.current.has(String(e.orderid)))return!0;if(er&&ut&&null!=e.deliveryid){var n=wt.find((function(n){return String(n.deliveryid)===String(e.deliveryid)}));if(n&&Mr===n.sequenceStep)return!0}return!1})(jn)||(vn.current&&clearTimeout(vn.current),vn.current=setTimeout((function(){gn(null),vn.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(){mn.current.delete(String(jn.orderid)),gn(null)},children:"\xd7"}),function(e){var n=(0,z.Cl)(e.orderstatus),s=e.rider_id||e.userid,r=z.Q6.has(String(e.orderstatus||"").toLowerCase())?null:Zt(s,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:n.bg,color:n.fg},children:n.label})]}),(0,P.jsxs)("div",{className:"pu-header-main",children:[(0,P.jsxs)("div",{className:"pu-header-left",children:[(0,P.jsxs)("div",{className:"pu-rider",children:[(0,P.jsx)(C.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)(C.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]})]}),null!=e.step&&(0,P.jsxs)("div",{className:"pu-header-step",children:[(0,P.jsx)("span",{className:"pu-header-step-label",children:"Step"}),(0,P.jsxs)("span",{className:"pu-header-step-value",children:[null!=e.trip_number&&e.trip_number>1?"T".concat(e.trip_number,"\xb7"):"",e.step]})]})]})]}),(0,P.jsxs)("div",{className:"pu-body",children:[be.some((function(n){return e[n.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(n){var s=Ne(e[n.key]);return s?(0,P.jsxs)("div",{className:"pu-tl-row ".concat(n.final?"delivered":""),children:[(0,P.jsx)("span",{className:"pu-tl-dot"}),(0,P.jsx)("span",{className:"pu-tl-label",children:n.label}),(0,P.jsx)("span",{className:"pu-tl-time",children:s})]},n.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)(C.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)(C.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||$(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)(C.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)(C.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.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)(C.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)(C.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)(C.x$F,{})}),(0,P.jsx)("span",{className:"pu-distance-label",children:"Est. to Drop"}),(0,P.jsx)("span",{className:"pu-distance-value",children:Ot(r)})]})]})]})]})]})}(jn)]})})]}),!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 n,s=G[e.key],r=pe===e.key,t=!1===(null===s||void 0===s||null===(n=s.data)||void 0===n?void 0:n.success),a=t?"#fee2e2":s?"".concat(e.color,"22"):"#f1f5f9",i=t?"#dc2626":s?e.color:"#64748b",c=r?"Loading\u2026":t?"! Failed":s?"\u2713 ".concat(s.fetchedAt):"Fetch",l=Pe===e.key;return(0,P.jsxs)("button",{type:"button",className:"da-picker ".concat(s?"has-data":""," ").concat(r?"is-loading":""," ").concat(l?"is-active":""),onClick:function(){return!r&&De(e.key)},style:{borderColor:l?e.color:t?"#fecaca":s?e.border:"#e2e8f0",background:t?"#fef2f2":s?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:a,color:i},children:c})]}),(0,P.jsx)("div",{className:"da-picker-sub",children:e.sub})]},e.key)}))}),function(){var e,n,s,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})),a=G[Pe],i=pe===Pe;if(i&&!a)return(0,P.jsxs)("div",{className:"da-empty",children:["Loading ",t.label," batch\u2026"]});if(!a)return null;var c,l,d=a.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 ",a.fetchedAt]})]}),(0,P.jsx)("button",{type:"button",className:"da-result-refresh",title:"Retry",onClick:function(){return De(Pe)},disabled:i,style:{background:"#fee2e2",color:"#dc2626"},children:(0,P.jsx)(C.la_,{})})]}),(0,P.jsxs)("div",{className:"da-error",children:[(0,P.jsxs)("div",{className:"da-error-title",children:[(0,P.jsx)(C.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:Ee(u.total_orders)},{label:"Total Riders",value:Ee(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 ",a.fetchedAt," \xb7 Input deliveries: ",null!==(n=d.input_delivery_count)&&void 0!==n?n:"\u2014"]})]}),(0,P.jsx)("button",{type:"button",className:"da-result-refresh",title:"Refresh",onClick:function(){U((function(e){var n=(0,o.Z)({},e);return delete n[Pe],n})),Le.mutate({batch:Pe,tenantId:916})},disabled:i,style:{background:"".concat(t.color,"22"),color:t.color},children:(0,P.jsx)(C.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)(C.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===(s=h.activate_when)||void 0===s||null===(r=s.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,n){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]})]},n)}))]})]})]}):(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)(C.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 n="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)(C.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(n?"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)(C.TkG,{})," ",e.kitchen]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(C.ByW,{})," ",e.order_count," orders"]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(C.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)(C.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,n){var s,r=e.idle_rider||{},t=e.most_relieved_rider||{},a=null!==(s=e.fleet_improvement_minutes)&&void 0!==s?s: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:a>0?{background:"#dcfce7",color:"#166534"}:{background:"#f1f5f9",color:"#475569"},children:["Fleet ",a>0?"\u2191":"\u2022"," ",a," min"]})]}),(0,P.jsxs)("div",{className:"da-sub-meta",children:[(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(C.v93,{})," ",e.travel_to_kitchen_km," km"]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(C.Vqd,{})," ",e.travel_to_kitchen_minutes," min travel"]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(C.dKE,{})," arrives ",e.arrive_at_kitchen]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(C.ByW,{})," ",e.total_orders_transferred," orders"]}),(0,P.jsxs)("span",{className:"da-chip",children:[(0,P.jsx)(C.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)(C.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 n,s=null!==(n=e.improvement_minutes)&&void 0!==n?n: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:s>0?{background:"#dcfce7",color:"#166534"}:s<0?{background:"#fee2e2",color:"#991b1b"}:{background:"#f1f5f9",color:"#475569"},children:[s>0?"+":"",s," min"]})]},e.deliveryid)}))]})]},n)}))})]})]})}()]})]})}},29127:function(e,n,s){s.d(n,{Cl:function(){return a},P0:function(){return d},Q6:function(){return i},XZ:function(){return o},Y_:function(){return l},di:function(){return u},us:function(){return c},xw:function(){return m}});var r=s(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"}},a=function(e){return t[String(e||"").toLowerCase()]||{label:e||"Unknown",bg:"#64748b",fg:"#fff"}},i=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,n){var s=e.trip_number||1,r=n.trip_number||1;return s!==r?s-r:(e.step||0)-(n.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 n=["th","st","nd","rd"],s=e%100;return e+(n[(s-20)%10]||n[s]||n[0])}}}]); |