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