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