UNPKG

jetsetgo_departure-selection

Version:

A reusable departure selection component for travel booking applications

31 lines (28 loc) 31 kB
(function(D,T){typeof exports=="object"&&typeof module<"u"?T(exports,require("react"),require("framer-motion"),require("lucide-react"),require("clsx"),require("tailwind-merge"),require("date-fns"),require("zustand")):typeof define=="function"&&define.amd?define(["exports","react","framer-motion","lucide-react","clsx","tailwind-merge","date-fns","zustand"],T):(D=typeof globalThis<"u"?globalThis:D||self,T(D.DepartureSelection={},D.React,D.framer,D.lucide,D.clsx,D.tailwindMerge,D.dateFns,D.zustand))})(this,function(D,T,W,$,Qe,et,re,tt){"use strict";var je={exports:{}},se={};/** * @license React * react-jsx-runtime.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var ke;function rt(){if(ke)return se;ke=1;var n=T,u=Symbol.for("react.element"),o=Symbol.for("react.fragment"),c=Object.prototype.hasOwnProperty,i=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,s={key:!0,ref:!0,__self:!0,__source:!0};function x(g,b,C){var w,R={},I=null,J=null;C!==void 0&&(I=""+C),b.key!==void 0&&(I=""+b.key),b.ref!==void 0&&(J=b.ref);for(w in b)c.call(b,w)&&!s.hasOwnProperty(w)&&(R[w]=b[w]);if(g&&g.defaultProps)for(w in b=g.defaultProps,b)R[w]===void 0&&(R[w]=b[w]);return{$$typeof:u,type:g,key:I,ref:J,props:R,_owner:i.current}}return se.Fragment=o,se.jsx=x,se.jsxs=x,se}var oe={};/** * @license React * react-jsx-runtime.development.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var Pe;function nt(){return Pe||(Pe=1,process.env.NODE_ENV!=="production"&&function(){var n=T,u=Symbol.for("react.element"),o=Symbol.for("react.portal"),c=Symbol.for("react.fragment"),i=Symbol.for("react.strict_mode"),s=Symbol.for("react.profiler"),x=Symbol.for("react.provider"),g=Symbol.for("react.context"),b=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),w=Symbol.for("react.suspense_list"),R=Symbol.for("react.memo"),I=Symbol.for("react.lazy"),J=Symbol.for("react.offscreen"),G=Symbol.iterator,O="@@iterator";function _e(e){if(e===null||typeof e!="object")return null;var r=G&&e[G]||e[O];return typeof r=="function"?r:null}var B=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function _(e){{for(var r=arguments.length,a=new Array(r>1?r-1:0),l=1;l<r;l++)a[l-1]=arguments[l];A("error",e,a)}}function A(e,r,a){{var l=B.ReactDebugCurrentFrame,m=l.getStackAddendum();m!==""&&(r+="%s",a=a.concat([m]));var h=a.map(function(f){return String(f)});h.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,h)}}var we=!1,U=!1,xe=!1,M=!1,le=!1,ne;ne=Symbol.for("react.module.reference");function Se(e){return!!(typeof e=="string"||typeof e=="function"||e===c||e===s||le||e===i||e===C||e===w||M||e===J||we||U||xe||typeof e=="object"&&e!==null&&(e.$$typeof===I||e.$$typeof===R||e.$$typeof===x||e.$$typeof===g||e.$$typeof===b||e.$$typeof===ne||e.getModuleId!==void 0))}function K(e,r,a){var l=e.displayName;if(l)return l;var m=r.displayName||r.name||"";return m!==""?a+"("+m+")":a}function ue(e){return e.displayName||"Context"}function k(e){if(e==null)return null;if(typeof e.tag=="number"&&_("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof e=="function")return e.displayName||e.name||null;if(typeof e=="string")return e;switch(e){case c:return"Fragment";case o:return"Portal";case s:return"Profiler";case i:return"StrictMode";case C:return"Suspense";case w:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case g:var r=e;return ue(r)+".Consumer";case x:var a=e;return ue(a._context)+".Provider";case b:return K(e,e.render,"ForwardRef");case R:var l=e.displayName||null;return l!==null?l:k(e.type)||"Memo";case I:{var m=e,h=m._payload,f=m._init;try{return k(f(h))}catch{return null}}}return null}var L=Object.assign,Y=0,he,ce,V,S,X,Z,ve;function ge(){}ge.__reactDisabledLog=!0;function Te(){{if(Y===0){he=console.log,ce=console.info,V=console.warn,S=console.error,X=console.group,Z=console.groupCollapsed,ve=console.groupEnd;var e={configurable:!0,enumerable:!0,value:ge,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}Y++}}function Ee(){{if(Y--,Y===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:L({},e,{value:he}),info:L({},e,{value:ce}),warn:L({},e,{value:V}),error:L({},e,{value:S}),group:L({},e,{value:X}),groupCollapsed:L({},e,{value:Z}),groupEnd:L({},e,{value:ve})})}Y<0&&_("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var de=B.ReactCurrentDispatcher,fe;function Q(e,r,a){{if(fe===void 0)try{throw Error()}catch(m){var l=m.stack.trim().match(/\n( *(at )?)/);fe=l&&l[1]||""}return` `+fe+e}}var q=!1,p;{var j=typeof WeakMap=="function"?WeakMap:Map;p=new j}function H(e,r){if(!e||q)return"";{var a=p.get(e);if(a!==void 0)return a}var l;q=!0;var m=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var h;h=de.current,de.current=null,Te();try{if(r){var f=function(){throw Error()};if(Object.defineProperty(f.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(f,[])}catch(N){l=N}Reflect.construct(e,[],f)}else{try{f.call()}catch(N){l=N}e.call(f.prototype)}}else{try{throw Error()}catch(N){l=N}e()}}catch(N){if(N&&l&&typeof N.stack=="string"){for(var d=N.stack.split(` `),E=l.stack.split(` `),v=d.length-1,y=E.length-1;v>=1&&y>=0&&d[v]!==E[y];)y--;for(;v>=1&&y>=0;v--,y--)if(d[v]!==E[y]){if(v!==1||y!==1)do if(v--,y--,y<0||d[v]!==E[y]){var F=` `+d[v].replace(" at new "," at ");return e.displayName&&F.includes("<anonymous>")&&(F=F.replace("<anonymous>",e.displayName)),typeof e=="function"&&p.set(e,F),F}while(v>=1&&y>=0);break}}}finally{q=!1,de.current=h,Ee(),Error.prepareStackTrace=m}var ie=e?e.displayName||e.name:"",te=ie?Q(ie):"";return typeof e=="function"&&p.set(e,te),te}function P(e,r,a){return H(e,!1)}function ee(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function be(e,r,a){if(e==null)return"";if(typeof e=="function")return H(e,ee(e));if(typeof e=="string")return Q(e);switch(e){case C:return Q("Suspense");case w:return Q("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case b:return P(e.render);case R:return be(e.type,r,a);case I:{var l=e,m=l._payload,h=l._init;try{return be(h(m),r,a)}catch{}}}return""}var me=Object.prototype.hasOwnProperty,Le={},Ye=B.ReactDebugCurrentFrame;function ye(e){if(e){var r=e._owner,a=be(e.type,e._source,r?r.type:null);Ye.setExtraStackFrame(a)}else Ye.setExtraStackFrame(null)}function ht(e,r,a,l,m){{var h=Function.call.bind(me);for(var f in e)if(h(e,f)){var d=void 0;try{if(typeof e[f]!="function"){var E=Error((l||"React class")+": "+a+" type `"+f+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof e[f]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw E.name="Invariant Violation",E}d=e[f](r,f,l,a,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(v){d=v}d&&!(d instanceof Error)&&(ye(m),_("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",l||"React class",a,f,typeof d),ye(null)),d instanceof Error&&!(d.message in Le)&&(Le[d.message]=!0,ye(m),_("Failed %s type: %s",a,d.message),ye(null))}}}var vt=Array.isArray;function Re(e){return vt(e)}function gt(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,a=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return a}}function bt(e){try{return Ve(e),!1}catch{return!0}}function Ve(e){return""+e}function Be(e){if(bt(e))return _("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",gt(e)),Ve(e)}var Me=B.ReactCurrentOwner,yt={key:!0,ref:!0,__self:!0,__source:!0},$e,ze;function jt(e){if(me.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function _t(e){if(me.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function wt(e,r){typeof e.ref=="string"&&Me.current}function St(e,r){{var a=function(){$e||($e=!0,_("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};a.isReactWarning=!0,Object.defineProperty(e,"key",{get:a,configurable:!0})}}function Tt(e,r){{var a=function(){ze||(ze=!0,_("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",r))};a.isReactWarning=!0,Object.defineProperty(e,"ref",{get:a,configurable:!0})}}var Et=function(e,r,a,l,m,h,f){var d={$$typeof:u,type:e,key:r,ref:a,props:f,_owner:h};return d._store={},Object.defineProperty(d._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(d,"_self",{configurable:!1,enumerable:!1,writable:!1,value:l}),Object.defineProperty(d,"_source",{configurable:!1,enumerable:!1,writable:!1,value:m}),Object.freeze&&(Object.freeze(d.props),Object.freeze(d)),d};function Rt(e,r,a,l,m){{var h,f={},d=null,E=null;a!==void 0&&(Be(a),d=""+a),_t(r)&&(Be(r.key),d=""+r.key),jt(r)&&(E=r.ref,wt(r,m));for(h in r)me.call(r,h)&&!yt.hasOwnProperty(h)&&(f[h]=r[h]);if(e&&e.defaultProps){var v=e.defaultProps;for(h in v)f[h]===void 0&&(f[h]=v[h])}if(d||E){var y=typeof e=="function"?e.displayName||e.name||"Unknown":e;d&&St(f,y),E&&Tt(f,y)}return Et(e,d,E,m,l,Me.current,f)}}var Ne=B.ReactCurrentOwner,Je=B.ReactDebugCurrentFrame;function ae(e){if(e){var r=e._owner,a=be(e.type,e._source,r?r.type:null);Je.setExtraStackFrame(a)}else Je.setExtraStackFrame(null)}var De;De=!1;function Ce(e){return typeof e=="object"&&e!==null&&e.$$typeof===u}function Ge(){{if(Ne.current){var e=k(Ne.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function Nt(e){return""}var Ke={};function Dt(e){{var r=Ge();if(!r){var a=typeof e=="string"?e:e.displayName||e.name;a&&(r=` Check the top-level render call using <`+a+">.")}return r}}function qe(e,r){{if(!e._store||e._store.validated||e.key!=null)return;e._store.validated=!0;var a=Dt(r);if(Ke[a])return;Ke[a]=!0;var l="";e&&e._owner&&e._owner!==Ne.current&&(l=" It was passed a child from "+k(e._owner.type)+"."),ae(e),_('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',a,l),ae(null)}}function He(e,r){{if(typeof e!="object")return;if(Re(e))for(var a=0;a<e.length;a++){var l=e[a];Ce(l)&&qe(l,r)}else if(Ce(e))e._store&&(e._store.validated=!0);else if(e){var m=_e(e);if(typeof m=="function"&&m!==e.entries)for(var h=m.call(e),f;!(f=h.next()).done;)Ce(f.value)&&qe(f.value,r)}}}function Ct(e){{var r=e.type;if(r==null||typeof r=="string")return;var a;if(typeof r=="function")a=r.propTypes;else if(typeof r=="object"&&(r.$$typeof===b||r.$$typeof===R))a=r.propTypes;else return;if(a){var l=k(r);ht(a,e.props,"prop",l,e)}else if(r.PropTypes!==void 0&&!De){De=!0;var m=k(r);_("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",m||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&_("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Ot(e){{for(var r=Object.keys(e.props),a=0;a<r.length;a++){var l=r[a];if(l!=="children"&&l!=="key"){ae(e),_("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",l),ae(null);break}}e.ref!==null&&(ae(e),_("Invalid attribute `ref` supplied to `React.Fragment`."),ae(null))}}var Xe={};function Ze(e,r,a,l,m,h){{var f=Se(e);if(!f){var d="";(e===void 0||typeof e=="object"&&e!==null&&Object.keys(e).length===0)&&(d+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var E=Nt();E?d+=E:d+=Ge();var v;e===null?v="null":Re(e)?v="array":e!==void 0&&e.$$typeof===u?(v="<"+(k(e.type)||"Unknown")+" />",d=" Did you accidentally export a JSX literal instead of a component?"):v=typeof e,_("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",v,d)}var y=Rt(e,r,a,m,h);if(y==null)return y;if(f){var F=r.children;if(F!==void 0)if(l)if(Re(F)){for(var ie=0;ie<F.length;ie++)He(F[ie],e);Object.freeze&&Object.freeze(F)}else _("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else He(F,e)}if(me.call(r,"key")){var te=k(e),N=Object.keys(r).filter(function(Wt){return Wt!=="key"}),Oe=N.length>0?"{key: someKey, "+N.join(": ..., ")+": ...}":"{key: someKey}";if(!Xe[te+Oe]){var Ft=N.length>0?"{"+N.join(": ..., ")+": ...}":"{}";_(`A props object containing a "key" prop is being spread into JSX: let props = %s; <%s {...props} /> React keys must be passed directly to JSX without using spread: let props = %s; <%s key={someKey} {...props} />`,Oe,te,Ft,te),Xe[te+Oe]=!0}}return e===c?Ot(y):Ct(y),y}}function kt(e,r,a){return Ze(e,r,a,!0)}function Pt(e,r,a){return Ze(e,r,a,!1)}var It=Pt,At=kt;oe.Fragment=c,oe.jsx=It,oe.jsxs=At}()),oe}process.env.NODE_ENV==="production"?je.exports=rt():je.exports=nt();var t=je.exports;function z(...n){return et.twMerge(Qe.clsx(n))}function Ie({departureTime:n,arrivalTime:u,departureLocation:o,arrivalLocation:c}){const i=re.format(new Date(`2000-01-01T${n}`),"h:mm a"),s=re.format(new Date(`2000-01-01T${u}`),"h:mm a");return t.jsxs("div",{className:"relative flex items-stretch gap-3",children:[t.jsxs("div",{className:"flex flex-col items-center",children:[t.jsx("div",{className:"relative top-[0.6rem]",children:t.jsx("div",{className:"w-2.5 h-2.5 rounded-full bg-blue-500"})}),t.jsx("div",{className:"w-0.5 bg-blue-200 flex-1 my-1.5"}),t.jsx("div",{className:"relative bottom-[0.6rem]",children:t.jsx("div",{className:"w-2.5 h-2.5 rounded-full border-2 border-blue-500"})})]}),t.jsxs("div",{className:"flex-1 py-0.5",children:[t.jsxs("div",{className:"mb-4",children:[t.jsx("div",{className:"text-lg font-semibold leading-tight",children:i}),t.jsx("div",{className:"text-sm text-gray-600",children:o})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-lg font-semibold leading-tight",children:s}),t.jsx("div",{className:"text-sm text-gray-600",children:c})]})]})]})}function Ae({flags:n}){return n.length===0?null:t.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:n.map((u,o)=>t.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-amber-50 text-amber-700 rounded-full text-xs font-medium",children:[t.jsx($.AlertCircle,{className:"h-3 w-3"}),u.flag_name]},o))})}function at({pats:n,totalCost:u,isExpanded:o}){if(!o)return null;const c=n.reduce((i,s)=>{const x=`${s.pat_type_name}-${s.pat_sub_type_name}`;return i[x]||(i[x]={type:s.pat_type_name,subType:s.pat_sub_type_name,plural:s.pat_sub_type_plural,count:0,price:0}),i[x].count+=s.count,i[x].price+=s.price,i},{});return t.jsx(W.motion.div,{initial:{height:0,opacity:0},animate:{height:"auto",opacity:1},className:"border-t border-gray-100 bg-gray-50",children:t.jsxs("div",{className:"p-4 space-y-3",children:[t.jsx("h4",{className:"font-medium text-gray-900",children:"Fare Breakdown"}),t.jsxs("div",{className:"space-y-2",children:[Object.values(c).map((i,s)=>t.jsxs("div",{className:"flex justify-between text-sm",children:[t.jsxs("span",{className:"text-gray-600",children:[i.count," x ",i.count===1?i.subType:i.plural]}),t.jsxs("span",{className:"font-medium",children:["$",i.price.toFixed(2)]})]},s)),t.jsxs("div",{className:"pt-2 border-t border-gray-200 flex justify-between font-medium",children:[t.jsx("span",{children:"Total"}),t.jsxs("span",{className:"text-blue-600",children:["$",u.toFixed(2)]})]})]})]})})}function it({service:n,isSelected:u,isExpanded:o,onSelect:c,onToggleExpand:i,disabled:s}){const x=n.can_accept!=="yes";return t.jsxs(W.motion.div,{className:z("bg-white rounded-lg border transition-all duration-200 overflow-hidden",u?"border-green-500 shadow-lg":"border-gray-200",x&&"opacity-75",s&&"opacity-50 cursor-not-allowed"),layout:!0,children:[t.jsx("div",{className:"p-4",children:t.jsxs("div",{className:z("flex items-start justify-between gap-4",!x&&!s&&"cursor-pointer"),onClick:()=>!x&&!s&&c(),children:[t.jsxs("div",{className:"flex-1",children:[t.jsx(Ie,{departureTime:n.departure_time,arrivalTime:n.arrival_time,departureLocation:n.departing_from,arrivalLocation:n.travelling_to}),t.jsxs("div",{className:"flex flex-wrap gap-2 mt-4",children:[x&&t.jsxs("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-red-50 text-red-700 rounded-full text-xs font-medium",children:[t.jsx($.AlertTriangle,{className:"h-3 w-3"}),"Unavailable"]}),t.jsx(Ae,{flags:n.flags})]})]}),t.jsxs("div",{className:"text-right",children:[t.jsxs("div",{className:z("flex items-center gap-2 text-2xl font-bold",u?"text-green-600":"text-blue-600",x&&"text-gray-400"),children:[u&&t.jsx($.Check,{className:"h-5 w-5"}),"$",n.total_cost.toFixed(2)]}),t.jsxs("button",{onClick:g=>{g.stopPropagation(),i()},className:"mt-2 text-sm font-medium text-gray-500 hover:text-gray-700 flex items-center gap-1 ml-auto",children:[o?"Hide":"Show"," details",t.jsx($.ChevronDown,{className:z("h-4 w-4 transition-transform",o&&"rotate-180")})]})]})]})}),t.jsx(at,{pats:n.pats,totalCost:n.total_cost,isExpanded:o})]})}function Fe({services:n,selectedId:u,onSelect:o,title:c,isLoading:i}){const[s,x]=T.useState(null);return n.length===0?null:t.jsxs(W.motion.div,{className:"space-y-4",animate:{opacity:i?.5:1},transition:{duration:.2},children:[t.jsx("h3",{className:"text-xl font-semibold text-gray-900",children:c}),t.jsx("div",{className:"space-y-4",children:t.jsx(W.AnimatePresence,{mode:"wait",children:n.map(g=>t.jsx(it,{service:g,isSelected:g.service_id===u,isExpanded:g.service_id===s,onSelect:()=>!i&&o(g.service_id),onToggleExpand:()=>{x(g.service_id===s?null:g.service_id)},disabled:i},g.service_id))})})]})}function st({dates:n,selectedDate:u,onSelect:o,onNavigate:c}){return t.jsx("div",{className:"flex flex-col items-center gap-4 mb-8",children:t.jsxs("div",{className:"flex items-center gap-4",children:[t.jsx("button",{onClick:()=>c("backward"),className:"p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx($.ChevronLeft,{className:"h-5 w-5 text-gray-600"})}),t.jsx("div",{className:"flex items-center gap-4 no-scrollbar",children:n.map(i=>t.jsxs(W.motion.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>o(i),className:z("flex flex-col items-center min-w-[140px] px-4 py-3 rounded-lg transition-all",u===i?"bg-blue-500 text-white shadow-lg shadow-blue-500/20":"bg-white border border-gray-200 hover:border-blue-200 text-gray-900"),children:[t.jsx($.Calendar,{className:z("h-5 w-5 mb-1",u===i?"text-white":"text-blue-500")}),t.jsx("span",{className:"text-sm font-medium whitespace-nowrap",children:re.format(new Date(i),"EEE, d MMM")})]},i))}),t.jsx("button",{onClick:()=>c("forward"),className:"p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx($.ChevronRight,{className:"h-5 w-5 text-gray-600"})})]})})}function ot({sortBy:n,onSortChange:u,showUnavailable:o,onToggleUnavailable:c}){return t.jsxs("div",{className:"flex items-center justify-between px-6 py-4 bg-white border border-gray-200 rounded-lg mb-6",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("label",{className:"text-sm font-medium text-gray-700",children:"Sort by:"}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{value:n,onChange:i=>u(i.target.value),className:"appearance-none bg-white border border-gray-200 rounded-lg pl-4 pr-10 py-2 text-sm font-medium text-gray-700 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",children:[t.jsx("option",{value:"departure",children:"Departure time"}),t.jsx("option",{value:"price",children:"Price"})]}),t.jsx($.ChevronDown,{className:"absolute right-3 top-1/2 -translate-y-1/2 h-4 w-4 text-gray-400 pointer-events-none"})]})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("span",{className:"text-sm text-gray-600",children:"Show unavailable ferries"}),t.jsx("button",{onClick:c,className:z("w-12 h-6 rounded-full transition-colors relative",o?"bg-blue-500":"bg-gray-200"),children:t.jsx("div",{className:z("absolute top-1 w-4 h-4 rounded-full bg-white transition-all",o?"right-1":"left-1")})})]})]})}function lt({service:n,title:u}){return t.jsxs(W.motion.div,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"bg-blue-50 rounded-lg border border-blue-100 p-4 mb-6",children:[t.jsx("h4",{className:"text-sm font-medium text-blue-700 mb-3",children:u}),t.jsxs("div",{className:"bg-white rounded-lg p-4 border border-blue-100",children:[t.jsx(Ie,{departureTime:n.departure_time,arrivalTime:n.arrival_time,departureLocation:n.departing_from,arrivalLocation:n.travelling_to}),t.jsx(Ae,{flags:n.flags}),t.jsx("div",{className:"mt-3 text-right",children:t.jsxs("span",{className:"text-lg font-semibold text-blue-600",children:["$",n.total_cost.toFixed(2)]})})]})]})}function ut(n){if(console.log("getDefaultDate input:",{servicesCount:n==null?void 0:n.length,firstService:n==null?void 0:n[0],allDates:n==null?void 0:n.map(s=>s.departure_date)}),!n||!Array.isArray(n)||n.length===0)return console.warn("No valid departure services provided, using current date"),new Date().toISOString().split("T")[0];const u=n.filter(s=>{const x=(s==null?void 0:s.departure_date)&&!isNaN(new Date(s.departure_date).getTime());return x||console.warn("Invalid departure_date found:",s==null?void 0:s.departure_date),x});if(u.length===0)return console.warn("No services with valid dates found, using current date"),new Date().toISOString().split("T")[0];const c=[...u].sort((s,x)=>new Date(s.departure_date).getTime()-new Date(x.departure_date).getTime())[0],i=c.departure_date;return console.log("Date selection:",{validDatesCount:u.length,allValidDates:u.map(s=>s.departure_date),selectedDate:i,firstDepartureService:c}),i}function ct(n,u=1){const o=[],c=new Date(n);for(let i=u;i>0;i--){const s=re.subDays(c,i);o.push(s.toISOString().split("T")[0])}o.push(n);for(let i=1;i<=u;i++){const s=re.addDays(c,i);o.push(s.toISOString().split("T")[0])}return o}function dt(n,u){const o=u==="forward"?1:-1;return n.map(c=>re.addDays(new Date(c),o).toISOString().split("T")[0])}function pe(n){return new Date(`1970-01-01T${n}`).getTime()}function We(n,u){return[...n].sort((o,c)=>{switch(u){case"departure":return pe(o.departure_time)-pe(c.departure_time);case"price":const i=o.total_cost-c.total_cost;return i===0?pe(o.departure_time)-pe(c.departure_time):i;default:return 0}})}function Ue(n,u){return u?n:n.filter(o=>o.can_accept==="yes")}function ft(n,u,o){let c=Ue(n,u);if(o){const i=new Date(`1970-01-01T${o}`).getTime();c=c.filter(s=>new Date(`1970-01-01T${s.departure_time}`).getTime()>i)}return c}const mt={selectedDepartureId:null,selectedReturnId:null,departureService:null,returnService:null,date:new Date().toISOString().split("T")[0],totalCost:0},pt=tt.create((n,u)=>({selections:{},setSelections:(o,c)=>n(i=>({selections:{...i.selections,[o]:c}})),getSelections:o=>u().selections[o]||{...mt},clearSelections:o=>n(c=>{const{[o]:i,...s}=c.selections;return{selections:s}})}));function xt({initialData:n,onComplete:u,onBack:o,uiConfig:c,selectedOutboundId:i,selectedReturnId:s,currentContext:x,onDateSelect:g,onServiceSelect:b,onContextChange:C,isLoading:w=!1,loadingContext:R="both",requested_date:I}){if(console.log("[DEBUG] DepartureSelection render"),!n)return console.error("DepartureSelection requires initialData"),null;const{departure:J,return:G}=n,O=c,{getSelections:_e,setSelections:B}=pt(),_=_e("departure-selection-1"),[A,we]=T.useState(i!==void 0?i:_.selectedDepartureId),[U,xe]=T.useState(s!==void 0?s:_.selectedReturnId),[M,le]=T.useState(x==="return"),[ne,Se]=T.useState("departure"),[K,ue]=T.useState(""),[k,L]=T.useState([]),[Y,he]=T.useState(!1);T.useEffect(()=>{const p=M?G:J;let j;I&&(j=I,console.log("Using requested_date from parent prop:",j));const H=j&&/^\d{4}-\d{2}-\d{2}$/.test(j);let P="";H?(P=j,console.log("Initial date set from requested_date:",P)):p&&p.length>0?(P=ut(p),console.log("Initial date set from getDefaultDate:",P)):(P=new Date().toISOString().split("T")[0],console.log("Initial date defaulted to today:",P)),ue(P);let ee=ct(P);(!ee||ee.length===0)&&(console.warn("generateDateRange returned empty, defaulting to [initialDate]",{initialDate:P}),ee=[P]),L(ee),console.log("Date initialization:",{initialDate:P,dateRange:ee})},[J,G,M,I]);const ce=G&&G.length>0,V=Ue(We(J,ne),Y),S=V.find(p=>p.service_id===A),X=ft(We(G,ne),Y,S==null?void 0:S.departure_time),Z=X.find(p=>p.service_id===U);T.useEffect(()=>{C&&C({previousContext:x||"outbound",nextContext:M?"return":"outbound",selectedOutboundId:A,selectedReturnId:U})},[M,A,U]);const ve=p=>{const j=dt(k,p);L(j)},ge=p=>{g&&g({date:p,previousDate:K,context:M?"return":"outbound"}),ue(p)},Te=p=>{const j=V.find(H=>H.service_id===p);j&&(we(p),xe(null),le(!1),b&&b({serviceId:p,context:"outbound",service:j}),B("departure-selection-1",{selectedDepartureId:p,selectedReturnId:null,departureService:j,returnService:null,date:K,totalCost:j.total_cost}))},Ee=p=>{const j=X.find(H=>H.service_id===p);!j||!S||(xe(p),b&&b({serviceId:p,context:"return",service:j}),B("departure-selection-1",{selectedDepartureId:S.service_id,selectedReturnId:p,departureService:S,returnService:j,date:K,totalCost:S.total_cost+j.total_cost}))},de=()=>{C&&C({previousContext:"outbound",nextContext:"return",selectedOutboundId:A,selectedReturnId:U}),le(!0)},fe=()=>{C&&C({previousContext:"return",nextContext:"outbound",selectedOutboundId:A,selectedReturnId:U}),le(!1)},Q=()=>{if(!S)return;const p={selectedDepartureId:A,selectedReturnId:U,departureService:S,returnService:Z||null,date:K,totalCost:((S==null?void 0:S.total_cost)||0)+((Z==null?void 0:Z.total_cost)||0)};u(p)},q=K||I||new Date().toISOString().split("T")[0];return t.jsx("div",{className:"container max-w-3xl mx-auto py-12 px-4",children:t.jsxs(W.motion.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"space-y-8 relative",children:[w&&t.jsx("div",{className:"absolute inset-0 bg-white/80 flex items-center justify-center z-50 rounded-xl",children:t.jsxs("div",{className:"text-center",children:[t.jsx("div",{className:"w-12 h-12 border-4 border-blue-500 border-t-transparent rounded-full animate-spin mx-auto"}),t.jsx("p",{className:"mt-4 text-gray-700 font-medium",children:"Loading..."})]})}),t.jsxs("div",{className:"text-center",children:[t.jsx("h2",{className:"text-3xl font-bold text-gray-900",children:O.pageTitle}),t.jsx("p",{className:"text-gray-600 mt-2",children:O.pageSubtitle})]}),t.jsx(st,{dates:k.length>0?k:[q],selectedDate:q,onSelect:ge,onNavigate:ve}),t.jsxs("div",{className:"bg-gray-50 rounded-xl p-6 space-y-6",children:[t.jsx(ot,{sortBy:ne,onSortChange:Se,showUnavailable:Y,onToggleUnavailable:()=>he(!Y)}),t.jsx(W.AnimatePresence,{mode:"wait",children:M&&S?t.jsxs(W.motion.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},children:[t.jsx("div",{onClick:fe,className:"cursor-pointer",children:t.jsx(lt,{service:S,title:"Selected Outbound Journey (click to change)"})}),X.length>0?t.jsx(Fe,{services:X,selectedId:U,onSelect:Ee,title:O.returnTitle,isLoading:w&&(R==="return"||R==="both")}):t.jsx("div",{className:"flex flex-col items-center justify-center py-12",children:t.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl px-6 py-8 text-center max-w-lg mx-auto",children:[t.jsxs("svg",{className:"mx-auto mb-4 h-10 w-10 text-blue-400",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:[t.jsx("circle",{cx:"12",cy:"12",r:"10"}),t.jsx("path",{d:"M12 8v4m0 4h.01"})]}),t.jsxs("h3",{className:"text-xl font-semibold text-blue-900 mb-2",children:["No return journeys available on ",q]}),t.jsx("p",{className:"text-blue-800 mb-4",children:"We couldn't find any return journeys for your chosen date. Please use the date picker above to select another date."})]})})]},"return-selection"):t.jsx(W.motion.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},children:(console.log("[DEBUG] Render outbound section:",{departure:V,departureLength:V.length,selectedDate:K,dates:k,selectedDepartureId:A,branch:V.length>0?"ServiceList":"EmptyState"}),V.length>0?t.jsxs(t.Fragment,{children:[t.jsx(Fe,{services:V,selectedId:A,onSelect:Te,title:O.outboundTitle,isLoading:w&&(R==="outbound"||R==="both")}),A&&t.jsx(W.motion.div,{initial:{opacity:0},animate:{opacity:1},className:"mt-6",children:t.jsx("button",{onClick:O.outboundButtonMode==="continue"?de:Q,className:"w-full py-3 bg-blue-500 text-white rounded-lg font-medium hover:bg-blue-600 transition-colors",children:O.outboundButtonMode==="continue"?O.continueToReturnText:O.finalContinueText})})]}):t.jsx("div",{className:"flex flex-col items-center justify-center py-12",children:t.jsxs("div",{className:"bg-blue-50 border border-blue-200 rounded-xl px-6 py-8 text-center max-w-lg mx-auto",children:[t.jsxs("svg",{className:"mx-auto mb-4 h-10 w-10 text-blue-400",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:[t.jsx("circle",{cx:"12",cy:"12",r:"10"}),t.jsx("path",{d:"M12 8v4m0 4h.01"})]}),t.jsxs("h3",{className:"text-xl font-semibold text-blue-900 mb-2",children:["No journeys available on ",q]}),t.jsx("p",{className:"text-blue-800 mb-4",children:"We couldn't find any journeys for your chosen date. Please try another date or check back soon!"})]})}))},"departure-selection")})]}),t.jsxs("div",{className:"flex justify-between items-center",children:[o&&t.jsx("button",{onClick:o,className:"px-6 py-3 text-gray-600 font-medium hover:bg-gray-50 rounded-lg transition-colors",children:M?O.backToOutboundText:O.backText}),(A&&!ce||ce&&U)&&t.jsx("button",{onClick:Q,className:"px-8 py-3 bg-blue-500 text-white font-medium rounded-lg hover:bg-blue-600 transition-colors",children:O.finalContinueText})]})]})})}D.DepartureSelection=xt,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});