1import{a as b,j as a}from"./vendor-BEUer1XH.js";import{b as F,g as C}from"./hub.api-Bt2XcAHO.js";import{u as v}from"./useQuery-CwENCggL.js";import{u as g}from"./useMutation-DE8xRGOj.js";import{L}from"./index-D9B8gFZC.js";import{L as N}from"./LoadingOutlined-NBYGflZN.js";import{m as O,l as E,F as de,D as I,i as me,k as ue}from"./format.date-CBT9wA-H.js";import{d as u,i as ce}from"./utils-Chrmq4rh.js";import{i as pe}from"./transport.api-BZy1zftv.js";import{g as he,A as M,a as fe,b as ye,c as _e}from"./datetime-BSbnrEvZ.js";import{M as be}from"./index-m0orFJWU.js";import{D as ge,T as De,B as xe}from"./index-CQA33AYy.js";import{F as p}from"./index-xbWzNeya.js";import{C as Se}from"./index-CJbWHbmU.js";import{S as R}from"./index-BZ2ty84A.js";import{S as k}from"./index-CeQCkKEx.js";import{D as Te}from"./index-DduVooXF.js";import"./index-dcRtSBKe.js";import"./index-fQRrFeNQ.js";import"./index-CC7xf1H6.js";import"./index-EQzNeqiQ.js";import"./EyeOutlined-CasV3VaN.js";import"./addEventListener-DapjV_MG.js";import"./LeftOutlined-BK0A0DBY.js";import"./RightOutlined-Q5JtFw_t.js";import"./image.sizes-tLP2hyyi.js";import"./TagsOutlined-DgaMTu4w.js";import"./messages-CBPyb3Vq.js";import"./download-D4OUWEYP.js";import"./index-DOaOBQcF.js";import"./collapse-BbEVqHco.js";import"./useForm-BtRpPDI1.js";import"./useBreakpoint-BlY8Qvla.js";import"./mediaQueryUtil-BSyvLspT.js";import"./Overflow-BNbYSUml.js";import"./PurePanel-BQufqbuG.js";import"./DownOutlined-DxUjWW0U.js";import"./SearchOutlined-BadKGrHj.js";import"./index-CUWDS_la.js";import"./weekday-DCQWGhN8.js";import"./ClockCircleOutlined-DY-N4vPG.js";const{Title:q}=De,ct=()=>{var H;const{notification:w}=ge.useApp(),[h]=p.useForm(),[D,x]=b.useState({}),[S,T]=b.useState({}),[j,P]=b.useState(""),y=p.useWatch(["same_day_delivery"],h),{data:B,isLoading:V}=v({queryKey:["hubs_origin",D],queryFn:()=>C(D||{}),select:e=>e.hubs,retry:0,placeholderData:e=>e}),{data:U,isLoading:z}=v({queryKey:["hubs_destination",S],queryFn:()=>C(S||{}),select:e=>e.hubs,retry:0,placeholderData:e=>e}),{data:c,mutate:G}=g({mutationFn:e=>F(e)}),{data:_,mutate:K}=g({mutationFn:e=>F(e)}),W=e=>{x(t=>({...t,search:e}))},Y=e=>{G(e)},Q=e=>{T(t=>({...t,search:e}))},$=e=>{K(e)},J=e=>{const t=e.target.checked;x(s=>({...s,filter:{...s==null?void 0:s.filter,same_day_delivery:t?"origin":void 0}})),T(s=>({...s,filter:{...s==null?void 0:s.filter,same_day_delivery:t?"destination":void 0}})),h.setFieldValue("origin_hub_id",void 0),h.setFieldValue("destination_hub_id",void 0),h.setFieldValue("drop_off_at",void 0)},X=(e,t)=>{const s=e.hub_hours.map(i=>i.day),r=t.hub_hours.map(i=>i.day),l=e.hub_groups.flatMap(i=>i.delivery_days).filter((i,o,m)=>m.indexOf(i)===o),n=t.hub_groups.flatMap(i=>i.delivery_days).filter((i,o,m)=>m.indexOf(i)===o),d=[];return l.map(i=>{if(n.includes(i)){const o=I[Number(i)].label.toLocaleLowerCase();s.includes(o)&&r.includes(o)&&d.push(o)}}),d};function Z(e,t,s){if(!e)return!1;const r=u().subtract(1,"day"),l=e.format("dddd").toLowerCase(),n=e&&e<r,d=e.isSame(u(),"day");if(n)return!0;if(t&&s){const i=[...t.holiday_infos,...s.holiday_infos];if(i.length>0&&_e({holidays:i,current:e}),d){const o=t.hub_hours.find(m=>m.day===l);if(o)if(y){const[m]=o.open_hour.toString().split(":").map(Number);return!(u().hour()<=m)}else{const[m]=o.close_hour.toString().split(":").map(Number);return!(u().hour()<m)}}if(y){const o=X(t,s);if(o.length>0)return!o.includes(l)}else return!t.hub_hours.map(o=>o.day).includes(l)}return n}function ee(e,t){if(!e)return M;const s=u(),r=e.format("dddd").toLowerCase(),l=e.isSame(s,"day");if(t){const n=t.find(o=>o.day===r);if(!n||!n.open_hour||!n.close_hour)return M;const d=n.open_hour,[i]=n.close_hour.toString().split(":").map(Number);return{disabledHours:()=>ye({isSameDay:y,isToday:l,openTime:d,closeHour:i,today:s}),disabledMinutes:o=>fe({selectedHour:o,today:s,isToday:l,isSameDay:y,openTime:d})}}return{}}const te=(e,t)=>{var s,r;if(t.subType==="minute"&&typeof e=="number")return a.jsx("div",{className:"ant-picker-time-panel-cell-inner",children:e});if(typeof e=="number"&&j){const l={color:"hsl(var(--secondary))",fontWeight:"bold"},n=u(j),d=I[n.day()].label.toLocaleLowerCase(),i=(r=(s=c==null?void 0:c.hub.hub_hours)==null?void 0:s.find(le=>le.day===d))==null?void 0:r.open_hour;if(!i)return a.jsx("div",{className:"ant-picker-time-panel-cell-inner",children:e});const{openHour:o,cutoffHour:m}=he(i),f=u(),ne=n.isSame(f,"day")?f.hour()<o?o:f.hour()+1:o,re=e>=ne&&e<=m;return a.jsx("div",{className:"ant-picker-time-panel-cell-inner",style:re?l:{},children:e})}return t.originNode},ae=e=>{var t;if(!Array.isArray(e)){const s=me+"T"+ue,r=(t=u(e))==null?void 0:t.format(s);P(r)}},{data:A,mutate:se,isPending:ie}=g({mutationFn:e=>pe(e),onSettled:(e,t)=>{var s,r,l,n,d;if(t&&ce(t)){let i=t==null?void 0:t.message;(r=(s=t==null?void 0:t.response)==null?void 0:s.data)!=null&&r.error&&(i=(d=(n=(l=t==null?void 0:t.response)==null?void 0:l.data)==null?void 0:n.details)==null?void 0:d.message),w.error({message:i})}}}),oe=e=>{e&&(e.drop_off_at=u(e.drop_off_at).format(de),se(e))};return a.jsxs(a.Fragment,{children:[a.jsx(be,{title:"ETA Calculator",shouldIndex:!0}),a.jsx("section",{className:"container py-6 my-8",children:a.jsxs("div",{className:"mx-auto max-w-screen-sm",children:[a.jsx("div",{className:"text-center",children:a.jsx(q,{level:3,children:"ETA Calculator"})}),a.jsxs(p,{form:h,layout:"vertical",requiredMark:!1,autoComplete:"off",initialValues:{same_day_delivery:!1},onFinish:oe,children:[a.jsx(p.Item,{name:"same_day_delivery",valuePropName:"checked",children:a.jsx(Se,{onChange:J,children:a.jsx("strong",{className:"text-sm",children:"Same day delivery ?"})})}),a.jsx(p.Item,{name:"origin_hub_id",label:"Origin hub:",rules:[{required:!0,message:"This field is required"}],children:a.jsx(R,{options:(B||[]).map(e=>({...e,key:e.id,value:e.id,label:a.jsx(L,{option:e}),title:e.name})),onSearch:W,filterOption:!1,notFoundContent:V?a.jsx(k,{indicator:a.jsx(N,{spin:!0})}):null,placeholder:"Search hub by name, zipcode, city, or address",defaultActiveFirstOption:!0,showSearch:!0,optionLabelProp:"label",listItemHeight:100,listHeight:400,style:{height:"3.5rem"},onSelect:Y,allowClear:!0})}),a.jsx(p.Item,{name:"destination_hub_id",label:"Destination hub:",rules:[{required:!0,message:"This field is required"}],children:a.jsx(R,{options:(U||[]).map(e=>({...e,key:e.id,value:e.id,label:a.jsx(L,{option:e}),title:e.name})),onSearch:Q,filterOption:!1,notFoundContent:z?a.jsx(k,{indicator:a.jsx(N,{spin:!0})}):null,placeholder:"Search hub by name, zipcode, city, or address",defaultActiveFirstOption:!0,showSearch:!0,optionLabelProp:"label",listItemHeight:100,listHeight:400,style:{height:"3.5rem"},onSelect:$,allowClear:!0})}),a.jsx(p.Item,{label:"Select drop off date & time",name:"drop_off_at",rules:[{required:!0,message:"This field is required"}],children:a.jsx(Te,{disabled:!c&&!_,className:"w-full",showTime:{defaultValue:u().startOf("day").hour(0).minute(0),format:O,minuteStep:30,use12Hours:!1},cellRender:te,disabledDate:e=>Z(e,c==null?void 0:c.hub,_==null?void 0:_.hub),disabledTime:e=>ee(e,c==null?void 0:c.hub.hub_hours),onCalendarChange:e=>{ae(e)},placeholder:"Select drop off date and time",format:`${E+" "+O}`,needConfirm:!1})}),a.jsx(p.Item,{className:"text-right",children:a.jsx(xe,{htmlType:"submit",type:"primary",loading:ie,children:"Calculate"})})]}),A&&a.jsxs("div",{className:"p-4 text-right bg-[#e4e4e4]",children:[a.jsx("p",{children:"Result:"}),a.jsx(q,{level:4,style:{marginBottom:0},children:u((H=A.data.eta)==null?void 0:H.split(".")[0]).format(E)})]})]})})]})};export{ct as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.