UNPKG

departureselection

Version:

A reusable departure selection component for travel booking applications

31 lines (28 loc) 29.7 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,k,U,Ze,Qe,H,et){"use strict";var je={exports:{}},ne={};/** * @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 Ce;function tt(){if(Ce)return ne;Ce=1;var n=T,i=Symbol.for("react.element"),l=Symbol.for("react.fragment"),o=Object.prototype.hasOwnProperty,s=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,u={key:!0,ref:!0,__self:!0,__source:!0};function h(x,b,C){var j,E={},W=null,B=null;C!==void 0&&(W=""+C),b.key!==void 0&&(W=""+b.key),b.ref!==void 0&&(B=b.ref);for(j in b)o.call(b,j)&&!u.hasOwnProperty(j)&&(E[j]=b[j]);if(x&&x.defaultProps)for(j in b=x.defaultProps,b)E[j]===void 0&&(E[j]=b[j]);return{$$typeof:i,type:x,key:W,ref:B,props:E,_owner:s.current}}return ne.Fragment=l,ne.jsx=h,ne.jsxs=h,ne}var ae={};/** * @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 rt(){return Pe||(Pe=1,process.env.NODE_ENV!=="production"&&function(){var n=T,i=Symbol.for("react.element"),l=Symbol.for("react.portal"),o=Symbol.for("react.fragment"),s=Symbol.for("react.strict_mode"),u=Symbol.for("react.profiler"),h=Symbol.for("react.provider"),x=Symbol.for("react.context"),b=Symbol.for("react.forward_ref"),C=Symbol.for("react.suspense"),j=Symbol.for("react.suspense_list"),E=Symbol.for("react.memo"),W=Symbol.for("react.lazy"),B=Symbol.for("react.offscreen"),fe=Symbol.iterator,pe="@@iterator";function me(e){if(e===null||typeof e!="object")return null;var r=fe&&e[fe]||e[pe];return typeof r=="function"?r:null}var R=n.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(e){{for(var r=arguments.length,a=new Array(r>1?r-1:0),c=1;c<r;c++)a[c-1]=arguments[c];Y("error",e,a)}}function Y(e,r,a){{var c=R.ReactDebugCurrentFrame,m=c.getStackAddendum();m!==""&&(r+="%s",a=a.concat([m]));var v=a.map(function(f){return String(f)});v.unshift("Warning: "+r),Function.prototype.apply.call(console[e],console,v)}}var he=!1,I=!1,se=!1,oe=!1,we=!1,L;L=Symbol.for("react.module.reference");function ie(e){return!!(typeof e=="string"||typeof e=="function"||e===o||e===u||we||e===s||e===C||e===j||oe||e===B||he||I||se||typeof e=="object"&&e!==null&&(e.$$typeof===W||e.$$typeof===E||e.$$typeof===h||e.$$typeof===x||e.$$typeof===b||e.$$typeof===L||e.getModuleId!==void 0))}function le(e,r,a){var c=e.displayName;if(c)return c;var m=r.displayName||r.name||"";return m!==""?a+"("+m+")":a}function ue(e){return e.displayName||"Context"}function P(e){if(e==null)return null;if(typeof e.tag=="number"&&w("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 o:return"Fragment";case l:return"Portal";case u:return"Profiler";case s:return"StrictMode";case C:return"Suspense";case j:return"SuspenseList"}if(typeof e=="object")switch(e.$$typeof){case x:var r=e;return ue(r)+".Consumer";case h:var a=e;return ue(a._context)+".Provider";case b:return le(e,e.render,"ForwardRef");case E:var c=e.displayName||null;return c!==null?c:P(e.type)||"Memo";case W:{var m=e,v=m._payload,f=m._init;try{return P(f(v))}catch{return null}}}return null}var M=Object.assign,$=0,X,S,q,z,ve,xe,ge;function be(){}be.__reactDisabledLog=!0;function Se(){{if($===0){X=console.log,S=console.info,q=console.warn,z=console.error,ve=console.group,xe=console.groupCollapsed,ge=console.groupEnd;var e={configurable:!0,enumerable:!0,value:be,writable:!0};Object.defineProperties(console,{info:e,log:e,warn:e,error:e,group:e,groupCollapsed:e,groupEnd:e})}$++}}function Te(){{if($--,$===0){var e={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:M({},e,{value:X}),info:M({},e,{value:S}),warn:M({},e,{value:q}),error:M({},e,{value:z}),group:M({},e,{value:ve}),groupCollapsed:M({},e,{value:xe}),groupEnd:M({},e,{value:ge})})}$<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Z=R.ReactCurrentDispatcher,Q;function J(e,r,a){{if(Q===void 0)try{throw Error()}catch(m){var c=m.stack.trim().match(/\n( *(at )?)/);Q=c&&c[1]||""}return` `+Q+e}}var ee=!1,K;{var p=typeof WeakMap=="function"?WeakMap:Map;K=new p}function _(e,r){if(!e||ee)return"";{var a=K.get(e);if(a!==void 0)return a}var c;ee=!0;var m=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var v;v=Z.current,Z.current=null,Se();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(O){c=O}Reflect.construct(e,[],f)}else{try{f.call()}catch(O){c=O}e.call(f.prototype)}}else{try{throw Error()}catch(O){c=O}e()}}catch(O){if(O&&c&&typeof O.stack=="string"){for(var d=O.stack.split(` `),N=c.stack.split(` `),g=d.length-1,y=N.length-1;g>=1&&y>=0&&d[g]!==N[y];)y--;for(;g>=1&&y>=0;g--,y--)if(d[g]!==N[y]){if(g!==1||y!==1)do if(g--,y--,y<0||d[g]!==N[y]){var F=` `+d[g].replace(" at new "," at ");return e.displayName&&F.includes("<anonymous>")&&(F=F.replace("<anonymous>",e.displayName)),typeof e=="function"&&K.set(e,F),F}while(g>=1&&y>=0);break}}}finally{ee=!1,Z.current=v,Te(),Error.prepareStackTrace=m}var re=e?e.displayName||e.name:"",G=re?J(re):"";return typeof e=="function"&&K.set(e,G),G}function A(e,r,a){return _(e,!1)}function vt(e){var r=e.prototype;return!!(r&&r.isReactComponent)}function ye(e,r,a){if(e==null)return"";if(typeof e=="function")return _(e,vt(e));if(typeof e=="string")return J(e);switch(e){case C:return J("Suspense");case j:return J("SuspenseList")}if(typeof e=="object")switch(e.$$typeof){case b:return A(e.render);case E:return ye(e.type,r,a);case W:{var c=e,m=c._payload,v=c._init;try{return ye(v(m),r,a)}catch{}}}return""}var ce=Object.prototype.hasOwnProperty,Le={},Ye=R.ReactDebugCurrentFrame;function _e(e){if(e){var r=e._owner,a=ye(e.type,e._source,r?r.type:null);Ye.setExtraStackFrame(a)}else Ye.setExtraStackFrame(null)}function xt(e,r,a,c,m){{var v=Function.call.bind(ce);for(var f in e)if(v(e,f)){var d=void 0;try{if(typeof e[f]!="function"){var N=Error((c||"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 N.name="Invariant Violation",N}d=e[f](r,f,c,a,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(g){d=g}d&&!(d instanceof Error)&&(_e(m),w("%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).",c||"React class",a,f,typeof d),_e(null)),d instanceof Error&&!(d.message in Le)&&(Le[d.message]=!0,_e(m),w("Failed %s type: %s",a,d.message),_e(null))}}}var gt=Array.isArray;function Re(e){return gt(e)}function bt(e){{var r=typeof Symbol=="function"&&Symbol.toStringTag,a=r&&e[Symbol.toStringTag]||e.constructor.name||"Object";return a}}function yt(e){try{return Ue(e),!1}catch{return!0}}function Ue(e){return""+e}function Ve(e){if(yt(e))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",bt(e)),Ue(e)}var Be=R.ReactCurrentOwner,_t={key:!0,ref:!0,__self:!0,__source:!0},Me,$e;function jt(e){if(ce.call(e,"ref")){var r=Object.getOwnPropertyDescriptor(e,"ref").get;if(r&&r.isReactWarning)return!1}return e.ref!==void 0}function wt(e){if(ce.call(e,"key")){var r=Object.getOwnPropertyDescriptor(e,"key").get;if(r&&r.isReactWarning)return!1}return e.key!==void 0}function St(e,r){typeof e.ref=="string"&&Be.current}function Tt(e,r){{var a=function(){Me||(Me=!0,w("%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 Rt(e,r){{var a=function(){$e||($e=!0,w("%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,c,m,v,f){var d={$$typeof:i,type:e,key:r,ref:a,props:f,_owner:v};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:c}),Object.defineProperty(d,"_source",{configurable:!1,enumerable:!1,writable:!1,value:m}),Object.freeze&&(Object.freeze(d.props),Object.freeze(d)),d};function Nt(e,r,a,c,m){{var v,f={},d=null,N=null;a!==void 0&&(Ve(a),d=""+a),wt(r)&&(Ve(r.key),d=""+r.key),jt(r)&&(N=r.ref,St(r,m));for(v in r)ce.call(r,v)&&!_t.hasOwnProperty(v)&&(f[v]=r[v]);if(e&&e.defaultProps){var g=e.defaultProps;for(v in g)f[v]===void 0&&(f[v]=g[v])}if(d||N){var y=typeof e=="function"?e.displayName||e.name||"Unknown":e;d&&Tt(f,y),N&&Rt(f,y)}return Et(e,d,N,m,c,Be.current,f)}}var Ee=R.ReactCurrentOwner,ze=R.ReactDebugCurrentFrame;function te(e){if(e){var r=e._owner,a=ye(e.type,e._source,r?r.type:null);ze.setExtraStackFrame(a)}else ze.setExtraStackFrame(null)}var Ne;Ne=!1;function Oe(e){return typeof e=="object"&&e!==null&&e.$$typeof===i}function Je(){{if(Ee.current){var e=P(Ee.current.type);if(e)return` Check the render method of \``+e+"`."}return""}}function Ot(e){return""}var Ke={};function Dt(e){{var r=Je();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 Ge(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 c="";e&&e._owner&&e._owner!==Ee.current&&(c=" It was passed a child from "+P(e._owner.type)+"."),te(e),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',a,c),te(null)}}function He(e,r){{if(typeof e!="object")return;if(Re(e))for(var a=0;a<e.length;a++){var c=e[a];Oe(c)&&Ge(c,r)}else if(Oe(e))e._store&&(e._store.validated=!0);else if(e){var m=me(e);if(typeof m=="function"&&m!==e.entries)for(var v=m.call(e),f;!(f=v.next()).done;)Oe(f.value)&&Ge(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===E))a=r.propTypes;else return;if(a){var c=P(r);xt(a,e.props,"prop",c,e)}else if(r.PropTypes!==void 0&&!Ne){Ne=!0;var m=P(r);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",m||"Unknown")}typeof r.getDefaultProps=="function"&&!r.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Pt(e){{for(var r=Object.keys(e.props),a=0;a<r.length;a++){var c=r[a];if(c!=="children"&&c!=="key"){te(e),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",c),te(null);break}}e.ref!==null&&(te(e),w("Invalid attribute `ref` supplied to `React.Fragment`."),te(null))}}var Xe={};function qe(e,r,a,c,m,v){{var f=ie(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 N=Ot();N?d+=N:d+=Je();var g;e===null?g="null":Re(e)?g="array":e!==void 0&&e.$$typeof===i?(g="<"+(P(e.type)||"Unknown")+" />",d=" Did you accidentally export a JSX literal instead of a component?"):g=typeof e,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",g,d)}var y=Nt(e,r,a,m,v);if(y==null)return y;if(f){var F=r.children;if(F!==void 0)if(c)if(Re(F)){for(var re=0;re<F.length;re++)He(F[re],e);Object.freeze&&Object.freeze(F)}else w("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(ce.call(r,"key")){var G=P(e),O=Object.keys(r).filter(function(Lt){return Lt!=="key"}),De=O.length>0?"{key: someKey, "+O.join(": ..., ")+": ...}":"{key: someKey}";if(!Xe[G+De]){var Wt=O.length>0?"{"+O.join(": ..., ")+": ...}":"{}";w(`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} />`,De,G,Wt,G),Xe[G+De]=!0}}return e===o?Pt(y):Ct(y),y}}function kt(e,r,a){return qe(e,r,a,!0)}function It(e,r,a){return qe(e,r,a,!1)}var At=It,Ft=kt;ae.Fragment=o,ae.jsx=At,ae.jsxs=Ft}()),ae}process.env.NODE_ENV==="production"?je.exports=tt():je.exports=rt();var t=je.exports;function V(...n){return Qe.twMerge(Ze.clsx(n))}function ke({departureTime:n,arrivalTime:i,departureLocation:l,arrivalLocation:o}){const s=H.format(new Date(`2000-01-01T${n}`),"h:mm a"),u=H.format(new Date(`2000-01-01T${i}`),"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:s}),t.jsx("div",{className:"text-sm text-gray-600",children:l})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-lg font-semibold leading-tight",children:u}),t.jsx("div",{className:"text-sm text-gray-600",children:o})]})]})]})}function Ie({flags:n}){return n.length===0?null:t.jsx("div",{className:"mt-4 flex flex-wrap gap-2",children:n.map((i,l)=>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(U.AlertCircle,{className:"h-3 w-3"}),i.flag_name]},l))})}function nt({pats:n,totalCost:i,isExpanded:l}){if(!l)return null;const o=n.reduce((s,u)=>{const h=`${u.pat_type_name}-${u.pat_sub_type_name}`;return s[h]||(s[h]={type:u.pat_type_name,subType:u.pat_sub_type_name,plural:u.pat_sub_type_plural,count:0,price:0}),s[h].count+=u.count,s[h].price+=u.price,s},{});return t.jsx(k.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(o).map((s,u)=>t.jsxs("div",{className:"flex justify-between text-sm",children:[t.jsxs("span",{className:"text-gray-600",children:[s.count," x ",s.count===1?s.subType:s.plural]}),t.jsxs("span",{className:"font-medium",children:["$",s.price.toFixed(2)]})]},u)),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:["$",i.toFixed(2)]})]})]})]})})}function at({service:n,isSelected:i,isExpanded:l,onSelect:o,onToggleExpand:s,disabled:u}){const h=n.can_accept!=="yes";return t.jsxs(k.motion.div,{className:V("bg-white rounded-lg border transition-all duration-200 overflow-hidden",i?"border-green-500 shadow-lg":"border-gray-200",h&&"opacity-75",u&&"opacity-50 cursor-not-allowed"),layout:!0,children:[t.jsx("div",{className:"p-4",children:t.jsxs("div",{className:V("flex items-start justify-between gap-4",!h&&!u&&"cursor-pointer"),onClick:()=>!h&&!u&&o(),children:[t.jsxs("div",{className:"flex-1",children:[t.jsx(ke,{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:[h&&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(U.AlertTriangle,{className:"h-3 w-3"}),"Unavailable"]}),t.jsx(Ie,{flags:n.flags})]})]}),t.jsxs("div",{className:"text-right",children:[t.jsxs("div",{className:V("flex items-center gap-2 text-2xl font-bold",i?"text-green-600":"text-blue-600",h&&"text-gray-400"),children:[i&&t.jsx(U.Check,{className:"h-5 w-5"}),"$",n.total_cost.toFixed(2)]}),t.jsxs("button",{onClick:x=>{x.stopPropagation(),s()},className:"mt-2 text-sm font-medium text-gray-500 hover:text-gray-700 flex items-center gap-1 ml-auto",children:[l?"Hide":"Show"," details",t.jsx(U.ChevronDown,{className:V("h-4 w-4 transition-transform",l&&"rotate-180")})]})]})]})}),t.jsx(nt,{pats:n.pats,totalCost:n.total_cost,isExpanded:l})]})}function Ae({services:n,selectedId:i,onSelect:l,title:o,isLoading:s}){const[u,h]=T.useState(null);return n.length===0?null:t.jsxs(k.motion.div,{className:"space-y-4",animate:{opacity:s?.5:1},transition:{duration:.2},children:[t.jsx("h3",{className:"text-xl font-semibold text-gray-900",children:o}),t.jsx("div",{className:"space-y-4",children:t.jsx(k.AnimatePresence,{mode:"wait",children:n.map(x=>t.jsx(at,{service:x,isSelected:x.service_id===i,isExpanded:x.service_id===u,onSelect:()=>!s&&l(x.service_id),onToggleExpand:()=>{h(x.service_id===u?null:x.service_id)},disabled:s},x.service_id))})})]})}function st({dates:n,selectedDate:i,onSelect:l,onNavigate:o}){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:()=>o("backward"),className:"p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx(U.ChevronLeft,{className:"h-5 w-5 text-gray-600"})}),t.jsx("div",{className:"flex items-center gap-4 no-scrollbar",children:n.map(s=>t.jsxs(k.motion.button,{whileHover:{scale:1.02},whileTap:{scale:.98},onClick:()=>l(s),className:V("flex flex-col items-center min-w-[140px] px-4 py-3 rounded-lg transition-all",i===s?"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(U.Calendar,{className:V("h-5 w-5 mb-1",i===s?"text-white":"text-blue-500")}),t.jsx("span",{className:"text-sm font-medium whitespace-nowrap",children:H.format(new Date(s),"EEE, d MMM")})]},s))}),t.jsx("button",{onClick:()=>o("forward"),className:"p-2 hover:bg-gray-100 rounded-full transition-colors",children:t.jsx(U.ChevronRight,{className:"h-5 w-5 text-gray-600"})})]})})}function ot({sortBy:n,onSortChange:i,showUnavailable:l,onToggleUnavailable:o}){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:s=>i(s.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(U.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:o,className:V("w-12 h-6 rounded-full transition-colors relative",l?"bg-blue-500":"bg-gray-200"),children:t.jsx("div",{className:V("absolute top-1 w-4 h-4 rounded-full bg-white transition-all",l?"right-1":"left-1")})})]})]})}function it({service:n,title:i}){return t.jsxs(k.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:i}),t.jsxs("div",{className:"bg-white rounded-lg p-4 border border-blue-100",children:[t.jsx(ke,{departureTime:n.departure_time,arrivalTime:n.arrival_time,departureLocation:n.departing_from,arrivalLocation:n.travelling_to}),t.jsx(Ie,{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 lt(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(u=>u.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 i=n.filter(u=>{const h=(u==null?void 0:u.departure_date)&&!isNaN(new Date(u.departure_date).getTime());return h||console.warn("Invalid departure_date found:",u==null?void 0:u.departure_date),h});if(i.length===0)return console.warn("No services with valid dates found, using current date"),new Date().toISOString().split("T")[0];const o=[...i].sort((u,h)=>new Date(u.departure_date).getTime()-new Date(h.departure_date).getTime())[0],s=o.departure_date;return console.log("Date selection:",{validDatesCount:i.length,allValidDates:i.map(u=>u.departure_date),selectedDate:s,firstDepartureService:o}),s}function ut(n,i=1){const l=[],o=new Date(n);for(let s=i;s>0;s--){const u=H.subDays(o,s);l.push(u.toISOString().split("T")[0])}l.push(n);for(let s=1;s<=i;s++){const u=H.addDays(o,s);l.push(u.toISOString().split("T")[0])}return l}function ct(n,i){const l=i==="forward"?1:-1;return n.map(o=>H.addDays(new Date(o),l).toISOString().split("T")[0])}function de(n){return new Date(`1970-01-01T${n}`).getTime()}function Fe(n,i){return[...n].sort((l,o)=>{switch(i){case"departure":return de(l.departure_time)-de(o.departure_time);case"price":const s=l.total_cost-o.total_cost;return s===0?de(l.departure_time)-de(o.departure_time):s;default:return 0}})}function We(n,i){return i?n:n.filter(l=>l.can_accept==="yes")}function dt(n,i,l){let o=We(n,i);if(l){const s=new Date(`1970-01-01T${l}`).getTime();o=o.filter(u=>new Date(`1970-01-01T${u.departure_time}`).getTime()>s)}return o}const ft={selectedDepartureId:null,selectedReturnId:null,departureService:null,returnService:null,date:new Date().toISOString().split("T")[0],totalCost:0},pt=et.create((n,i)=>({selections:{},setSelections:(l,o)=>n(s=>({selections:{...s.selections,[l]:o}})),getSelections:l=>i().selections[l]||{...ft},clearSelections:l=>n(o=>{const{[l]:s,...u}=o.selections;return{selections:u}})}));function mt({context:n,showReturnSelection:i}){return!(n==="both"||n==="outbound"&&!i)&&!(n==="both"||n==="return"&&i)?null:t.jsx(k.motion.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:V("absolute inset-0 bg-white/80 backdrop-blur-sm z-50","flex items-center justify-center"),children:t.jsxs("div",{className:"flex flex-col items-center gap-4",children:[t.jsx(U.Loader2,{className:"w-8 h-8 text-blue-500 animate-spin"}),t.jsx("p",{className:"text-gray-600 font-medium",children:"Updating journey options..."})]})})}function ht({initialData:n,onComplete:i,onBack:l,uiConfig:o,selectedOutboundId:s,selectedReturnId:u,currentContext:h,onDateSelect:x,onServiceSelect:b,onContextChange:C,isLoading:j=!1,loadingContext:E="both"}){var Q,J,ee,K;if(console.log("DepartureSelection - Component rendering with initialData:",{departureCount:(Q=n==null?void 0:n.departure)==null?void 0:Q.length,returnCount:(J=n==null?void 0:n.return)==null?void 0:J.length,firstDeparture:(ee=n==null?void 0:n.departure)==null?void 0:ee[0],firstReturn:(K=n==null?void 0:n.return)==null?void 0:K[0]}),!n)return console.error("DepartureSelection - No initial data available"),null;const{departure:W,return:B}=n,{getSelections:fe,setSelections:pe}=pt(),me=fe("departure-selection-1"),[R,w]=T.useState(s??me.selectedDepartureId),[Y,he]=T.useState(u??me.selectedReturnId),[I,se]=T.useState(h==="return"),[oe,we]=T.useState("departure"),[L,ie]=T.useState(""),[le,ue]=T.useState([]),[P,M]=T.useState(!1);T.useEffect(()=>{const p=I?B:W;if(console.log("DepartureSelection - Date initialization effect running:",{context:I?"return":"outbound",servicesCount:p==null?void 0:p.length,firstService:p==null?void 0:p[0],currentSelectedDate:L,currentDates:le}),p&&p.length>0){const _=lt(p);console.log("DepartureSelection - Calculated default date:",{defaultDate:_,fromServices:p.map(A=>({id:A.service_id,date:A.departure_date,time:A.departure_time}))}),ie(_),ue(ut(_))}},[W,B,I]);const $=B.length>0,X=We(Fe(W,oe),P),S=X.find(p=>p.service_id===R),q=dt(Fe(B,oe),P,S==null?void 0:S.departure_time),z=q.find(p=>p.service_id===Y);T.useEffect(()=>{C&&C({previousContext:h,nextContext:I?"return":"outbound",selectedOutboundId:R,selectedReturnId:Y})},[I,R,Y]);const ve=p=>{const _=ct(le,p);ue(_);const A=_[1];ie(A),x&&x({date:A,previousDate:L,context:I?"return":"outbound"})},xe=p=>{x&&x({date:p,previousDate:L,context:I?"return":"outbound"}),ie(p)},ge=p=>{const _=X.find(A=>A.service_id===p);_&&(w(p),he(null),se(!1),b&&b({serviceId:p,context:"outbound",service:_}),pe("departure-selection-1",{selectedDepartureId:p,selectedReturnId:null,departureService:_,returnService:null,date:L,totalCost:_.total_cost}))},be=p=>{const _=q.find(A=>A.service_id===p);!_||!S||(he(p),b&&b({serviceId:p,context:"return",service:_}),pe("departure-selection-1",{selectedDepartureId:S.service_id,selectedReturnId:p,departureService:S,returnService:_,date:L,totalCost:S.total_cost+_.total_cost}))},Se=()=>{C&&C({previousContext:"outbound",nextContext:"return",selectedOutboundId:R,selectedReturnId:Y}),se(!0)},Te=()=>{C&&C({previousContext:"return",nextContext:"outbound",selectedOutboundId:R,selectedReturnId:Y}),se(!1)},Z=()=>{if(!S)return;const p={selectedDepartureId:R,selectedReturnId:Y,departureService:S,returnService:z||null,date:L,totalCost:((S==null?void 0:S.total_cost)||0)+((z==null?void 0:z.total_cost)||0)};i(p)};return L?t.jsx("div",{className:"container max-w-3xl mx-auto py-12 px-4",children:t.jsxs(k.motion.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"space-y-8 relative",children:[j&&t.jsx(mt,{context:E,showReturnSelection:I}),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:le,selectedDate:L,onSelect:xe,onNavigate:ve}),t.jsxs("div",{className:"bg-gray-50 rounded-xl p-6 space-y-6",children:[t.jsx(ot,{sortBy:oe,onSortChange:we,showUnavailable:P,onToggleUnavailable:()=>M(!P)}),t.jsx(k.AnimatePresence,{mode:"wait",children:I&&S?t.jsxs(k.motion.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},children:[t.jsx("div",{onClick:Te,className:"cursor-pointer",children:t.jsx(it,{service:S,title:"Selected Outbound Journey (click to change)"})}),t.jsx(Ae,{services:q,selectedId:Y,onSelect:be,title:o.returnTitle,isLoading:j&&(E==="return"||E==="both")})]},"return-selection"):t.jsxs(k.motion.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},children:[t.jsx(Ae,{services:X,selectedId:R,onSelect:ge,title:o.outboundTitle,isLoading:j&&(E==="outbound"||E==="both")}),R&&t.jsx(k.motion.div,{initial:{opacity:0},animate:{opacity:1},className:"mt-6",children:t.jsx("button",{onClick:o.outboundButtonMode==="continue"?Se:Z,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})})]},"departure-selection")})]}),t.jsxs("div",{className:"flex justify-between items-center",children:[l&&t.jsx("button",{onClick:l,className:"px-6 py-3 text-gray-600 font-medium hover:bg-gray-50 rounded-lg transition-colors",children:I?o.backToOutboundText:o.backText}),(R&&!$||$&&Y)&&t.jsx("button",{onClick:Z,className:"px-8 py-3 bg-blue-500 text-white font-medium rounded-lg hover:bg-blue-600 transition-colors",children:o.finalContinueText})]})]})}):(console.log("DepartureSelection - Waiting for date initialization..."),null)}D.DepartureSelection=ht,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});