"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5861],{65861:function(e,l,a){a.r(l),a.d(l,{default:function(){return ef}});var r=a(27573),i=a(76184),t=a(48687),n=a(12839),o=a(34011),s=a(10701),u=a(7653),d=a(36825),c=a(5191),v=a(1138),m=a(96504),p=a(71811);function y(e){let{length:l,children:a}=e,{currentStep:i}=(0,p.H)(),[t,n]=(0,u.useState)(!1),[o,s]=(0,d.E)({breakpoints:{"(min-width: 0px)":{slides:{perView:2,spacing:12}},"(min-width: 600px)":{slides:{perView:l>3?3:l,spacing:12}}}});return(0,u.useEffect)(()=>{s.current&&n(!0)},[s.current]),(0,r.jsxs)("div",{className:(0,m.cn)("w-full relative",{hidden:"initial"!==i&&"availability"!==i&&"guest_information"!==i&&"payment_retry"!==i}),children:[!t&&(0,r.jsx)("div",{className:"w-full h-full absolute left-0 top-0 z-20 bg-background",children:(0,r.jsx)(m.OdW,{className:"w-full h-full bg-border/40"})}),(0,r.jsxs)("div",{ref:o,className:(0,m.cn)("w-full keen-slider",{"pt-10":l>3}),children:[a,l>3&&(0,r.jsxs)("div",{className:"w-full flex gap-2 items-center justify-center absolute left-0 top-0",children:[(0,r.jsx)(m.zxk,{className:"w-6 h-6 p-0 bg-white hover:bg-white hover:text-neutral-600 text-neutral-600 border border-border rounded-full",onClick:()=>{var e;return null===(e=s.current)||void 0===e?void 0:e.prev()},children:(0,r.jsx)(c.Z,{size:14})}),(0,r.jsx)(m.zxk,{className:"w-6 h-6 p-0 bg-white hover:bg-white hover:text-neutral-600 text-neutral-600 border border-border rounded-full",onClick:()=>{var e;return null===(e=s.current)||void 0===e?void 0:e.next()},children:(0,r.jsx)(v.Z,{size:14})})]})]})]})}var b=a(31683),x=a(85069),g=a(68055),_=a(54279);function h(e){let{name:l,image:a,price:i,children:t,currency:n,exchangeRate:o}=e,s=(0,g.eR)("checkout.payment.extras");return(0,r.jsxs)("div",{className:"w-full bg-secondary text-foreground overflow-hidden rounded-md border keen-slider__slide",children:[(0,r.jsx)("div",{className:"w-full pb-[60%] bg-black/20 relative overflow-hidden",children:(0,r.jsx)("img",{src:a,className:"object-cover h-full w-full absolute left-0 top-0",alt:l})}),(0,r.jsxs)("div",{className:"w-full px-4 py-2 flex flex-col",children:[(0,r.jsx)("h2",{className:"font-semibold h-[52px]",children:l}),(0,r.jsxs)("div",{className:"w-full flex flex-col mb-2",children:[(0,r.jsx)("p",{className:"text-xs opacity-60",children:s("common.startingAt")}),(0,r.jsx)("p",{children:(0,_.Z)(Number(i||0)*o,String(n||"USD"))})]}),t]})]})}var f=a(52958),w=a(39135),N=a(22034),j=a(8454);function S(e){let{label:l,value:a,setValue:i,min:t,max:n,disabled:o}=e;return(0,r.jsxs)("div",{className:"w-full flex justify-between",children:[(0,r.jsx)("div",{className:"w-full",children:(0,r.jsx)("p",{className:"font-semibold",children:l})}),(0,r.jsxs)("div",{className:"w-full flex items-center justify-end gap-4",children:[(0,r.jsx)(m.zxk,{size:"sm",className:"h-6 w-6 p-0 rounded-full",onClick:()=>{a>t&&i(a-1)},disabled:o,children:"-"}),(0,r.jsx)("div",{className:"w-6 text-center",children:(0,r.jsx)("p",{children:a})}),(0,r.jsx)(m.zxk,{size:"sm",className:"h-6 w-6 p-0 rounded-full",onClick:()=>{a<n&&i(a+1)},disabled:o,children:"+"})]})]})}function k(e){let{tripType:l,setTripType:a,origin:i,setOrigin:t,disabled:n,arrivalFlight:o,setArrivalFlight:s,departureFlight:u,setDepartureFlight:d,arrivalTime:c,setArrivalTime:v,departureTime:p,setDepartureTime:y,arrivalDate:b,setArrivalDate:x,departureDate:_,setDepartureDate:h}=e,f=(0,g.eR)("checkout.payment.extras");return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(m.Z0O,{}),(0,r.jsxs)("div",{className:"w-full flex justify-between items-center gap-2",children:[(0,r.jsx)("p",{className:"font-semibold w-full",children:f("checkout.flights.type")}),(0,r.jsx)("div",{className:"w-full flex gap-2 justify-end",children:["roundtrip","oneway"].map(e=>(0,r.jsx)(m.zxk,{size:"sm",variant:l===e?"default":"outline",onClick:()=>a(e),disabled:n,children:"roundtrip"===e?f("checkout.flights.roundtrip"):f("checkout.flights.oneWay")},e))})]}),(0,r.jsxs)("div",{className:"w-full flex justify-between items-center gap-2",children:[(0,r.jsx)("p",{className:"font-semibold w-full",children:f("checkout.flights.origin")}),(0,r.jsx)("div",{className:"w-full flex gap-2 justify-end",children:["airport","property"].map(e=>(0,r.jsx)(m.zxk,{size:"sm",variant:i===e?"default":"outline",onClick:()=>t(e),disabled:n,children:"airport"===e?f("checkout.flights.airport"):f("checkout.flights.property")},e))})]}),"airport"===i||"roundtrip"===l?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(m.Z0O,{}),(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsx)("p",{className:"text-xs font-semibold",children:f("checkout.flights.arrival")}),(0,r.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,r.jsx)(m.__J,{htmlFor:"flight-checkin",children:f("checkout.flights.flightAndAirline")}),(0,r.jsx)(m.IIB,{className:"w-full",id:"flight-checkin",type:"text",disabled:n,defaultValue:o,onChange:e=>s(e.target.value)})]}),(0,r.jsxs)("div",{className:"w-full flex gap-2",children:[(0,r.jsxs)("div",{className:"flex flex-col gap-2 w-full",children:[(0,r.jsx)(m.__J,{htmlFor:"date-checkin",children:f("checkout.flights.date")}),(0,r.jsx)(m.IIB,{className:"w-full",id:"date-checkin",type:"date",disabled:n,defaultValue:b,onChange:e=>x(e.target.value)})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-2 w-full",children:[(0,r.jsx)(m.__J,{htmlFor:"time-checkin",children:f("checkout.flights.time")}),(0,r.jsx)(m.IIB,{className:"w-full",id:"time-checkin",type:"time",disabled:n,defaultValue:c,onChange:e=>v(e.target.value)})]})]})]})]}):null,"oneway"===l&&"property"===i||"roundtrip"===l?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(m.Z0O,{}),(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsx)("p",{className:"text-xs font-semibold",children:f("checkout.flights.departure")}),(0,r.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,r.jsx)(m.__J,{htmlFor:"flight-checkout",children:f("checkout.flights.flightAndAirline")}),(0,r.jsx)(m.IIB,{className:"w-full",id:"flight-checkout",type:"text",disabled:n,defaultValue:u,onChange:e=>d(e.target.value)})]}),(0,r.jsxs)("div",{className:"w-full flex gap-2",children:[(0,r.jsxs)("div",{className:"flex flex-col gap-2 w-full",children:[(0,r.jsx)(m.__J,{htmlFor:"date-checkout",children:f("checkout.flights.date")}),(0,r.jsx)(m.IIB,{className:"w-full",id:"date-checkout",type:"date",disabled:n,defaultValue:_,onChange:e=>h(e.target.value)})]}),(0,r.jsxs)("div",{className:"flex flex-col gap-2 w-full",children:[(0,r.jsx)(m.__J,{htmlFor:"time-checkout",children:f("checkout.flights.time")}),(0,r.jsx)(m.IIB,{className:"w-full",id:"time-checkout",type:"time",disabled:n,defaultValue:p,onChange:e=>y(e.target.value)})]})]})]})]}):null]})}function P(e){var l,a,i,t,n,o,s,d,c,v,y,b;let{extra:x,checkin:h,checkout:P,image:C,occupancy:I,currency:R}=e,z=(0,g.eR)("checkout.payment.extras"),{currentCurrencyConversionRate:T}=(0,p.H)(),{extras:F,setExtras:M}=(0,j.z)(),[E,q]=(0,u.useState)(!1),[A,Z]=(0,u.useState)(1),[O,D]=(0,u.useState)(0),[B,G]=(0,u.useState)(1),[U,L]=(0,u.useState)(1),[H,V]=(0,u.useState)(""),[K,J]=(0,u.useState)(""),[W,Y]=(0,u.useState)(""),[$,Q]=(0,u.useState)(""),[X,ee]=(0,u.useState)(""),[el,ea]=(0,u.useState)(""),[er,ei]=(0,u.useState)((null==x?void 0:null===(l=x.extra_data)||void 0===l?void 0:l.serviceType)==="roundtrip"?"roundtrip":"oneway"),[et,en]=(0,u.useState)("airport"),eo=(null==x?void 0:x.price_quantity)!==0?null==x?void 0:x.price_quantity:(null==x?void 0:x.price_adults)!==0?null==x?void 0:x.price_adults:(null==x?void 0:x.price_children)!==0?null==x?void 0:x.price_children:(null==x?void 0:x.extra_data.onewayPrice)||0,[es,eu]=(0,u.useState)(Number(eo)),ed=null!=x&&null!==(a=x.extra_data)&&void 0!==a&&!!a.serviceType;(0,u.useEffect)(()=>{let e=(Number(null==x?void 0:x.price_adults)*A+Number(null==x?void 0:x.price_children)*O+Number(null==x?void 0:x.price_quantity)*B)*U,l="roundtrip"===er?Number(null==x?void 0:x.extra_data.roundtripPrice)*A+Number(null==x?void 0:x.extra_data.roundtripPrice)*O:Number(null==x?void 0:x.extra_data.onewayPrice)*A+Number(null==x?void 0:x.extra_data.onewayPrice)*O;eu(ed?l:e)},[A,O,B,U,er]);let ec=!!F.find(e=>String(e.extra_id)===String(null==x?void 0:x.id)),ev=Number(function(e,l){let a=Date.UTC(e.getFullYear(),e.getMonth(),e.getDate());return Math.floor((Date.UTC(l.getFullYear(),l.getMonth(),l.getDate())-a)/864e5)}(new Date(h),new Date(P))),em="roundtrip"===er,ep=ed&&(em&&(!H||!K||!W||!$||!X||!el)||!em&&("airport"===et?!H||!W||!X:!K||!$||!el));return(0,u.useEffect)(()=>{em||"property"!==et||(V(""),Y(""),ee(""))},[em,et]),(0,r.jsxs)(m.VqE,{open:E,onOpenChange:q,children:[(0,r.jsx)(m.hgM,{asChild:!0,children:(0,r.jsx)(m.zxk,{size:"sm",className:(0,m.cn)("w-full mb-2 gap-2 bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground",{"opacity-60":ec}),children:ec?(0,r.jsxs)(r.Fragment,{children:[z("common.added")," ",(0,r.jsx)(f.Z,{size:16})]}):(0,r.jsxs)(r.Fragment,{children:[z("common.add")," ",(0,r.jsx)(w.Z,{size:16})]})})}),(0,r.jsx)(m.cZJ,{className:"border-border shadow-none",children:(0,r.jsx)(m.xrM,{className:"pb-2 max-h-[560px]",children:(0,r.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,r.jsx)("div",{className:"pb-[50%] relative overflow-hidden rounded-md",children:C&&(0,r.jsx)("img",{alt:null==x?void 0:x.name,src:C,className:"object-cover h-full w-full absolute left-0 top-0"})}),(0,r.jsxs)("div",{className:"flex flex-col gap-2 w-full",children:[(null==x?void 0:x.availability_label)&&(0,r.jsx)(m.bZj,{variant:"warning",className:"h-auto py-2",children:(0,r.jsx)(m.XaZ,{children:null==x?void 0:x.availability_label})}),(0,r.jsx)("h4",{className:"font-semibold text-xl",children:null==x?void 0:x.name}),(null==x?void 0:x.description)&&(0,r.jsx)("p",{className:"text-sm mb-2",children:null==x?void 0:x.description}),(0,r.jsxs)("div",{className:"w-full flex flex-col gap-3 border p-4 rounded-sm",children:[ed?(null==I?void 0:null===(i=I[0])||void 0===i?void 0:i.adults)!==0&&(0,r.jsx)(S,{label:z("checkout.adults"),value:A,setValue:Z,min:1,max:Number(null==I?void 0:null===(t=I[0])||void 0===t?void 0:t.adults),disabled:ec}):(null==x?void 0:x.price_adults)!==0&&(0,r.jsx)(S,{label:z("checkout.adults"),value:A,setValue:Z,min:1,max:Number(null==I?void 0:null===(n=I[0])||void 0===n?void 0:n.adults),disabled:ec}),ed?(null==I?void 0:null===(o=I[0])||void 0===o?void 0:o.children)!==0&&(0,r.jsx)(S,{label:z("checkout.children"),value:O,setValue:D,min:1,max:Number(null==I?void 0:null===(s=I[0])||void 0===s?void 0:s.children),disabled:ec}):(null==I?void 0:null===(d=I[0])||void 0===d?void 0:d.children)!==0&&(null==x?void 0:x.price_children)!==0&&(0,r.jsx)(S,{label:z("checkout.children"),value:O,setValue:D,min:1,max:Number(null==I?void 0:null===(c=I[0])||void 0===c?void 0:c.children),disabled:ec}),!!(null==x?void 0:x.price_quantity)&&(0,r.jsx)(S,{label:z("checkout.quantity"),value:B,setValue:G,min:1,max:0!==Number(null==x?void 0:x.max_per_res)?Number(null==x?void 0:x.max_per_res):Number(null==I?void 0:null===(v=I[0])||void 0===v?void 0:v.adults)+Number(null==I?void 0:null===(y=I[0])||void 0===y?void 0:y.children),disabled:ec}),!(null==x?void 0:null===(b=x.extra_data)||void 0===b?void 0:b.serviceType)&&(null==x?void 0:x.multiple_days)&&1!==ev&&(0,r.jsx)(S,{label:z("checkout.days"),value:U,setValue:L,min:1,max:ev,disabled:ec}),ed&&(0,r.jsx)(k,{tripType:er,setTripType:ei,origin:et,setOrigin:en,disabled:ec,arrivalFlight:H,setArrivalFlight:V,departureFlight:K,setDepartureFlight:J,arrivalTime:W,setArrivalTime:Y,departureTime:$,setDepartureTime:Q,arrivalDate:X,setArrivalDate:ee,departureDate:el,setDepartureDate:ea})]}),(0,r.jsxs)("div",{className:"w-full flex justify-between my-2 items-center",children:[(0,r.jsx)("div",{className:"w-full",children:(0,r.jsx)("p",{className:"font-semibold text-lg",children:z("checkout.total")})}),(0,r.jsx)("div",{className:"w-full justify-end flex",children:(0,r.jsx)("p",{className:"text-lg",children:(0,_.Z)(Number(es*T),String(R||"USD"))})})]}),(0,r.jsx)(m.zxk,{size:"sm",className:"w-full gap-2 bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground",onClick:()=>{let e={extra_id:String(null==x?void 0:x.id),name:String(null==x?void 0:x.name),image:String(C),quantity:B,adults:A,children:O,days:U,travel_origin:"property"===et?"hotel":"airport",trip_type:er,arrival_date:X,departure_date:el,arrival_flight:H,departure_flight:K,arrival_time:W,departure_time:$};ec?M(F.filter(e=>String(e.extra_id)!==String(null==x?void 0:x.id))):(M([...F,e]),q(!1))},disabled:ep,children:ec?(0,r.jsxs)(r.Fragment,{children:[z("common.removeFromCart")," ",(0,r.jsx)(N.Z,{size:16})]}):(0,r.jsxs)(r.Fragment,{children:[z("common.addToCart")," ",(0,r.jsx)(w.Z,{size:16})]})})]})]})})})]})}function C(e){var l;let{website:a}=e,{currentReservation:i,currentCurrencyConversionRate:t}=(0,p.H)(),n=null==a?void 0:a.extras,o=new Date,s=(null==i?void 0:i.checkin)||"",u=(null==i?void 0:i.checkout)||"",d=(e,l)=>Math.ceil((e.getTime()-o.getTime())/864e5)>=l,c=null==n?void 0:n.map(e=>{var l;let a=null===(l=(0,x.Z)(null==e?void 0:e.images))||void 0===l?void 0:l.map(e=>(0,b.M)(e,"800")),r=0!==e.price_quantity?e.price_quantity:0!==e.price_adults?e.price_adults:0!==e.price_children?e.price_children:e.extra_data.onewayPrice;return d(new Date(s),e.min_prev_days)?{id:String(e.id),name:e.name,description:e.description,image:null==a?void 0:a[0],price:r}:null});return null==c?void 0:null===(l=c.filter(e=>null==e?void 0:e.name))||void 0===l?void 0:l.map(e=>{let l=null==n?void 0:n.find(l=>String(l.id)===String(null==e?void 0:e.id));return(0,r.jsx)(h,{name:null==e?void 0:e.name,image:null==e?void 0:e.image,price:null==e?void 0:e.price,currency:null==i?void 0:i.request_currency,exchangeRate:t,children:(0,r.jsx)(P,{extra:l,checkin:s,checkout:u,image:null==e?void 0:e.image,occupancy:null==i?void 0:i.occupancy,currency:null==i?void 0:i.request_currency})},null==e?void 0:e.id)})}function I(e){var l,a;let{website:i}=e,t=(null==i?void 0:null===(l=i.extras)||void 0===l?void 0:l.length)<3?3:null==i?void 0:null===(a=i.extras)||void 0===a?void 0:a.length;if("zavia"===i.property.type)return(0,r.jsx)(y,{length:t,children:(0,r.jsx)(C,{website:i})})}var R=a(72971),z=a(67754),T=a(55536),F=a(75190),M=a(66424),E=a(96874),q=a(98590),A=a.n(q),Z=a(95623),O=a(34690),D=a(3774),B=a(87876);function G(e){let{children:l,className:a}=e,i=(0,g.eR)("global.asyncStepper"),{toast:t}=(0,m.pmc)(),{currentStep:n,setCurrentStep:o,errorMessage:s,handleUpdateReservation:d,setErrorMessage:c}=(0,p.H)(),[v,y]=(0,u.useState)(!1);async function b(e){y(!0),c(null);let l=await d({current_step:e});if(l.errors){var a,r;t({title:null==l?void 0:null===(r=l.errors)||void 0===r?void 0:null===(a=r[0])||void 0===a?void 0:a.message}),console.error("updateReservationOnPaymentError",null==l?void 0:l.errors),y(!1)}else o(e),y(!1)}return(0,r.jsx)("div",{className:(0,m.cn)("w-full py-12 bg-secondary text-foreground flex items-center justify-center z-20 rounded-md border",a),children:(0,r.jsxs)("div",{className:"w-full flex flex-col justify-center items-center p-4 gap-4",children:[(0,r.jsx)("div",{className:"w-full flex gap-2 items-center justify-center",children:Array.from({length:3}).map((e,l)=>(n.includes("payment")||n.includes("itinerary")||n.includes("reservation"))&&0===l?(0,r.jsx)("div",{className:(0,m.cn)("h-8 w-8 bg-foreground text-secondary flex items-center justify-center rounded-full opacity-10",{"bg-green-600 text-white opacity-100":n.includes("payment_success")||n.includes("itinerary")||n.includes("reservation"),"bg-red-600 text-white opacity-100":n.includes("payment_error"),"bg-foreground text-secondary opacity-100":n.includes("payment_processing")}),children:n.includes("payment_success")||n.includes("itinerary")||n.includes("reservation")?(0,r.jsx)(f.Z,{size:18}):n.includes("payment_error")?(0,r.jsx)(Z.Z,{size:18}):n.includes("payment_processing")?(0,r.jsx)(O.Z,{size:18,className:"animate-spin"}):(0,r.jsx)(D.Z,{size:18})},l):(n.includes("itinerary")||n.includes("reservation"))&&1===l?(0,r.jsx)("div",{className:(0,m.cn)("h-8 w-8 bg-foreground text-secondary flex items-center justify-center rounded-full opacity-10",{"bg-green-600 text-white opacity-100":n.includes("itinerary_success")||n.includes("reservation"),"bg-red-600 text-white opacity-100":n.includes("itinerary_error"),"bg-foreground text-secondary opacity-100":n.includes("itinerary_processing")}),children:n.includes("itinerary_success")||n.includes("reservation")?(0,r.jsx)(f.Z,{size:18}):n.includes("itinerary_error")?(0,r.jsx)(Z.Z,{size:18}):n.includes("itinerary_processing")?(0,r.jsx)(O.Z,{size:18,className:"animate-spin"}):(0,r.jsx)(D.Z,{size:18})},l):n.includes("reservation")&&2===l?(0,r.jsx)("div",{className:(0,m.cn)("h-8 w-8 bg-foreground text-secondary flex items-center justify-center rounded-full opacity-10",{"bg-green-600 text-white opacity-100":n.includes("reservation_success"),"bg-red-600 text-white opacity-100":n.includes("reservation_error"),"bg-foreground text-secondary opacity-100":n.includes("reservation_processing")}),children:n.includes("reservation_success")?(0,r.jsx)(f.Z,{size:18}):n.includes("reservation_error")?(0,r.jsx)(Z.Z,{size:18}):n.includes("reservation_processing")?(0,r.jsx)(O.Z,{size:18,className:"animate-spin"}):(0,r.jsx)(D.Z,{size:18})},l):(0,r.jsx)("div",{className:"h-8 w-8 bg-foreground text-secondary flex items-center justify-center rounded-full opacity-10",children:(0,r.jsx)(D.Z,{size:18})},l))}),(0,r.jsxs)("div",{className:"w-full flex items-center flex-col",children:[(0,r.jsxs)("p",{className:"font-semibold",children:[n.includes("payment_processing")&&i("payment.processing"),n.includes("payment_success")&&i("payment.success"),n.includes("payment_error")&&i("payment.error"),n.includes("itinerary_processing")&&i("itinerary.processing"),n.includes("itinerary_success")&&i("itinerary.success"),n.includes("itinerary_error")&&i("itinerary.error"),n.includes("reservation_processing")&&i("reservation.processing"),n.includes("reservation_success")&&i("reservation.success"),n.includes("reservation_error")&&i("reservation.error")]}),(0,r.jsx)("p",{className:"text-xs opacity-60",children:i("disclaimer")})]}),n.includes("error")&&(0,r.jsx)("div",{className:"w-full flex justify-center items-center",children:s&&(0,r.jsx)("div",{className:"w-fit flex items-center justify-center border border-red-500 bg-red-100 text-red-900 rounded-lg py-2 px-4",children:(0,r.jsx)("p",{className:"text-sm font-semibold",children:s})})}),n.includes("payment_error")&&(0,r.jsxs)(m.zxk,{size:"sm",className:"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground gap-2",onClick:()=>b("payment_retry"),disabled:v,children:[i("paymentErrorButton")," ",v?(0,r.jsx)(O.Z,{size:14,className:"animate-spin"}):(0,r.jsx)(B.Z,{size:14})]}),(0,r.jsx)("div",{className:"w-full flex items-center justify-center",children:l})]})})}var U=a(19808),L=a(43011),H=a(19793),V=a(59668);function K(e){let{retriesFromCurrentStepGlobal:l,currentStep:a,locale:i,params:t,loading:n,createItineraryAction:o}=e,s=(0,g.rj)(),{toast:d}=(0,m.pmc)(),[c,v]=(0,u.useState)(!1),{handleCancelPayment:y,currentReservation:b,handleUpdateReservation:x,handleUpdatePayment:_}=(0,p.H)();async function h(){var e,l;v(!0);let a=await (0,V.Iox)(V.OFs,{id:null==b?void 0:b.id}),r=null==a?void 0:a.data.reservations_by_pk,i=await y({orderReference:null==r?void 0:r.order_reference,paymentReference:null==r?void 0:r.payment_reference,amount:null==r?void 0:null===(l=r.metadata)||void 0===l?void 0:null===(e=l.payment)||void 0===e?void 0:e.amount_paid});i.result.success?(await x({status:"refunded"}),await _({orderReference:null==r?void 0:r.order_reference,paymentReference:null==r?void 0:r.payment_reference,params:{status:"REFUNDED"}}),d({title:s("global.asyncStepper.itinerary.requestRefund.success")}),await new Promise(e=>setTimeout(e,2e3))):(await x({status:"refund_error",error_message:i.result.message}),d({title:s("global.asyncStepper.itinerary.requestRefund.error")}),console.error("errorOnRefundPaymentAfterRetryItinerary",i.result.message),await new Promise(e=>setTimeout(e,2e3))),window.location.reload(),v(!1)}return(0,r.jsxs)(r.Fragment,{children:[l>=3?a.includes("itinerary")?(0,r.jsxs)("div",{className:"w-full flex flex-col gap-2 items-center justify-center",children:[(0,r.jsxs)("p",{className:"max-w-xl mx-auto text-sm text-center text-foreground",children:[s("global.asyncStepper.itinerary.afterRetryMessageOne")," ",(0,r.jsx)("b",{children:s("global.asyncStepper.itinerary.afterRetryMessageTwo")})]}),(0,r.jsx)("div",{className:"max-w-md mx-auto w-full mt-2 text-center",children:(0,r.jsxs)(m.zxk,{size:"sm",variant:"outline",className:"bg-transparent border-amber-500 hover:border-amber-500 text-amber-500 hover:bg-transparent hover:text-amber-500 gap-2 w-fit mx-auto",onClick:()=>h(),disabled:(null==b?void 0:b.status)==="refunded"||c,children:[(null==b?void 0:b.status)==="refunded"?s("global.asyncStepper.itinerary.requestRefund.refunded"):s("global.asyncStepper.itinerary.requestRefund.button")," ",c?(0,r.jsx)(O.Z,{size:14,className:"animate-spin"}):(0,r.jsx)(L.Z,{size:14})]})})]}):(0,r.jsxs)("div",{className:"w-full flex flex-col gap-2 items-center justify-center",children:[(0,r.jsx)("p",{className:"max-w-xl mx-auto text-sm text-center text-foreground",children:s("global.asyncStepper.reservation.afterRetryMessage")}),(0,r.jsx)(U.default,{href:"/".concat(i,"/guest/reservation?").concat(t.toString()),children:(0,r.jsxs)(m.zxk,{size:"sm",className:"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground gap-2 w-fit mx-auto",children:[s("global.asyncStepper.goToReservation"),(0,r.jsx)(H.Z,{size:14})]})})]}):a.includes("itinerary_error")?(0,r.jsxs)(m.zxk,{size:"sm",className:"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground gap-2",onClick:()=>o(),disabled:n,children:[s("global.asyncStepper.itineraryErrorButton")," (",l," / 3)",n?(0,r.jsx)(O.Z,{size:14,className:"animate-spin"}):(0,r.jsx)(B.Z,{size:14})]}):a.includes("reservation_error")?(0,r.jsxs)(m.zxk,{size:"sm",className:"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground gap-2",onClick:()=>o(),disabled:n,children:[s("global.asyncStepper.reservationErrorButton")," (",l," / 3)",n?(0,r.jsx)(O.Z,{size:14,className:"animate-spin"}):(0,r.jsx)(B.Z,{size:14})]}):null,"reservation_success"===a&&(0,r.jsxs)("div",{className:"w-full flex flex-col items-center justify-center gap-2",children:[(0,r.jsx)("p",{className:"text-sm font-semibold text-foreground",children:s("global.asyncStepper.redirectToReservation")}),(0,r.jsx)(O.Z,{size:16,className:"animate-spin"})]})]})}var J=a(4750),W=a(29870),Y=a(15813),$=a(69363);function Q(e){let{widgetToken:l,locale:a,setPaymentMethod:i}=e,t=(0,g.eR)("checkout.payment"),{extras:n,totalsExtras:o}=(0,j.z)(),{currentStep:s,setCurrentStep:d,currentReservation:c,handleUpdateReservation:v,setErrorMessage:y,paymentIntent:b}=(0,p.H)(),[x,_]=(0,u.useState)(!1),[h,f]=(0,u.useState)(!1),w=async()=>{i(null),_(!1),d("guest_information"),await new Promise(e=>setTimeout(e,50)),i("FINTOC")},N=async()=>{d("fintoc_payment_success"),_(!1),y(null)},S=async e=>{if("opened"===e&&d("fintoc_payment_initializing"),"payment_created"===e){var l,a,r,i,t,s,u,m,p,x,g,h,f,w,N,j,S,k,P,C,I,R,z,T,F,M;_(!0);let e=(null==c?void 0:c.provider)==="zavia"?{metadata:{...null==c?void 0:c.metadata,payment:{...null==c?void 0:null===(l=c.metadata)||void 0===l?void 0:l.payment,status:"PAID",amount_paid:Number((null==b?void 0:b.amount_paid)||0)},extras:n},subtotal_extras:(null==o?void 0:null===(a=o.requested)||void 0===a?void 0:a.extras_subtotal)?String(null==o?void 0:null===(r=o.requested)||void 0===r?void 0:r.extras_subtotal):null,taxes_extras:(null==o?void 0:null===(i=o.requested)||void 0===i?void 0:i.extras_taxes)?String(null==o?void 0:null===(t=o.requested)||void 0===t?void 0:t.extras_taxes):null,total_extras:(null==o?void 0:null===(s=o.requested)||void 0===s?void 0:s.extras_total)?String(null==o?void 0:null===(u=o.requested)||void 0===u?void 0:u.extras_total):null,pay_now_with_extras:(null==o?void 0:null===(p=o.requested)||void 0===p?void 0:null===(m=p.policyPayment)||void 0===m?void 0:m.pay_now_with_extras)?String(null==o?void 0:null===(g=o.requested)||void 0===g?void 0:null===(x=g.policyPayment)||void 0===x?void 0:x.pay_now_with_extras):null,pay_later_with_extras:(null==o?void 0:null===(f=o.requested)||void 0===f?void 0:null===(h=f.policyPayment)||void 0===h?void 0:h.pay_later_with_extras)?String(null==o?void 0:null===(N=o.requested)||void 0===N?void 0:null===(w=N.policyPayment)||void 0===w?void 0:w.pay_later_with_extras):null,total_with_extras:(null==o?void 0:null===(j=o.requested)||void 0===j?void 0:j.total_with_extras)?String(null==o?void 0:null===(S=o.requested)||void 0===S?void 0:S.total_with_extras):null,totals:{requested:{...null==c?void 0:null===(k=c.totals)||void 0===k?void 0:k.requested,...null==o?void 0:o.requested,policyPayment:{...null==c?void 0:null===(C=c.totals)||void 0===C?void 0:null===(P=C.requested)||void 0===P?void 0:P.policyPayment,...null==o?void 0:null===(I=o.requested)||void 0===I?void 0:I.policyPayment}},converted:(null==c?void 0:null===(R=c.totals)||void 0===R?void 0:R.converted)!==null?{...null==c?void 0:null===(z=c.totals)||void 0===z?void 0:z.converted,...null==o?void 0:o.converted,policyPayment:{...null==c?void 0:null===(F=c.totals)||void 0===F?void 0:null===(T=F.converted)||void 0===T?void 0:T.policyPayment,...null==o?void 0:null===(M=o.converted)||void 0===M?void 0:M.policyPayment}}:null}}:{};await v({current_step:"fintoc_payment_success",...e})}"on_error"===e&&(await v({current_step:"fintoc_payment_error",error_message:"Fintoc payment error"}),d("fintoc_payment_error"),_(!1),console.error("fintocPaymentError","Fintoc payment error"),y(String("Fintoc payment error")))},k=async()=>{let e=await (0,Y.Jz)();if(s.includes("payment_success"))return;let a=null==e?void 0:e.create({holderType:"individual",product:"payments",country:"mx",publicKey:"pk_test_yPizhishxb9xPV2r_YqFY1YWt6wyT7oz",widgetToken:l,onSuccess:N,onExit:w,onEvent:S});null==a||a.open()};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)($.Z,{locale:a,state:h,setState:f}),(0,r.jsx)(m.zxk,{disabled:x||!h,className:"w-full mt-4 bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground text-md font-semibold",size:"lg",onClick:()=>k(),children:x?(0,r.jsx)(O.Z,{size:16,className:"animate-spin"}):t("payAndReserve")})]})}function X(e){var l;let{setPaymentMethod:a}=e,{paymentIntent:i,currentReservation:t}=(0,p.H)(),n=(null==i?void 0:i.metadata)?null===(l=JSON.parse((null==i?void 0:i.metadata)||""))||void 0===l?void 0:l.widget_token:null,o=(null==t?void 0:t.lang)==="es"?"es":"en";return n?(0,r.jsx)("div",{className:"w-full",children:n&&(0,r.jsx)(Q,{widgetToken:n,locale:o,setPaymentMethod:a})}):null}var ee=a(97583),el=a(37938);async function ea(e,l,a){return(0,el.J)("MXN"===e?"pk_live_iCrWGqRumuqvHqdpyEtVeddM00ZBETolW3":"pk_live_KGXmbziXnZ67rTTGylr0Ro2P00LjpVt6mW",a?{locale:l,stripeAccount:a}:{locale:l})}function er(e){let{clientSecret:l,locale:a}=e,i=(0,g.eR)("checkout.payment"),{extras:t,totalsExtras:n}=(0,j.z)(),{currentStep:o,setCurrentStep:s,currentReservation:d,handleUpdateReservation:c,setErrorMessage:v}=(0,p.H)(),y=(0,ee.useStripe)(),b=(0,ee.useElements)(),[x,_]=(0,u.useState)(!1),[h,f]=(0,u.useState)(!1),w=async e=>{var r,i,u,m,p,x,g,h,f,w,N,j,S,k,P,C,I,R,z,T,F,M,E,q,A,Z;if(e.preventDefault(),!y||!b||o.includes("payment_success"))return;_(!0);let O=(null==d?void 0:d.provider)==="zavia"?{metadata:{...null==d?void 0:d.metadata,extras:t},subtotal_extras:(null==n?void 0:null===(r=n.requested)||void 0===r?void 0:r.extras_subtotal)?String(null==n?void 0:null===(i=n.requested)||void 0===i?void 0:i.extras_subtotal):null,taxes_extras:(null==n?void 0:null===(u=n.requested)||void 0===u?void 0:u.extras_taxes)?String(null==n?void 0:null===(m=n.requested)||void 0===m?void 0:m.extras_taxes):null,total_extras:(null==n?void 0:null===(p=n.requested)||void 0===p?void 0:p.extras_total)?String(null==n?void 0:null===(x=n.requested)||void 0===x?void 0:x.extras_total):null,pay_now_with_extras:(null==n?void 0:null===(h=n.requested)||void 0===h?void 0:null===(g=h.policyPayment)||void 0===g?void 0:g.pay_now_with_extras)?String(null==n?void 0:null===(w=n.requested)||void 0===w?void 0:null===(f=w.policyPayment)||void 0===f?void 0:f.pay_now_with_extras):null,pay_later_with_extras:(null==n?void 0:null===(j=n.requested)||void 0===j?void 0:null===(N=j.policyPayment)||void 0===N?void 0:N.pay_later_with_extras)?String(null==n?void 0:null===(k=n.requested)||void 0===k?void 0:null===(S=k.policyPayment)||void 0===S?void 0:S.pay_later_with_extras):null,total_with_extras:(null==n?void 0:null===(P=n.requested)||void 0===P?void 0:P.total_with_extras)?String(null==n?void 0:null===(C=n.requested)||void 0===C?void 0:C.total_with_extras):null,totals:{requested:{...null==d?void 0:null===(I=d.totals)||void 0===I?void 0:I.requested,...null==n?void 0:n.requested,policyPayment:{...null==d?void 0:null===(z=d.totals)||void 0===z?void 0:null===(R=z.requested)||void 0===R?void 0:R.policyPayment,...null==n?void 0:null===(T=n.requested)||void 0===T?void 0:T.policyPayment}},converted:(null==d?void 0:null===(F=d.totals)||void 0===F?void 0:F.converted)!==null?{...null==d?void 0:null===(M=d.totals)||void 0===M?void 0:M.converted,...null==n?void 0:n.converted,policyPayment:{...null==d?void 0:null===(q=d.totals)||void 0===q?void 0:null===(E=q.converted)||void 0===E?void 0:E.policyPayment,...null==n?void 0:null===(A=n.converted)||void 0===A?void 0:A.policyPayment}}:null}}:{};if(await c({current_step:"stripe_payment_processing",...O}),s("stripe_payment_processing"),(await y.retrievePaymentIntent(l)).error){_(!1);return}let D=await y.confirmPayment({elements:b,redirect:"if_required",confirmParams:{return_url:"https://".concat(window.location.host,"/").concat(a,"/checkout/payment?payment=success")}});D.error?(await c({current_step:"stripe_payment_error",error_message:D.error.message}),s("stripe_payment_error"),_(!1),console.error("stripePaymentError",D.error.message),v(String(D.error.message))):(await c({current_step:"stripe_payment_success",metadata:{...null==d?void 0:d.metadata,payment:{...null==d?void 0:null===(Z=d.metadata)||void 0===Z?void 0:Z.payment,status:"PAID",amount_paid:D.paymentIntent.amount},extras:t},error_message:null}),s("stripe_payment_success"),_(!1),v(null))};return(0,r.jsxs)("form",{onSubmit:w,className:"w-full",children:[(0,r.jsx)("div",{className:"w-full min-h-[200px]",children:(0,r.jsx)(ee.PaymentElement,{options:{layout:"accordion"}})}),(0,r.jsx)($.Z,{locale:a,state:h,setState:f}),(0,r.jsx)(m.zxk,{type:"submit",disabled:!y||!b||x||!h,className:"w-full mt-4 bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground text-md font-semibold",size:"lg",children:x?(0,r.jsx)(O.Z,{size:16,className:"animate-spin"}):i("payAndReserve")})]})}function ei(){var e,l,a,i,t,n,o;let{paymentIntent:s,currentReservation:u}=(0,p.H)(),d=(null==s?void 0:s.metadata)?null===(e=JSON.parse((null==s?void 0:s.metadata)||""))||void 0===e?void 0:e.client_secret:null,c=(null==u?void 0:null===(a=u.metadata)||void 0===a?void 0:null===(l=a.payment)||void 0===l?void 0:l.account_currency)||(null==u?void 0:null===(t=u.metadata)||void 0===t?void 0:null===(i=t.payment)||void 0===i?void 0:i.currency)||(null==u?void 0:u.currency)||"USD",v=null==u?void 0:null===(o=u.metadata)||void 0===o?void 0:null===(n=o.payment)||void 0===n?void 0:n.account,m=(null==u?void 0:u.lang)==="es"?"es":"en";return d?(0,r.jsx)("div",{className:"w-full",children:d&&(0,r.jsx)(ee.Elements,{stripe:ea(c,m,v),options:{clientSecret:d,appearance:{theme:"flat",variables:{colorPrimary:"#444444",colorText:"#444444",colorDanger:"#df1b41",fontFamily:"DM Sans, sans-serif",spacingUnit:"4px"}},fonts:[{cssSrc:"https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=Inter:wght@400;500;700"}]},children:(0,r.jsx)(er,{clientSecret:d,locale:m})})}):null}function et(e){let{allowedMethods:l,paymentMethod:a,setPaymentMethod:i,loadingPayment:t}=e,n=(0,g.eR)("checkout.payment"),o=[{id:"STRIPE",image:"/payment-methods/stripe.svg",description:n("methods.stripe.description"),name:"Stripe"},{id:"FINTOC",image:"/payment-methods/fintoc.svg",description:n("methods.fintoc.description"),name:"Fintoc"}];return(0,r.jsxs)("div",{className:"w-full flex flex-col bg-neutral-100 text-neutral-950 p-2 rounded-md border border-neutral-200",children:[(0,r.jsx)(W.Z,{}),o.filter(e=>l.includes(e.id)).map(e=>(0,r.jsxs)("div",{className:(0,m.cn)("bg-white rounded-md border mb-3 p-6 ring-1 ring-transparent hover:ring-neutral-300",{"ring-neutral-300 hover:ring-neutral-300":e.id===a}),children:[(0,r.jsxs)("div",{className:"flex items-center gap-6",onClick:()=>i(e.id),role:"button",children:[(0,r.jsx)("div",{className:(0,m.cn)("w-[20px] flex justify-center h-[20px] rounded-full ring-1 ring-neutral-200 bg-white shrink-0 items-center",{"bg-neutral-950 text-white":e.id===a}),children:(0,r.jsx)("span",{className:(0,m.cn)("w-[12px] h-[12px] rounded-full bg-white flex")})}),(0,r.jsxs)("div",{className:"w-full flex flex-col gap-1",children:[(0,r.jsx)("div",{children:(0,r.jsx)("img",{src:e.image,alt:e.name,className:"h-5 max-w-[70px]"})}),(0,r.jsx)("p",{className:"text-sm",children:e.description})]})]}),(0,r.jsx)("div",{className:(0,m.cn)("w-full",{"mt-3":e.id===a}),children:t?e.id===a&&(0,r.jsx)(m.OdW,{className:(0,m.cn)("w-full h-96 opacity-20",{"h-20":"FINTOC"===a})}):(0,r.jsx)(en,{setPaymentMethod:i,paymentMethod:e.id,active:a})})]},e.id))]})}function en(e){let{setPaymentMethod:l,paymentMethod:a,active:i}=e;return"STRIPE"===a?"STRIPE"===i?(0,r.jsx)(ei,{}):null:"FINTOC"===a&&"FINTOC"===i?(0,r.jsx)(X,{setPaymentMethod:l}):null}var eo=a(96181);function es(e){let l=e.replace(/\s+/g,"").replace(/[^0-9]/gi,"").substr(0,16),a=[];for(let e=0;e<l.length;e+=4)a.push(l.substr(e,4));return a.length>1?a.join(" "):e}function eu(e){return e.replace(/[^0-9]/g,"").replace(/^([2-9])$/g,"0$1").replace(/^(1{1})([3-9]{1})$/g,"0$1/$2").replace(/^0{1,}/g,"0").replace(/^([0-1]{1}[0-9]{1})([0-9]{1,2}).*/g,"$1/$2")}function ed(e){let{onChange:l}=e,a=(0,g.eR)("checkout.payment"),{currentStep:i,setCurrentStep:t,handleUpdateReservation:n}=(0,p.H)(),[o,s]=(0,u.useState)(!1),[d,c]=(0,u.useState)({number:"",expiry:"",cvc:""});(0,u.useEffect)(()=>{if(l){var e,a,r;l({cvc:d.cvc,month:null===(e=d.expiry)||void 0===e?void 0:e.slice(0,2),number:null===(a=d.number)||void 0===a?void 0:a.replaceAll(/\s/g,""),year:null===(r=d.expiry)||void 0===r?void 0:r.slice(3,5)})}},[d]);let v=async e=>{e.preventDefault(),"plain_form_payment_success"!==i&&(s(!0),await n({current_step:"plain_form_payment_success",error_message:null}),t("plain_form_payment_success"),s(!1))};function y(e){let l=e.code;"Backspace"!==l&&"Delete"!==l&&"Tab"!==l&&(/^[0-9]$/.test(e.key)||e.preventDefault())}return(0,r.jsxs)("form",{onSubmit:v,className:"w-full",children:[(0,r.jsxs)("div",{className:"w-full flex flex-col gap-4",children:[(0,r.jsxs)("div",{className:"w-full flex gap-6 items-center",children:[(0,r.jsx)(M.Z,{size:18,className:"text-neutral-600",strokeWidth:2.4}),(0,r.jsx)(m.__J,{className:"font-semibold",children:a("methods.plainForm.title")})]}),(0,r.jsxs)("div",{className:"w-full grid grid-cols-2 md:grid-cols-4 gap-4",children:[(0,r.jsxs)("div",{className:"w-full flex flex-col gap-1 col-span-2",children:[(0,r.jsx)(m.__J,{htmlFor:"card",className:"text-neutral-600 text-sm",children:a("methods.plainForm.number")}),(0,r.jsxs)("div",{className:"w-full relative flex items-center",children:[(0,r.jsx)(m.IIB,{id:"card",type:"text",placeholder:"1234 1234 1234 1234",required:!0,className:"w-full bg-neutral-100 rounded-xl h-auto py-3 px-4 placeholder:text-neutral-400 focus-visible:ring-neutral-200 text-md border-none",value:es(d.number),onChange:e=>{let l=e.target.value;c(e=>({...e,number:es(l)}))},onKeyDown:e=>{y(e)}}),(0,r.jsx)(M.Z,{size:16,className:"absolute right-3 text-neutral-300"})]})]}),(0,r.jsxs)("div",{className:"w-full flex flex-col gap-1",children:[(0,r.jsx)(m.__J,{htmlFor:"expiry",className:"text-neutral-600 text-sm",children:a("methods.plainForm.expiry")}),(0,r.jsx)(m.IIB,{id:"expiry",type:"text",placeholder:"MM / AA",required:!0,className:"w-full bg-neutral-100 rounded-xl h-auto py-3 px-4 placeholder:text-neutral-400 focus-visible:ring-neutral-200 text-md border-none",value:eu(d.expiry),onChange:e=>{let l=e.target.value;c(e=>({...e,expiry:eu(l)}))},onKeyDown:e=>{y(e)}})]}),(0,r.jsxs)("div",{className:"w-full flex flex-col gap-1",children:[(0,r.jsx)(m.__J,{htmlFor:"cvc",className:"text-neutral-600 text-sm",children:a("methods.plainForm.cvc")}),(0,r.jsxs)("div",{className:"w-full relative flex items-center",children:[(0,r.jsx)(m.IIB,{id:"cvc",type:"text",placeholder:"CVC",required:!0,className:"w-full bg-neutral-100 rounded-xl h-auto py-3 px-4 placeholder:text-neutral-400 focus-visible:ring-neutral-200 text-md border-none",minLength:3,maxLength:4,onChange:e=>{let l=e.target.value;(null==l?void 0:l.replace(/[^\d]/g,""))&&c(l=>({...l,cvc:e.target.value.replace(/\D/g,"")}))},onKeyDown:e=>{y(e)}}),(0,r.jsx)(eo.Z,{size:16,className:"absolute right-3 text-neutral-300"})]})]})]})]}),(0,r.jsx)(m.zxk,{type:"submit",disabled:o,className:"w-full mt-4 bg-green-500 hover:bg-green-600 text-md font-semibold",size:"lg",children:o?(0,r.jsx)(O.Z,{size:16,className:"animate-spin"}):a("methods.plainForm.submit")})]})}function ec(e){let{onChange:l}=e,a=(0,g.eR)("checkout.payment.methods.plainForm");return(0,r.jsxs)("div",{className:"w-full bg-neutral-100 text-neutral-950 p-2 rounded-md border border-neutral-200",children:[(0,r.jsx)("div",{className:"border border-amber-800/10 bg-yellow-500/10 text-amber-600 text-sm py-1 px-3 text-center rounded-md mb-4",children:(0,r.jsx)("p",{className:"text-center mx-auto max-w-lg",children:a("disclaimer")})}),(0,r.jsx)(W.Z,{}),(0,r.jsx)("div",{className:"bg-white rounded-lg p-4",children:(0,r.jsx)(ed,{onChange:l})})]})}function ev(e){var l,a,i,t,n,o,s;let{website:d}=e,c=(0,g.rj)(),v=(0,z.useRouter)(),{currentReservation:y,currentStep:b,setCurrentStep:x,handleUpdateReservation:h,handleUpdatePayment:f,setErrorMessage:w,paymentIntent:N,setPaymentIntent:j,handleCreatePayment:S,currentCurrencyConversionRate:k}=(0,p.H)(),P=null==d?void 0:d.providerOptions,C=null==P?void 0:P.pay_online,I=null==P?void 0:P.pay_at_hotel,R=C&&I,q=(null==y?void 0:y.lang)||"en",Z=(null==y||y.currency,(0,J.r)()),O=(0,J.o)(),[D,B]=(0,u.useState)("STRIPE"),[U,L]=(0,u.useState)(Number(null==y?void 0:y.total)),[H,V]=(0,u.useState)("payOnline"),[W,Y]=(0,u.useState)(),[$,Q]=(0,u.useState)(!1),[X,ee]=(0,u.useState)(!1),[el,ea]=(0,u.useState)((null==y?void 0:y.itinerary_id)||null),er=A().generate(),ei=new URLSearchParams;ei.set("email",(null==y?void 0:null===(l=y.guest)||void 0===l?void 0:l.email)||""),ei.set("itineraryId",String(el));let en=Number((null==b?void 0:b.match(/\d+/))||0);(0,u.useEffect)(()=>{L("payOnline"===H?Number(null==y?void 0:y.total):I?P.deposit&&0!==Number(P.deposit||0)?Number((null==y?void 0:y.total)||0)*(Number(P.deposit||0)/100):0:Number(null==y?void 0:y.total))},[H]);let eo="payOnline"===H?{pay_now:Number(U).toFixed(2),pay_later:String(0),totals:{requested:{...null==y?void 0:null===(a=y.totals)||void 0===a?void 0:a.requested,policyPayment:{pay_now:Number(Number(U).toFixed(2)),pay_later:Number(0)}},converted:(null==y?void 0:y.currency)!==(null==y?void 0:y.request_currency)?{...null==y?void 0:null===(i=y.totals)||void 0===i?void 0:i.converted,policyPayment:{pay_now:Number(Number(U*k).toFixed(2)),pay_later:Number(0)}}:null}}:{pay_now:Number(U).toFixed(2),pay_later:Number(Number(null==y?void 0:y.total)-U).toFixed(2),totals:{requested:{...null==y?void 0:null===(t=y.totals)||void 0===t?void 0:t.requested,policyPayment:{pay_now:Number(Number(U).toFixed(2)),pay_later:Number(Number(Number(null==y?void 0:y.total)-U).toFixed(2))}},converted:(null==y?void 0:y.currency)!==(null==y?void 0:y.request_currency)?{...null==y?void 0:null===(n=y.totals)||void 0===n?void 0:n.converted,policyPayment:{pay_now:Number(Number(U*k).toFixed(2)),pay_later:Number(Number(Number(Number(null==y?void 0:y.total)-U)*k).toFixed(2))}}:null}};(0,u.useEffect)(()=>{(async()=>{var e,l,a,r,i,t,n,o;Q(!0),j(null);let s=await S({orderReference:er,currency:null==y?void 0:y.currency,amount:Math.round(100*U),monthlyInstallments:!0,paymentMethod:"STRIPE"===D?"CARD":D,paymentProvider:D,gurufee:Math.round(100*Number((null==y?void 0:y.fee)||0)),futureUsage:!0,client:{client_reference:"Client-".concat(er),name:"".concat(null==y?void 0:null===(e=y.guest)||void 0===e?void 0:e.first_name," ").concat(null==y?void 0:null===(l=y.guest)||void 0===l?void 0:l.last_name),email:null==y?void 0:null===(a=y.guest)||void 0===a?void 0:a.email,phone:"+".concat(null==y?void 0:null===(r=y.guest)||void 0===r?void 0:r.phoneCode).concat(null==y?void 0:null===(i=y.guest)||void 0===i?void 0:i.phone)},business:{business_reference:String(null==d?void 0:null===(t=d.property)||void 0===t?void 0:t.id),name:d.name},origin:"HOTELS"});await h({order_reference:null==s?void 0:null===(n=s.payment)||void 0===n?void 0:n.order_reference,payment_reference:null==s?void 0:null===(o=s.payment)||void 0===o?void 0:o.payment_reference,payment_provider:D,...eo}),j(null==s?void 0:s.payment),await new Promise(e=>setTimeout(e,2e3)),Q(!1)})()},[U,D]);let es=null===(o=T.find(e=>{var l;return e.name.toUpperCase()===(null==y?void 0:null===(l=y.guest)||void 0===l?void 0:l.country.toUpperCase())}))||void 0===o?void 0:o.iso2,eu=(0,u.useCallback)(async(e,l,a)=>{var r,i,t,n,o,s,u,d,c,m,p,g,_,N,j,S,k,P,C,I,R,z,T,F,M,A,D,B;ee(!0);let G=Number((null==b?void 0:b.match(/\d+/))||0)+1;if("itinerary_success"!==b){if(b.includes("reservation_error")){let e=await h({status:"booked",current_step:"reservation_success",error_message:null});if(e.errors)await h({current_step:"reservation_error_".concat(Number(G)),error_message:null==e?void 0:null===(i=e.errors)||void 0===i?void 0:null===(r=i[0])||void 0===r?void 0:r.message}),x("reservation_error_".concat(Number(G))),console.error("updateReservationOnReservationError",null==e?void 0:e.errors),w(null==e?void 0:null===(n=e.errors)||void 0===n?void 0:null===(t=n[0])||void 0===t?void 0:t.message),ee(!1);else{w(null),x("reservation_success"),await new Promise(e=>setTimeout(e,2e3));let e=new URLSearchParams;e.set("email",(null==y?void 0:null===(o=y.guest)||void 0===o?void 0:o.email)||""),e.set("itineraryId",String(el)),await new Promise(e=>setTimeout(e,2e3));let l="/".concat(q,"/guest/reservation?").concat(e.toString());v.replace(l)}}else{await h({current_step:"itinerary_processing"}),x("itinerary_processing");let r=await (0,E.Z)(String("itineraries/book?token=".concat(el)),{},{payment:{status:0===U?"details_only":"paid",amount:U.toFixed(2),currency:null==y?void 0:y.currency,method:"credit_card",payment_reference:null==l?void 0:l.payment_reference,order_reference:null==l?void 0:l.order_reference},guest:{first_name:null==y?void 0:null===(s=y.guest)||void 0===s?void 0:s.first_name,last_name:null==y?void 0:null===(u=y.guest)||void 0===u?void 0:u.last_name,email:null==y?void 0:null===(d=y.guest)||void 0===d?void 0:d.email,phone:null==y?void 0:null===(c=y.guest)||void 0===c?void 0:c.phone,phone_code:null==y?void 0:null===(m=y.guest)||void 0===m?void 0:m.phoneCode,address:null==y?void 0:null===(p=y.guest)||void 0===p?void 0:p.billing_address,country:es,state:null==y?void 0:null===(g=y.guest)||void 0===g?void 0:g.state,city:null==y?void 0:null===(_=y.guest)||void 0===_?void 0:_.city,zip_code:null==y?void 0:null===(N=y.guest)||void 0===N?void 0:N.zip_code}});if(null==r?void 0:r.success){ea(String(r.data.itinerary_id||"")),O.trackEvent("itinerary",{property:null==y?void 0:y.property_name,checkin:null==y?void 0:y.checkin,checkout:null==y?void 0:y.checkout,currency:null==y?void 0:y.currency,lang:(null==y?void 0:y.lang)||"en",orderReference:null==l?void 0:l.order_reference,paymentReference:null==l?void 0:l.payment_reference,user:{first_name:null==y?void 0:null===(j=y.guest)||void 0===j?void 0:j.first_name,last_name:null==y?void 0:null===(S=y.guest)||void 0===S?void 0:S.last_name,email:null==y?void 0:null===(k=y.guest)||void 0===k?void 0:k.email,phone:"+".concat(null==y?void 0:null===(P=y.guest)||void 0===P?void 0:P.phoneCode).concat(null==y?void 0:null===(C=y.guest)||void 0===C?void 0:C.phone),reservation_id:null==y?void 0:y.itinerary_id}}),Z({eventName:"Complete booking",eventData:{hotel:null==y?void 0:y.property_name,arrival:null==y?void 0:y.checkin,departure:null==y?void 0:y.checkout,currency:null==y?void 0:y.currency,original_currency:null==y?void 0:y.request_currency,itinerary_id:String(r.data.itinerary_id||""),nights:null==y?void 0:y.nights,rooms:null==y?void 0:null===(I=y.occupancy)||void 0===I?void 0:I.length,lang:null==y?void 0:y.lang}}),await h({itinerary_id:String(r.data.itinerary_id||""),type:"payOnline"===e?"guru_collect":"hotel_collect",metadata:{...null==y?void 0:y.metadata,itineraryEngine:{...null==y?void 0:null===(R=y.metadata)||void 0===R?void 0:R.itineraryEngine,createItineraryResponse:r,plainFormCardData:a}},current_step:"itinerary_success",error_message:null}),x("itinerary_success");let i=await f({orderReference:null==l?void 0:l.order_reference,paymentReference:null==l?void 0:l.payment_reference,params:{status:"PAID"},metadata:JSON.stringify({pay_at:e,itinerary_id:String(null==y?void 0:y.itinerary_id),reservation_id:null==y?void 0:y.id,guest_id:null==y?void 0:null===(z=y.guest)||void 0===z?void 0:z.id,guest_currency:null==y?void 0:y.request_currency,request_currency:null==y?void 0:y.currency,token:String(null==y?void 0:y.itinerary_id)})});x("reservation_processing");let t=JSON.parse((null==i?void 0:null===(T=i.payment)||void 0===T?void 0:T.metadata)||"{}"),n=await h({status:"booked",payment_method:t,current_step:"reservation_success",error_message:null});if(n.errors)await h({current_step:"reservation_error_".concat(Number(G)),error_message:null==n?void 0:null===(M=n.errors)||void 0===M?void 0:null===(F=M[0])||void 0===F?void 0:F.message}),x("reservation_error_".concat(Number(G))),console.error("updateReservationOnReservationError",null==n?void 0:n.errors),w(null==n?void 0:null===(D=n.errors)||void 0===D?void 0:null===(A=D[0])||void 0===A?void 0:A.message),ee(!1);else{w(null),x("reservation_success"),await new Promise(e=>setTimeout(e,2e3));let e=new URLSearchParams;e.set("email",(null==y?void 0:null===(B=y.guest)||void 0===B?void 0:B.email)||""),e.set("itineraryId",String(r.data.itinerary_id||"")),await new Promise(e=>setTimeout(e,2e3));let l=(null==y?void 0:y.lang)||"en",a="/".concat(l,"/guest/reservation?").concat(e.toString());v.replace(a)}}else Z({eventName:"Booking error",eventData:{hotel:null==y?void 0:y.property_name,arrival:null==y?void 0:y.checkin,departure:null==y?void 0:y.checkout,currency:null==y?void 0:y.currency,original_currency:null==y?void 0:y.request_currency,itinerary_id:String(null==y?void 0:y.itinerary_id),error:null==r?void 0:r.errors[0].message}}),await h({current_step:"itinerary_error_".concat(Number(G)),error_message:null==r?void 0:r.errors[0].message}),x("itinerary_error_".concat(Number(G))),console.error("expediaItineraryError",null==r?void 0:r.errors[0].message),w(null==r?void 0:r.errors[0].message),ee(!1)}}},[b,H,U,N]);(0,u.useEffect)(()=>{b.includes("payment_success")&&H&&eu(H,N,W)},[b,eu]);let ed="initial"!==b&&"availability"!==b&&"guest_information"!==b&&"payment_retry"!==b&&!b.includes("initializing"),ev=(null==d||null===(s=d.providerOptions)||void 0===s||s.currency,["STRIPE"]);return(0,r.jsxs)("div",{className:"rounded-md overflow-hidden relative min-h-[400px]",children:[ed&&(0,r.jsx)(G,{className:"w-full h-full fixed left-0 top-0 z-20",children:(0,r.jsx)(K,{retriesFromCurrentStepGlobal:en,currentStep:b,createItineraryAction:()=>eu(H,N,W),loading:X,locale:q,params:ei})}),(0,r.jsxs)(m.mQc,{defaultValue:R?"payOnline":C?"payOnline":"payAtProperty",className:"w-full",children:[R&&(0,r.jsxs)(m.drW,{className:"w-full bg-neutral-100 border border-neutral-200 h-auto mb-2 p-2",children:[I&&(0,r.jsxs)(m.SPt,{value:"payAtProperty",className:"w-full flex-col text-neutral-500 shadow-none h-auto gap-2 items-center py-4 data-[state=active]:text-neutral-950 data-[state=active]:shadow-none border border-transparent data-[state=active]:border-neutral-200",onClick:()=>V("payAtProperty"),children:[(0,r.jsx)(F.Z,{size:20}),(0,r.jsx)("span",{children:c("checkout.payment.payAtProperty")})]}),C&&(0,r.jsxs)(m.SPt,{value:"payOnline",className:"w-full flex-col text-neutral-500 shadow-none h-auto gap-2 items-center py-4 data-[state=active]:text-neutral-950 data-[state=active]:shadow-none border border-transparent data-[state=active]:border-neutral-200",onClick:()=>V("payOnline"),children:[(0,r.jsx)(M.Z,{size:20}),(0,r.jsx)("span",{children:c("checkout.payment.payOnline")})]})]}),(0,r.jsx)(m.nUL,{value:"payAtProperty",children:I&&(0===U?(0,r.jsx)(r.Fragment,{children:(0,r.jsx)(ec,{onChange:e=>Y(e)})}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"border border-amber-800/10 bg-yellow-500/10 text-amber-600 text-sm py-1 px-3 text-center rounded-md mb-4",children:(0,r.jsx)("p",{className:"text-center mx-auto max-w-lg",children:c("checkout.payment.methods.plainForm.disclaimerWithDeposit",{deposit:(0,r.jsx)(r.Fragment,{children:(0,_.Z)(Number(Number(Number(U||0)*k).toFixed(2)),(null==y?void 0:y.request_currency)||"USD")})})})}),(0,r.jsx)(et,{allowedMethods:ev,paymentMethod:D,setPaymentMethod:B,loadingPayment:$})]}))}),C&&(0,r.jsx)(m.nUL,{value:"payOnline",children:(0,r.jsx)(et,{allowedMethods:ev,paymentMethod:D,setPaymentMethod:B,loadingPayment:$})})]})]})}var em=a(83100),ep=a(59453);function ey(e){var l,a,r,i,t;return e?null===(t=Object.values(e))||void 0===t?void 0:null===(i=t[0])||void 0===i?void 0:null===(r=i.links)||void 0===r?void 0:null===(a=r.price_check)||void 0===a?void 0:null===(l=a.href)||void 0===l?void 0:l.replace("/v3/",""):null}function eb(e){var l,a,i,t,n,o;let{guestIP:s}=e,d=(0,g.rj)(),c=(0,z.useRouter)(),{currentReservation:v,currentStep:y,setCurrentStep:b,handleUpdateReservation:x,handleUpdatePayment:_,setErrorMessage:h}=(0,p.H)(),f=null==v?void 0:null===(a=v.metadata)||void 0===a?void 0:null===(l=a.bedGroupSelected)||void 0===l?void 0:l.expedia,w=null==v?void 0:null===(t=v.metadata)||void 0===t?void 0:null===(i=t.bedGroupSelected)||void 0===i?void 0:i.property,N=f&&w,j=(null==v?void 0:v.lang)||"en",S=(0,J.r)(),k=(0,J.o)(),[P,C]=(0,u.useState)(w?"payAtProperty":"payOnline"),[I,R]=(0,u.useState)(),[E,q]=(0,u.useState)(!1),[A,Z]=(0,u.useState)((null==v?void 0:v.itinerary_id)||null),O=new URLSearchParams;O.set("email",(null==v?void 0:null===(n=v.guest)||void 0===n?void 0:n.email)||""),O.set("itineraryId",String(A));let D=Number((null==y?void 0:y.match(/\d+/))||0),{priceCheck:B,refetchPriceCheck:U}=function(e,l,a){var r,i,t;let{data:n,refetch:o}=(0,ep.a)(["price-check",e,l,a],async()=>{let r="payAtProperty"===e?ey(a):ey(l);return await (0,em.Z)(r)});return{priceCheck:null==n?void 0:null===(t=n.links)||void 0===t?void 0:null===(i=t.book)||void 0===i?void 0:null===(r=i.href)||void 0===r?void 0:r.replace("/v3/",""),refetchPriceCheck:o}}(P,f,w);(0,u.useEffect)(()=>{U()},[P]);let L=(0,u.useCallback)(e=>{C(e)},[]),H=null===(o=T.find(e=>{var l;return e.name.toUpperCase()===(null==v?void 0:null===(l=v.guest)||void 0===l?void 0:l.country.toUpperCase())}))||void 0===o?void 0:o.iso2,V=(0,u.useCallback)(async(e,l,a)=>{var r,i,t,n,o,u,d,m,p,g,f,w,N,P,C,I,R,z,T,F,M,E,O,D,B,G,U,L;q(!0);let V=Number((null==y?void 0:y.match(/\d+/))||0)+1;if("itinerary_success"!==y){if(y.includes("reservation_error")){let e=await x({status:"booked",current_step:"reservation_success",error_message:null});if(e.errors)await x({current_step:"reservation_error_".concat(Number(V)),error_message:null==e?void 0:null===(i=e.errors)||void 0===i?void 0:null===(r=i[0])||void 0===r?void 0:r.message}),b("reservation_error_".concat(Number(V))),console.error("updateReservationOnReservationError",null==e?void 0:e.errors),h(null==e?void 0:null===(n=e.errors)||void 0===n?void 0:null===(t=n[0])||void 0===t?void 0:t.message),q(!1);else{h(null),b("reservation_success"),await new Promise(e=>setTimeout(e,2e3));let e=new URLSearchParams;e.set("email",(null==v?void 0:null===(o=v.guest)||void 0===o?void 0:o.email)||""),e.set("itineraryId",String(A)),await new Promise(e=>setTimeout(e,2e3));let l="/".concat(j,"/guest/reservation?").concat(e.toString());c.replace(l)}}else{await x({current_step:"itinerary_processing"}),b("itinerary_processing");let r={given_name:null==v?void 0:null===(u=v.guest)||void 0===u?void 0:u.first_name,family_name:null==v?void 0:null===(d=v.guest)||void 0===d?void 0:d.last_name,address:{line_1:null==v?void 0:null===(m=v.guest)||void 0===m?void 0:m.billing_address,line_2:(null==v?void 0:null===(p=v.guest)||void 0===p?void 0:p.billing_address_line_2)||"",city:null==v?void 0:null===(g=v.guest)||void 0===g?void 0:g.city,state_province_code:null==v?void 0:null===(f=v.guest)||void 0===f?void 0:f.state,postal_code:null==v?void 0:null===(w=v.guest)||void 0===w?void 0:w.zip_code,country_code:H}},i={affiliate_reference_id:null==v?void 0:v.order_reference,hold:!1,email:null==v?void 0:null===(N=v.guest)||void 0===N?void 0:N.email,phone:{country_code:null==v?void 0:null===(P=v.guest)||void 0===P?void 0:P.phoneCode,number:null==v?void 0:null===(C=v.guest)||void 0===C?void 0:C.phone},rooms:null==v?void 0:v.occupancy.map(()=>{var e,l;return{given_name:null==v?void 0:null===(e=v.guest)||void 0===e?void 0:e.first_name,family_name:null==v?void 0:null===(l=v.guest)||void 0===l?void 0:l.last_name,smoking:!1,special_request:""}}),payments:"payOnline"===l?[{type:"affiliate_collect",billing_contact:r}]:[{type:"customer_card",number:null==a?void 0:a.number,security_code:null==a?void 0:a.cvc,expiration_month:null==a?void 0:a.month,expiration_year:"20"+(null==a?void 0:a.year),billing_contact:r}]},t=await (0,em.Z)(e,{},i,s);if(null==t?void 0:t.itinerary_id){Z(t.itinerary_id),k.trackEvent("itinerary",{property:null==v?void 0:v.property_name,checkin:null==v?void 0:v.checkin,checkout:null==v?void 0:v.checkout,currency:null==v?void 0:v.currency,lang:(null==v?void 0:v.lang)||"en",orderReference:null==v?void 0:v.order_reference,paymentReference:null==v?void 0:v.payment_reference,user:{first_name:null==v?void 0:null===(I=v.guest)||void 0===I?void 0:I.first_name,last_name:null==v?void 0:null===(R=v.guest)||void 0===R?void 0:R.last_name,email:null==v?void 0:null===(z=v.guest)||void 0===z?void 0:z.email,phone:"+".concat(null==v?void 0:null===(T=v.guest)||void 0===T?void 0:T.phoneCode).concat(null==v?void 0:null===(F=v.guest)||void 0===F?void 0:F.phone),reservation_id:null==v?void 0:v.itinerary_id}}),S({eventName:"Complete booking",eventData:{hotel:null==v?void 0:v.property_name,arrival:null==v?void 0:v.checkin,departure:null==v?void 0:v.checkout,currency:null==v?void 0:v.currency,original_currency:null==v?void 0:v.request_currency,itinerary_id:String(t.resId),nights:null==v?void 0:v.nights,rooms:null==v?void 0:null===(M=v.occupancy)||void 0===M?void 0:M.length,lang:null==v?void 0:v.lang}}),await x({itinerary_id:t.itinerary_id,type:"payOnline"===l?"guru_collect":"hotel_collect",metadata:{...null==v?void 0:v.metadata,itineraryExpedia:t},current_step:"itinerary_success",error_message:null}),b("itinerary_success");let e=await _({orderReference:null==v?void 0:v.order_reference,paymentReference:null==v?void 0:v.payment_reference,params:{status:"PAID"},metadata:JSON.stringify({pay_at:l,itinerary_id:t.itinerary_id,reservation_id:null==v?void 0:v.id,guest_id:null==v?void 0:null===(E=v.guest)||void 0===E?void 0:E.id,guest_currency:null==v?void 0:v.request_currency,request_currency:null==v?void 0:v.currency})});b("reservation_processing");let a=JSON.parse((null==e?void 0:null===(O=e.payment)||void 0===O?void 0:O.metadata)||"{}"),r=await x({status:"booked",payment_method:a,current_step:"reservation_success",error_message:null});if(r.errors)await x({current_step:"reservation_error_".concat(Number(V)),error_message:null==r?void 0:null===(B=r.errors)||void 0===B?void 0:null===(D=B[0])||void 0===D?void 0:D.message}),b("reservation_error_".concat(Number(V))),console.error("updateReservationOnReservationError",null==r?void 0:r.errors),h(null==r?void 0:null===(U=r.errors)||void 0===U?void 0:null===(G=U[0])||void 0===G?void 0:G.message),q(!1);else{h(null),b("reservation_success"),await new Promise(e=>setTimeout(e,2e3));let e=new URLSearchParams;e.set("email",(null==v?void 0:null===(L=v.guest)||void 0===L?void 0:L.email)||""),e.set("itineraryId",t.itinerary_id),await new Promise(e=>setTimeout(e,2e3));let l=(null==v?void 0:v.lang)||"en",a="/".concat(l,"/guest/reservation?").concat(e.toString());c.replace(a)}}else(null==t?void 0:t.message)&&(S({eventName:"Booking error",eventData:{hotel:null==v?void 0:v.property_name,arrival:null==v?void 0:v.checkin,departure:null==v?void 0:v.checkout,currency:null==v?void 0:v.currency,original_currency:null==v?void 0:v.request_currency,itinerary_id:String(t.resId),error:null==t?void 0:t.message}}),await x({current_step:"itinerary_error_".concat(Number(V)),error_message:null==t?void 0:t.message}),b("itinerary_error_".concat(Number(V))),console.error("expediaItineraryError",null==t?void 0:t.message),h(null==t?void 0:t.message),q(!1))}}},[y,P,B]);(0,u.useEffect)(()=>{("stripe_payment_success"===y||"plain_form_payment_success"===y)&&B&&P&&V(B,P,I)},[y,V]);let W="initial"!==y&&"availability"!==y&&"guest_information"!==y&&"payment_retry"!==y;return(0,r.jsxs)("div",{className:"rounded-md overflow-hidden relative min-h-[400px]",children:[W&&(0,r.jsx)(G,{className:"w-full h-full fixed left-0 top-0 z-20",children:(0,r.jsx)(K,{retriesFromCurrentStepGlobal:D,currentStep:y,createItineraryAction:()=>V(B,P,I),loading:E,locale:j,params:O})}),(0,r.jsxs)(m.mQc,{defaultValue:w?"payAtProperty":"payOnline",className:"w-full",children:[N&&(0,r.jsxs)(m.drW,{className:"w-full bg-neutral-100 border border-neutral-200 h-auto mb-2 p-2",children:[w&&(0,r.jsxs)(m.SPt,{value:"payAtProperty",className:"w-full flex-col text-neutral-500 shadow-none h-auto gap-2 items-center py-4 data-[state=active]:text-neutral-950 data-[state=active]:shadow-none border border-transparent data-[state=active]:border-neutral-200",onClick:()=>L("payAtProperty"),children:[(0,r.jsx)(F.Z,{size:20}),(0,r.jsx)("span",{children:d("checkout.payment.payAtProperty")})]}),f&&(0,r.jsxs)(m.SPt,{value:"payOnline",className:"w-full flex-col text-neutral-500 shadow-none h-auto gap-2 items-center py-4 data-[state=active]:text-neutral-950 data-[state=active]:shadow-none border border-transparent data-[state=active]:border-neutral-200",onClick:()=>L("payOnline"),children:[(0,r.jsx)(M.Z,{size:20}),(0,r.jsx)("span",{children:d("checkout.payment.payOnline")})]})]}),(0,r.jsx)(m.nUL,{value:"payAtProperty",children:w&&(0,r.jsx)(ec,{onChange:e=>R(e)})}),f&&(0,r.jsx)(m.nUL,{value:"payOnline",children:(0,r.jsx)(ei,{})})]})]})}var ex=a(35797);let eg=[{label:"United States",value:71,a2:"US"},{label:"France",value:77,a2:"FR"},{label:"Israel",value:119,a2:"IL"},{label:"Mexico",value:156,a2:"MX"},{label:"Afghanistan",value:1,a2:"AF"},{label:"Albania",value:2,a2:"AL"},{label:"Algeria",value:12,a2:"DZ"},{label:"American Samoa",value:4,a2:"AS"},{label:"Andorra",value:5,a2:"AD"},{label:"Angola",value:6,a2:"AO"},{label:"Anguilla",value:7,a2:"AI"},{label:"Antarctica",value:10,a2:"AQ"},{label:"Antigua and Barbuda",value:8,a2:"AG"},{label:"Argentina",value:13,a2:"AR"},{label:"Armenia",value:14,a2:"AM"},{label:"Aruba",value:15,a2:"AW"},{label:"Australia",value:17,a2:"AU"},{label:"Austria",value:18,a2:"AT"},{label:"Azerbaijan",value:19,a2:"AZ"},{label:"Bahamas",value:20,a2:"BS"},{label:"Bahrain",value:21,a2:"BH"},{label:"Bangladesh",value:22,a2:"BD"},{label:"Barbados",value:23,a2:"BB"},{label:"Belarus",value:27,a2:"BY"},{label:"Belgium",value:39,a2:"BE"},{label:"Belize",value:24,a2:"BZ"},{label:"Benin",value:25,a2:"BJ"},{label:"Bermuda",value:26,a2:"BM"},{label:"Bhutan",value:38,a2:"BT"},{label:"Bolivia",value:28,a2:"BO"},{label:"Bosnia and Herzegovina",value:29,a2:"BA"},{label:"Botswana",value:30,a2:"BW"},{label:"Bouvet Island",value:31,a2:"BV"},{label:"Brazil",value:32,a2:"BR"},{label:"British Indian Ocean Territory",value:33,a2:"IO"},{label:"Brunei Darussalam",value:34,a2:"BN"},{label:"Bulgaria",value:35,a2:"BG"},{label:"Burkina Faso",value:36,a2:"BF"},{label:"Burundi",value:37,a2:"BI"},{label:"Cabo Verde",value:40,a2:"CV"},{label:"Cambodia",value:41,a2:"KH"},{label:"Cameroon",value:42,a2:"CM"},{label:"Canada",value:44,a2:"CA"},{label:"Cayman Islands",value:109,a2:"KY"},{label:"Central African Republic",value:184,a2:"CF"},{label:"Chad",value:45,a2:"TD"},{label:"Chile",value:46,a2:"CL"},{label:"China",value:47,a2:"CN"},{label:"Christmas Island",value:107,a2:"CX"},{label:"Cocos (Keeling) Islands",value:106,a2:"CC"},{label:"Colombia",value:49,a2:"CO"},{label:"Comoros",value:50,a2:"KM"},{label:"Congo",value:51,a2:"CG"},{label:"Cook Islands",value:110,a2:"CK"},{label:"Costa Rica",value:54,a2:"CR"},{label:"Croatia",value:56,a2:"HR"},{label:"Cuba",value:57,a2:"CU"},{label:"Cyprus",value:48,a2:"CY"},{label:"Czech Republic",value:185,a2:"CZ"},{label:"Democratic Republic of the Congo (Kinshasa)",value:186,a2:"CD"},{label:"Denmark",value:58,a2:"DK"},{label:"Djibouti",value:59,a2:"DJ"},{label:"Dominica",value:60,a2:"DM"},{label:"Dominican Republic",value:187,a2:"DO"},{label:"East Timor",value:61,a2:"TL"},{label:"Ecuador",value:62,a2:"EC"},{label:"Egypt",value:63,a2:"EG"},{label:"El Salvador",value:64,a2:"SV"},{label:"Equatorial Guinea",value:93,a2:"GQ"},{label:"Eritrea",value:67,a2:"ER"},{label:"Estonia",value:72,a2:"EE"},{label:"Ethiopia",value:73,a2:"ET"},{label:"Falkland Islands",value:112,a2:"FK"},{label:"Faroe Islands",value:111,a2:"FO"},{label:"Fiji",value:74,a2:"FJ"},{label:"Finland",value:76,a2:"FI"},{label:"French Guiana",value:78,a2:"GF"},{label:"French Polynesia",value:79,a2:"PF"},{label:"French Southern Territories",value:80,a2:"TF"},{label:"Gabon",value:81,a2:"GA"},{label:"Gambia",value:82,a2:"GM"},{label:"Georgia",value:83,a2:"GE"},{label:"Germany",value:3,a2:"DE"},{label:"Ghana",value:84,a2:"GH"},{label:"Gibraltar",value:85,a2:"GI"},{label:"Greece",value:87,a2:"GR"},{label:"Greenland",value:88,a2:"GL"},{label:"Grenada",value:86,a2:"GD"},{label:"Guadeloupe",value:89,a2:"GP"},{label:"Guam",value:90,a2:"GU"},{label:"Guatemala",value:91,a2:"GT"},{label:"Guinea",value:92,a2:"GN"},{label:"Guinea-Bissau",value:94,a2:"GW"},{label:"Guyana",value:95,a2:"GY"},{label:"Haiti",value:96,a2:"HT"},{label:"Heard Island and McDonald Isla",value:97,a2:"HM"},{label:"Honduras",value:99,a2:"HN"},{label:"Hong Kong",value:100,a2:"HK"},{label:"Hungary",value:101,a2:"HU"},{label:"Iceland",value:108,a2:"IS"},{label:"India",value:102,a2:"IN"},{label:"Indonesia",value:103,a2:"ID"},{label:"Iran (Islamic Republic of)",value:188,a2:"IR"},{label:"Iraq",value:104,a2:"IQ"},{label:"Ireland",value:105,a2:"IE"},{label:"Italy",value:120,a2:"IT"},{label:"Ivory Coast (Cote d'Ivoire)",value:55,a2:"CI"},{label:"Jamaica",value:121,a2:"JM"},{label:"Japan",value:122,a2:"JP"},{label:"Jordan",value:123,a2:"JO"},{label:"Kazakhstan",value:124,a2:"KZ"},{label:"Kenya",value:125,a2:"KE"},{label:"Kiribati",value:126,a2:"KI"},{label:"Korea, Democratic People's Rep. (North Korea)",value:52,a2:"KP"},{label:"Korea, Republic of (South Korea)",value:53,a2:"KR"},{label:"Kuwait",value:127,a2:"KW"},{label:"Kyrgyzstan",value:128,a2:"KG"},{label:"Lao, People's Democratic Republic",value:129,a2:"LA"},{label:"Latvia",value:130,a2:"LV"},{label:"Lebanon",value:137,a2:"LB"},{label:"Lesoto",value:131,a2:"LS"},{label:"Liberia",value:132,a2:"LR"},{label:"Libya",value:133,a2:"LY"},{label:"Liechtenstein",value:134,a2:"LI"},{label:"Lithuania",value:135,a2:"LT"},{label:"Luxembourg",value:136,a2:"LU"},{label:"Macao",value:138,a2:"MO"},{label:"Macedonia, Rep. of",value:139,a2:"MK"},{label:"Madagascar",value:140,a2:"MG"},{label:"Malaui",value:142,a2:"MW"},{label:"Malaysia",value:141,a2:"MY"},{label:"Maldives",value:143,a2:"MV"},{label:"Mali",value:145,a2:"ML"},{label:"Malta",value:144,a2:"MT"},{label:"Marshall Islands",value:113,a2:"MH"},{label:"Martinique",value:147,a2:"MQ"},{label:"Mauritania",value:148,a2:"MR"},{label:"Mauritius Islands",value:114,a2:"MU"},{label:"Mayotte",value:149,a2:"YT"},{label:"Micronesia, Federal States of",value:150,a2:"FM"},{label:"Moldova, Republic of",value:151,a2:"MD"},{label:"Monaco",value:157,a2:"MC"},{label:"Mongolia",value:152,a2:"MN"},{label:"Montserrat",value:153,a2:"MS"},{label:"Morocco",value:146,a2:"MA"},{label:"Mozambique",value:154,a2:"MZ"},{label:"Myanmar, Burma",value:155,a2:"MM"},{label:"Namibia",value:158,a2:"NA"},{label:"Nauru",value:159,a2:"NR"},{label:"Nepal",value:160,a2:"NP"},{label:"Netherlands",value:98,a2:"NL"},{label:"Netherlands Antilles",value:9,a2:"AN"},{label:"New Caledonia",value:167,a2:"NC"},{label:"New Zealand",value:168,a2:"NZ"},{label:"Nicaragua",value:161,a2:"NI"},{label:"Niger",value:169,a2:"NE"},{label:"Nigeria",value:162,a2:"NG"},{label:"Niue",value:163,a2:"NU"},{label:"Norfolk Island",value:164,a2:"NF"},{label:"Northern Mariana Islands",value:165,a2:"MP"},{label:"Norway",value:166,a2:"NO"},{label:"Oman",value:170,a2:"OM"},{label:"Pakistan",value:171,a2:"PK"},{label:"Palau",value:172,a2:"PW"},{label:"Palestinian territories",value:173,a2:"PS"},{label:"Panama",value:174,a2:"PA"},{label:"Papua New Guinea",value:175,a2:"PG"},{label:"Paraguay",value:176,a2:"PY"},{label:"Peru",value:177,a2:"PE"},{label:"Philippines",value:75,a2:"PH"},{label:"Pitcairn Island",value:178,a2:"PN"},{label:"Poland",value:179,a2:"PL"},{label:"Portugal",value:180,a2:"PT"},{label:"Puerto Rico",value:181,a2:"PR"},{label:"Qatar",value:182,a2:"QA"},{label:"Romania",value:190,a2:"RO"},{label:"Russian",value:191,a2:"RU"},{label:"Rwanda",value:189,a2:"RW"},{label:"Saint Elena",value:197,a2:"SH"},{label:"Saint Kitts and Nevis",value:192,a2:"KN"},{label:"Saint Lucia",value:198,a2:"LC"},{label:"Saint Pierre y Miquelon",value:193,a2:"PM"},{label:"Saint Vincent and the Grenadines",value:196,a2:"VC"},{label:"Samoa",value:194,a2:"WS"},{label:"San Marino",value:195,a2:"SM"},{label:"Sandwhich islands",value:116,a2:"GS"},{label:"Sao Tome and Pr\xedncipe",value:199,a2:"ST"},{label:"Saudi Arabia",value:11,a2:"SA"},{label:"Senegal",value:200,a2:"SN"},{label:"Serbia",value:201,a2:"RS"},{label:"Seychelles",value:202,a2:"SC"},{label:"Sierra Leone",value:203,a2:"SL"},{label:"Singapore",value:204,a2:"SG"},{label:"Slovakia (Slovak Republic)",value:68,a2:"SK"},{label:"Slovenia",value:69,a2:"SI"},{label:"Solomon Islands",value:115,a2:"SB"},{label:"Somalia",value:206,a2:"SO"},{label:"South Africa",value:209,a2:"ZA"},{label:"Spain",value:70,a2:"ES"},{label:"Sri Lanka",value:207,a2:"LK"},{label:"Suazilandia",value:208,a2:"SZ"},{label:"Sudan",value:210,a2:"SD"},{label:"Suriname",value:213,a2:"SR"},{label:"Svalbard and Jan Mayen",value:214,a2:"SJ"},{label:"Sweden",value:211,a2:"SE"},{label:"Switzerland",value:212,a2:"CH"},{label:"Syria",value:205,a2:"SY"},{label:"Taiwan",value:216,a2:"TW"},{label:"Tajikistan",value:217,a2:"TJ"},{label:"Tanzania",value:218,a2:"TZ"},{label:"Thailand",value:215,a2:"TH"},{label:"Togo",value:219,a2:"TG"},{label:"Tonga",value:220,a2:"TO"},{label:"Toquelau",value:221,a2:"TK"},{label:"Trinidad and Tobago",value:222,a2:"TT"},{label:"Tunisia",value:226,a2:"TN"},{label:"Turkey",value:224,a2:"TR"},{label:"Turkmenistan",value:223,a2:"TM"},{label:"Turks and Caicos Islands",value:117,a2:"TC"},{label:"Tuvalu",value:225,a2:"TV"},{label:"Uganda",value:228,a2:"UG"},{label:"Ukraine",value:227,a2:"UA"},{label:"United Arab Emirates",value:66,a2:"AE"},{label:"United Kingdom",value:183,a2:"GB"},{label:"Unknown",value:242,a2:"UN"},{label:"Uruguay",value:230,a2:"UY"},{label:"Uzbekistan",value:231,a2:"UZ"},{label:"Vanuatu",value:232,a2:"VU"},{label:"Vatican City State (Holy See)",value:65,a2:"VA"},{label:"Venezuela",value:233,a2:"VE"},{label:"Vietnam",value:234,a2:"VN"},{label:"Virgin Islands British",value:235,a2:"VG"},{label:"Virgin Islands U.S.",value:236,a2:"VI"},{label:"Wallis and Futuna Islands",value:118,a2:"WF"},{label:"Western Sahara",value:237,a2:"EH"},{label:"Yemen",value:238,a2:"YE"},{label:"Zambia",value:240,a2:"ZM"},{label:"Zimbabue",value:241,a2:"ZW"}];function e_(e){var l,a,i,t,n,o;let{website:s}=e,d=(0,z.useRouter)(),{paymentIntent:c,setPaymentIntent:v,currentReservation:m,currentStep:y,setCurrentStep:b,handleCreatePayment:x,handleUpdateReservation:g,handleUpdatePayment:_,setErrorMessage:h,currentCurrencyConversionRate:f}=(0,p.H)(),{extras:w,totalsExtras:N,setTotalsExtras:S}=(0,j.z)(),k=(null==m?void 0:m.lang)||"en",P=(null==m?void 0:m.currency)||"USD",C=(null==m?void 0:m.request_currency)||"USD",I=(null==m?void 0:m.checkin)||"",R=(null==m?void 0:m.checkout)||"",F=0===Number((null==s?void 0:null===(l=s.providerOptions)||void 0===l?void 0:l.accountFee)||0)?5:(null==s?void 0:null===(a=s.providerOptions)||void 0===a?void 0:a.accountFee)||5,M=(0,J.r)(),E=(0,J.o)(),q=F/100,{priceCheck:Z,refetchPriceCheck:O,rooms:D,isRefetchingPriceCheck:B}=function(e,l,a){var r;let i=null==e?void 0:e.providerOptions,t=(null==l?void 0:l.checkin)||"",n=(null==l?void 0:l.checkout)||"",o=(null==l?void 0:l.lang)||"en",s=(null==l?void 0:l.currency)||"USD",u=null==i?void 0:i.childrenMinAge,d=null==l?void 0:null===(r=l.occupancy)||void 0===r?void 0:r.map(e=>{var a,r,i,t,n,o;return{room_type_id:null==e?void 0:null===(a=e.room)||void 0===a?void 0:a.id,rate_type_id:null==l?void 0:null===(i=l.metadata)||void 0===i?void 0:null===(r=i.availability)||void 0===r?void 0:r.id,promotion_id:null==l?void 0:null===(n=l.metadata)||void 0===n?void 0:null===(t=n.availability)||void 0===t?void 0:t.promotion_id,quantity:1,pax:[{adults:(null==e?void 0:e.adults)||2,children:(null==e?void 0:e.children)||0,infants:Number((null===(o=e.childrenAges)||void 0===o?void 0:o.filter(e=>Number(e)<Number(u)).length)||0)}]}}),{data:c,refetch:v,isRefetching:m}=(0,ep.a)({queryKey:["totals"],queryFn:async()=>(0,ex.Z)("summary/get-totals",{lang:o,hotel_id:"gzav-".concat(e.property.zavia_id),currency:s,arrival:t,departure:n},{currency:s,arrival:t,departure:n,rooms:d,extras:(null==a?void 0:a.map(e=>{let{image:l,...a}=e;return a}))||[]})});return{priceCheck:null==c?void 0:c.data,refetchPriceCheck:v,isRefetchingPriceCheck:m,rooms:d}}(s,m,w),[U,L]=(0,u.useState)("STRIPE"),H=0!==Number(null==m?void 0:m.pay_later)?"payAtProperty":"payOnline",[V,W]=(0,u.useState)(B||!1),[Y,$]=(0,u.useState)(!1),[Q,X]=(0,u.useState)((null==m?void 0:m.itinerary_id)||null),ee=A().generate(),el=Number(null==Z?void 0:Z.subtotalGeneral)*q,ea=.16*el,er=Number((el+ea).toFixed(2)),ei=new URLSearchParams;ei.set("email",(null==m?void 0:null===(i=m.guest)||void 0===i?void 0:i.email)||""),ei.set("itineraryId",String(Q));let en=Number((null==y?void 0:y.match(/\d+/))||0);(0,u.useEffect)(()=>{if(!B&&Z&&m){let e=function(e){var l,a;let{totals:r,priceCheck:i,requestCurrency:t,currency:n,accountFee:o,currentCurrencyConversionRate:s}=e,u=null==r?void 0:r.converted,d=null==r?void 0:r.requested;return{requested:{extras_subtotal:null==i?void 0:i.subtotalExtras,extras_taxes:null==i?void 0:i.taxesExtras,extras_total:null==i?void 0:i.totalExtras,currency:t,subtotal_with_extras:Number(Number(Number(Number(null==d?void 0:d.subtotal)+Number(null==i?void 0:i.subtotalExtras)).toFixed(2)).toFixed(2)),taxes_with_extras:Number(Number(Number(Number(null==d?void 0:d.taxes_inclusive)+Number(null==i?void 0:i.taxesExtras)).toFixed(2)).toFixed(2)),total_with_extras:Number(Number(Number(Number(null==i?void 0:i.totalExtras)+Number(null==d?void 0:d.total)).toFixed(2)).toFixed(2)),policyPayment:0!==Number(null==d?void 0:null===(l=d.policyPayment)||void 0===l?void 0:l.pay_later)?{pay_now_with_extras:Number((Number(Number(null==i?void 0:i.totalGeneral))*(o/100)).toFixed(2)),pay_later_with_extras:Number(Number(null==i?void 0:i.totalGeneral)-Number((Number(Number(null==i?void 0:i.totalGeneral))*(o/100)).toFixed(2)))}:{pay_later_with_extras:0,pay_now_with_extras:Number(null==i?void 0:i.totalGeneral)}},converted:t!==n?{extras_subtotal:Number(Number((Number(null==i?void 0:i.subtotalExtras)*s).toFixed(2)).toFixed(2)),extras_taxes:Number(Number((Number(null==i?void 0:i.taxesExtras)*s).toFixed(2)).toFixed(2)),extras_total:Number(Number((Number(null==i?void 0:i.totalExtras)*s).toFixed(2)).toFixed(2)),currency:n,subtotal_with_extras:Number(Number(Number(null==u?void 0:u.subtotal)+Number((Number(null==i?void 0:i.subtotalExtras)*s).toFixed(2))).toFixed(2)),taxes_with_extras:Number(Number(Number(null==u?void 0:u.taxes_inclusive)+Number((Number(null==i?void 0:i.taxesExtras)*s).toFixed(2))).toFixed(2)),total_with_extras:Number(Number(Number((Number(null==i?void 0:i.totalExtras)*s).toFixed(2))+Number(null==u?void 0:u.total)).toFixed(2)),policyPayment:0!==Number(null==d?void 0:null===(a=d.policyPayment)||void 0===a?void 0:a.pay_later)?{pay_now_with_extras:Number((Number(Number(Number(null==i?void 0:i.totalGeneral))*(o/100))*s).toFixed(2)),pay_later_with_extras:Number(Number(Number(Number(null==i?void 0:i.totalGeneral)-Number((Number(Number(null==i?void 0:i.totalGeneral))*(o/100)).toFixed(2)))*s).toFixed(2))}:{pay_later_with_extras:0,pay_now_with_extras:Number(Number(null==i?void 0:i.totalGeneral))*s}}:null}}({totals:null==m?void 0:m.totals,priceCheck:Z,requestCurrency:P,currency:C,accountFee:F,currentCurrencyConversionRate:f});(null==w?void 0:w.length)===0?S(void 0):S(e)}},[B,Z,m,w]),(0,u.useEffect)(()=>{(async()=>{var e,l,a,r,i,t,n,o,u,d,c,p,y,b,_,h,f,j,S,k,P;if(W(!0),(null==w?void 0:w.length)===0){let e=null==m?void 0:null===(a=m.totals)||void 0===a?void 0:a.requested,l=await x({orderReference:ee,currency:null==e?void 0:e.currency,amount:Math.round(100*((null==e?void 0:null===(r=e.policyPayment)||void 0===r?void 0:r.pay_now)||0)),monthlyInstallments:!0,paymentMethod:"STRIPE"===U?"CARD":U,paymentProvider:U,gurufee:Math.round(100*(er||0)),futureUsage:!0,client:{client_reference:"Client-".concat(ee),name:"".concat(null==m?void 0:null===(i=m.guest)||void 0===i?void 0:i.first_name," ").concat(null==m?void 0:null===(t=m.guest)||void 0===t?void 0:t.last_name),email:null==m?void 0:null===(n=m.guest)||void 0===n?void 0:n.email,phone:"+".concat(null==m?void 0:null===(o=m.guest)||void 0===o?void 0:o.phoneCode).concat(null==m?void 0:null===(u=m.guest)||void 0===u?void 0:u.phone)},business:{business_reference:String("gzav-".concat(null==s?void 0:null===(d=s.property)||void 0===d?void 0:d.zavia_id)),name:s.name},origin:"HOTELS"});await g({order_reference:null==l?void 0:null===(c=l.payment)||void 0===c?void 0:c.order_reference,payment_reference:null==l?void 0:null===(p=l.payment)||void 0===p?void 0:p.payment_reference,fee_percentage:String(F),fee:String(er),payment_provider:U}),v(null==l?void 0:l.payment)}else if(null==N?void 0:null===(l=N.requested)||void 0===l?void 0:null===(e=l.policyPayment)||void 0===e?void 0:e.pay_now_with_extras){let e=null==N?void 0:N.requested,l=await x({orderReference:ee,currency:null==e?void 0:e.currency,amount:Math.round(100*((null==e?void 0:null===(y=e.policyPayment)||void 0===y?void 0:y.pay_now_with_extras)||0)),monthlyInstallments:!0,paymentMethod:"STRIPE"===U?"CARD":U,paymentProvider:U,gurufee:Math.round(100*(er||0)),futureUsage:!0,client:{client_reference:"Client-".concat(ee),name:"".concat(null==m?void 0:null===(b=m.guest)||void 0===b?void 0:b.first_name," ").concat(null==m?void 0:null===(_=m.guest)||void 0===_?void 0:_.last_name),email:null==m?void 0:null===(h=m.guest)||void 0===h?void 0:h.email,phone:"+".concat(null==m?void 0:null===(f=m.guest)||void 0===f?void 0:f.phoneCode).concat(null==m?void 0:null===(j=m.guest)||void 0===j?void 0:j.phone)},business:{business_reference:String("gzav-".concat(null==s?void 0:null===(S=s.property)||void 0===S?void 0:S.zavia_id)),name:s.name},origin:"HOTELS"});await g({order_reference:null==l?void 0:null===(k=l.payment)||void 0===k?void 0:k.order_reference,payment_reference:null==l?void 0:null===(P=l.payment)||void 0===P?void 0:P.payment_reference,fee_percentage:String(F),fee:String(er),payment_provider:U}),v(null==l?void 0:l.payment)}await new Promise(e=>setTimeout(e,2e3)),W(!1)})()},[w,N,el,U]),(0,u.useEffect)(()=>{O()},[w]);let eo=null===(t=T.find(e=>{var l;return e.name.toUpperCase()===(null==m?void 0:null===(l=m.guest)||void 0===l?void 0:l.country.toUpperCase())}))||void 0===t?void 0:t.iso2,es=(0,u.useCallback)(async(e,l)=>{var a,r,i,t,n,o,u,v,p,x,f,j,S,C,z,T,F,q,A,Z,O,B,G,U,L,H,V,K,J,W,Y,ee,el,ea,er;$(!0);let ei=Number((null==y?void 0:y.match(/\d+/))||0)+1;if("itinerary_success"!==y){if(y.includes("reservation_error")){let e=await g({status:"booked",current_step:"reservation_success",error_message:null});if(e.errors)await g({current_step:"reservation_error_".concat(Number(ei)),error_message:null==e?void 0:null===(r=e.errors)||void 0===r?void 0:null===(a=r[0])||void 0===a?void 0:a.message}),b("reservation_error_".concat(Number(ei))),console.error("updateReservationOnReservationError",null==e?void 0:e.errors),h(null==e?void 0:null===(t=e.errors)||void 0===t?void 0:null===(i=t[0])||void 0===i?void 0:i.message),$(!1);else{h(null),b("reservation_success"),await new Promise(e=>setTimeout(e,2e3));let e=new URLSearchParams;e.set("email",(null==m?void 0:null===(n=m.guest)||void 0===n?void 0:n.email)||""),e.set("itineraryId",String(Q)),await new Promise(e=>setTimeout(e,2e3));let l="/".concat(k,"/guest/reservation?").concat(e.toString());d.replace(l)}}else{await g({current_step:"itinerary_processing",type:"payOnline"===l?"guru_collect":"hotel_collect"}),b("itinerary_processing");let a=null===(u=eg.filter(e=>e.a2===eo))||void 0===u?void 0:null===(o=u[0])||void 0===o?void 0:o.value,r={arrival:I,departure:R,payment_method_key:"nD26e0LbLUwGtHRLCKCgEVT7",rooms:D,client:{first_name:null==m?void 0:null===(v=m.guest)||void 0===v?void 0:v.first_name,last_name:null==m?void 0:null===(p=m.guest)||void 0===p?void 0:p.last_name,mobile_phone:"".concat(null==m?void 0:null===(x=m.guest)||void 0===x?void 0:x.phoneCode).concat(null==m?void 0:null===(f=m.guest)||void 0===f?void 0:f.phone),email:null==m?void 0:null===(j=m.guest)||void 0===j?void 0:j.email,user_address_line1:null==m?void 0:null===(S=m.guest)||void 0===S?void 0:S.billing_address,user_address_line2:(null==m?void 0:null===(C=m.guest)||void 0===C?void 0:C.billing_address_line_2)||"",user_city:null==m?void 0:null===(z=m.guest)||void 0===z?void 0:z.city,user_state_province_code:null==m?void 0:null===(T=m.guest)||void 0===T?void 0:T.state,user_zip_code:null==m?void 0:null===(F=m.guest)||void 0===F?void 0:F.zip_code,country:a},payment:{amount:(null==N?void 0:null===(A=N.requested)||void 0===A?void 0:null===(q=A.policyPayment)||void 0===q?void 0:q.pay_now_with_extras)||(null==N?void 0:null===(O=N.requested)||void 0===O?void 0:null===(Z=O.policyPayment)||void 0===Z?void 0:Z.pay_now)||(null==e?void 0:e.amountToPay),refId:null==c?void 0:c.order_reference},sessionId:null==c?void 0:c.order_reference,extras:w.map(e=>{let{image:l,...a}=e;return a})},i=await (0,ex.Z)("reservations",{lang:k,hotel_id:"gzav-".concat(null==s?void 0:null===(B=s.property)||void 0===B?void 0:B.zavia_id),currency:P,arrival:I,departure:R},r);if(null==i?void 0:i.success){X(String(i.resId)),E.trackEvent("itinerary",{property:s.name,checkin:I,checkout:R,currency:null==m?void 0:m.currency,lang:(null==m?void 0:m.lang)||"en",orderReference:null==c?void 0:c.order_reference,paymentReference:null==c?void 0:c.payment_reference,user:{first_name:null==m?void 0:null===(G=m.guest)||void 0===G?void 0:G.first_name,last_name:null==m?void 0:null===(U=m.guest)||void 0===U?void 0:U.last_name,email:null==m?void 0:null===(L=m.guest)||void 0===L?void 0:L.email,phone:"+".concat(null==m?void 0:null===(H=m.guest)||void 0===H?void 0:H.phoneCode).concat(null==m?void 0:null===(V=m.guest)||void 0===V?void 0:V.phone),reservation_id:null==m?void 0:m.itinerary_id}}),M({eventName:"Complete booking",eventData:{hotel:s.name,arrival:I,departure:R,currency:null==m?void 0:m.currency,original_currency:null==m?void 0:m.request_currency,itinerary_id:String(i.resId),nights:null==m?void 0:m.nights,rooms:null==m?void 0:null===(K=m.occupancy)||void 0===K?void 0:K.length,lang:null==m?void 0:m.lang}}),await g({itinerary_id:String(i.resId),metadata:{...null==m?void 0:m.metadata,itineraryZavia:i,extras:w},current_step:"itinerary_success",error_message:null}),b("itinerary_success");let e=await _({orderReference:null==c?void 0:c.order_reference,paymentReference:null==c?void 0:c.payment_reference,params:{status:"PAID"},metadata:JSON.stringify({pay_at:l,itinerary_id:i.resId,reservation_id:null==m?void 0:m.id,guest_id:null==m?void 0:null===(J=m.guest)||void 0===J?void 0:J.id,guest_currency:null==m?void 0:m.request_currency,request_currency:null==m?void 0:m.currency,token:null==i?void 0:i.token})});b("reservation_processing");let a=JSON.parse((null==e?void 0:null===(W=e.payment)||void 0===W?void 0:W.metadata)||"{}"),r=await g({status:"booked",payment_method:a,payments:[{date:String(new Date().toISOString()),payment:{amount:null==a?void 0:a.amount,clientSecret:null==a?void 0:a.clientSecret,paymentIntent:null==a?void 0:a.id}}],current_step:"reservation_success",error_message:null});if(r.errors)await g({current_step:"reservation_error_".concat(Number(ei)),error_message:null==r?void 0:null===(ee=r.errors)||void 0===ee?void 0:null===(Y=ee[0])||void 0===Y?void 0:Y.message}),b("reservation_error_".concat(Number(ei))),console.error("updateReservationOnReservationError",null==r?void 0:r.errors),h(null==r?void 0:null===(ea=r.errors)||void 0===ea?void 0:null===(el=ea[0])||void 0===el?void 0:el.message),$(!1);else{h(null),b("reservation_success"),await new Promise(e=>setTimeout(e,2e3));let e=new URLSearchParams;e.set("email",(null==m?void 0:null===(er=m.guest)||void 0===er?void 0:er.email)||""),e.set("itineraryId",i.resId),await new Promise(e=>setTimeout(e,2e3));let l=(null==m?void 0:m.lang)||"en",a="/".concat(l,"/guest/reservation?").concat(e.toString());d.replace(a)}}else(null==i?void 0:i.errorMessage)&&(M({eventName:"Booking error",eventData:{hotel:s.name,arrival:I,departure:R,currency:null==m?void 0:m.currency,original_currency:null==m?void 0:m.request_currency,itinerary_id:String(i.resId),error:null==i?void 0:i.errorMessage}}),await g({current_step:"itinerary_error_".concat(Number(ei)),error_message:null==i?void 0:i.errorMessage}),b("itinerary_error_".concat(Number(ei))),console.error("zaviaItineraryError",null==i?void 0:i.errorMessage),h(null==i?void 0:i.errorMessage),$(!1))}}},[y,H,Z,N,c]);(0,u.useEffect)(()=>{y.includes("payment_success")&&Z&&H&&es(Z,H)},[Z,y,es]);let eu="initial"!==y&&"availability"!==y&&"guest_information"!==y&&"payment_retry"!==y&&!y.includes("initializing"),ed=(null==s||null===(o=s.providerOptions)||void 0===o||null===(n=o.currencies)||void 0===n||n.includes("MXN"),["STRIPE"]);return(0,r.jsxs)("div",{className:"rounded-md overflow-hidden relative min-h-[400px]",children:[eu&&(0,r.jsx)(G,{className:"w-full h-full fixed left-0 top-0 z-20",children:(0,r.jsx)(K,{retriesFromCurrentStepGlobal:en,currentStep:y,createItineraryAction:()=>es(Z,H),loading:Y,locale:k,params:ei})}),(0,r.jsx)(et,{allowedMethods:ed,paymentMethod:U,setPaymentMethod:L,loadingPayment:V})]})}function eh(e){var l;let{website:a}=e,i=null==a?void 0:a.property.type,t=null==a?void 0:null===(l=a.tracking_codes)||void 0===l?void 0:l.find(e=>"sojernTracker"===e.name),n=(0,u.useMemo)(()=>{var e;return{id:null==t?void 0:null===(e=t.codes)||void 0===e?void 0:e.shopping,name:"Shopping",parameters:[],placement:"body"}},[]);if((0,R.j)({config:n,params:{}}),"engine"===i)return(0,r.jsx)(ev,{website:a});if("expedia"===i){let e=null==a?void 0:a.providerConstants,l=(null==e?void 0:e.cookies.guestIP)||"";return(0,r.jsx)(eb,{guestIP:l})}return"zavia"===i?(0,r.jsx)(e_,{website:a}):null}function ef(e){let{component:l,website:a}=e,u=(0,i.Z)(l),d=null==a?void 0:a.currentReservation,c=(null==d?void 0:d.status)==="timed_out";return(0,r.jsx)("section",{className:"w-full py-4 bg-background text-foreground",style:u,children:(0,r.jsxs)(t.Z,{className:"flex flex-col gap-4 max-w-4xl md:px-0",children:[c?null:(0,r.jsx)(n.Z,{currentReservation:d}),(0,r.jsx)(s.Z,{opened:!0}),c?(0,r.jsx)(o.Z,{}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(I,{website:a}),(0,r.jsx)(eh,{website:a})]})]})})}},12839:function(e,l,a){a.d(l,{Z:function(){return d}});var r=a(27573),i=a(7653),t=a(68055),n=a(1804),o=a(59668),s=a(96504),u=a(71811);function d(e){let{currentReservation:l,durationInMinutes:a=30,stopCountdown:d=!1}=e,c=(0,t.eR)("global.reservationCountdown"),v=(0,i.useRef)(!1),{toast:m}=(0,s.pmc)(),{currentStep:p}=(0,u.H)(),y=(null==l?void 0:l.created_at)||new Date,[b,x]=(0,i.useState)(0);async function g(){if((null==l?void 0:l.status)!=="timed_out"&&!d&&!v.current&&("availability"===p||"guest_information"===p||p.includes("payment_error")||p.includes("payment_retry"))){v.current=!0;let r=await (0,o.Iox)(o.XH6,{where:{id:{_eq:null==l?void 0:l.id}},set:{status:"timed_out"}});if((null==r?void 0:r.data)&&(m({title:c("timedOut")}),await new Promise(e=>setTimeout(e,2e3)),window.location.reload()),null==r?void 0:r.errors){var e,a;m({title:null==r?void 0:null===(a=r.errors)||void 0===a?void 0:null===(e=a[0])||void 0===e?void 0:e.message}),console.error("updateReservationsOnCountDownOverError",null==r?void 0:r.errors)}}}return((p.includes("initializing")||p.includes("processing"))&&(d=!0),(0,i.useEffect)(()=>{if("availability"===p||"guest_information"===p||p.includes("payment_error")||p.includes("payment_retry")){let e=new Date(y),l=60*a-Math.floor((new Date().getTime()-e.getTime())/1e3);if(x(l>0?l:0),l<=0){g();return}let r=setInterval(()=>{x(e=>e<=1?(clearInterval(r),g(),0):e-1)},1e3);return()=>clearInterval(r)}},[y,a,g,p]),"availability"===p||"guest_information"===p||p.includes("payment_error")||p.includes("payment_retry"))?(0,r.jsx)("div",{className:"w-full flex justify-center",children:(0,r.jsxs)("p",{className:"w-fit bg-secondary py-1 px-3 rounded-full border text-xs gap-1 items-center flex",children:[(0,r.jsx)(n.Z,{size:14,className:"opacity-60"})," ",(0,r.jsx)("span",{className:"opacity-60",children:c("title")})," ",Math.floor(b/60),":",(b%60).toString().padStart(2,"0")]})}):null}},34011:function(e,l,a){a.d(l,{Z:function(){return d}});var r=a(27573),i=a(68055),t=a(77680),n=a(96504),o=a(18337),s=a(71811),u=a(19808);function d(){let e=(0,i.eR)("global.reservationCountdown"),{currentReservation:l}=(0,s.H)(),a=(0,o.k)(l);return(0,r.jsxs)("div",{className:"border rounded-md bg-secondary p-32 flex flex-col justify-center items-center gap-4",children:[(0,r.jsx)(t.Z,{size:40,strokeWidth:.8,className:"opacity-60"}),(0,r.jsx)("h2",{className:"text-lg font-semibold",children:e("timedOut")}),(0,r.jsx)(u.default,{href:"/availability?".concat(a),children:(0,r.jsx)(n.zxk,{size:"sm",className:"bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground",children:e("restart")})})]})}},72971:function(e,l,a){a.d(l,{j:function(){return i}});var r=a(7653);function i(e){let{config:l,params:a}=e;(0,r.useEffect)(()=>{let{id:e,placement:r,parameters:i}=l,t={vid:"hot",...a},n=i.filter(e=>e in t).map(e=>"".concat(e,"=").concat(encodeURIComponent(t[e]))),o="https://static.sojern.com/cip/w/s?id=".concat(e,"&f_v=v6_js&p_v=1&").concat(n.join("&")),s=document.createElement("script");return s.type="text/javascript",s.async=!0,s.id="".concat(e,"-").concat(r),s.innerHTML="\n      (function () {\n        var pl = document.createElement('iframe');\n        pl.type = 'text/html';\n        pl.style.cssText = 'height:0; width: 0; display:none;';\n        pl.async = true;\n        pl.src = '".concat(o,"';\n        document.getElementsByTagName('").concat(r,"')[0].appendChild(pl);\n      })();\n    "),document.getElementsByTagName(r)[0].appendChild(s),()=>{let l=document.getElementById("".concat(e,"-").concat(r));l&&l.remove()}},[l,a])}},4750:function(e,l,a){a.d(l,{o:function(){return n},r:function(){return t}});var r=a(7653),i=a(26155);function t(){return(0,r.useCallback)(e=>{let{eventName:l,eventData:a,userData:r,eventCharge:t}=e;window.gtag&&window.gtag("event",l,a),i.ZP&&i.ZP.capture(l,{...a}),window.dataLayer&&window.dataLayer.push({event:l,eventData:a}),window.mixpanel&&window.mixpanel.track(l,a),r&&(i.ZP&&i.ZP.identify(r.email,{...r,...a}),window.mixpanel&&window.mixpanel.identify(r.email),window.mixpanel&&window.mixpanel.alias(r.email),window.mixpanel&&window.mixpanel.people.set({$name:"".concat(r.firstName," ").concat(r.lastName),$email:r.email,$phone:r.phone,logged:r.isMember}),window.H&&window.H.identify(r.email,{...r,...a})),t&&window.mixpanel&&window.mixpanel.people.track_charge(t.total,{currency:t.currency})},[])}function n(){let[e,l]=r.useState(null),a=r.useCallback(()=>{!e&&window.Intercom&&l(window.Intercom)},[e]);r.useEffect(()=>{a()},[a]);let i=r.useCallback(()=>{a(),e&&e("show")},[e,a]),t=r.useCallback(()=>{a(),e&&e("hide")},[e,a]),n=r.useCallback(l=>{a(),e&&e("update",l)},[e,a]),o=r.useCallback((l,r)=>{a(),e&&e("trackEvent",l,r)},[e,a]);return{hide:t,open:i,showNewMessage:r.useCallback(l=>{a(),e&&e("showNewMessage",l)},[e,a]),trackEvent:o,update:n}}}}]);