1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6577],{56577:(t,e,r)=>{r.d(e,{_6:()=>z,vd:()=>p,zq:()=>f,bR:()=>H,lH:()=>L,fQ:()=>F.fQ,BT:()=>x,ad:()=>S,XF:()=>I,K3:()=>J,nl:()=>U,ZY:()=>j,jo:()=>q,Zq:()=>T,F0:()=>$,oM:()=>D,qO:()=>F.qO,UJ:()=>F.UJ,c8:()=>K});var a=r(95155),n=r(12115),o=r(83840),i=r(11171),u=r(80023),s=r(91970),c=r(6816),l=r(62312);class d extends Error{constructor(t,e){super(t),this.status=e,this.name="CartRequestError"}}class f extends Error{constructor(t){super(t),this.name="CouponError",this.code=t}}class p extends Error{constructor(t,e){super(e),this.name="CheckoutError",this.code=t}}function h(t){return{Accept:"application/json","Content-Type":"application/json","X-Client-Source":(0,u.getClientSourceHeader)(),"X-Client-Platform":(0,u.getClientPlatformHeader)(),...t?{"X-Currency":t}:{}}}async function w(t){try{return await t.json()}catch{return{}}}async function y(t){var e;let r=await w(t);return r.cart?{...e=r.cart,subtotal_formatted:(0,l.wv)(e.subtotal_formatted),discount_formatted:(0,l.wv)(e.discount_formatted),total_price_formatted:(0,l.wv)(e.total_price_formatted),coupon:e.coupon?{...e.coupon,discount_formatted:(0,l.wv)(e.coupon.discount_formatted)}:null,items:e.items.map(t=>({...t,unit_price_formatted:(0,l.wv)(t.unit_price_formatted),total_price_formatted:(0,l.wv)(t.total_price_formatted)}))}:null}function m(t){if(!t||"object"!=typeof t)return null;let e=Object.entries(t).flatMap(([t,e])=>(Array.isArray(e)?e:[e]).filter(t=>"string"==typeof t).map(e=>`${t}: ${e}`));return e.length>0?`Dados de checkout inv\xe1lidos: ${e.join(", ")}`:null}async function _(t,e){let r=await (0,o.nr)("/api/v1/cart",{method:"GET",headers:h(t),cache:"no-store",signal:e},{auth:!0});if(401===r.status)return null;if(!r.ok)throw new d(`Cart request failed: ${r.status}`,r.status);return y(r)}async function g(t,e,r,a){let n=await (0,o.nr)("/api/v1/cart/preview",{method:"POST",headers:h(e),body:JSON.stringify(a?{items:t,coupon_code:a}:{items:t}),cache:"no-store",signal:r});if(!n.ok)throw Error(`Cart preview failed: ${n.status}`);return y(n)}async function v(t,e,r){let a=await (0,o.nr)("/api/v1/cart/items",{method:"POST",headers:h(r),body:JSON.stringify({purchase_token:t,quantity:e})},{auth:!0});if(!a.ok)throw new d(`Cart add failed: ${a.status}`,a.status);let n=await y(a);if(!n)throw Error("Invalid cart response");return n}async function k(t,e,r){let a=await (0,o.nr)(`/api/v1/cart/items/${t}`,{method:"PATCH",headers:h(r),body:JSON.stringify({quantity:e})},{auth:!0});if(!a.ok)throw new d(`Cart update failed: ${a.status}`,a.status);let n=await y(a);if(!n)throw Error("Invalid cart response");return n}async function E(t,e){let r=await (0,o.nr)(`/api/v1/cart/items/${t}`,{method:"DELETE",headers:h(e)},{auth:!0});if(!r.ok)throw Error(`Cart remove failed: ${r.status}`);let a=await y(r);if(!a)throw Error("Invalid cart response");return a}async function C(t,e){let r=await (0,o.nr)("/api/v1/cart/coupon",{method:"POST",headers:h(e),body:JSON.stringify({code:t})},{auth:!0});if(!r.ok){let t=await w(r);if("string"==typeof t.error_code)throw new f(t.error_code);throw Error(`Coupon apply failed: ${r.status}`)}let a=await y(r);if(!a)throw Error("Invalid cart response");return a}async function b(t){let e=await (0,o.nr)("/api/v1/cart/coupon",{method:"DELETE",headers:h(t)},{auth:!0});if(!e.ok)throw Error(`Coupon remove failed: ${e.status}`);let r=await y(e);if(!r)throw Error("Invalid cart response");return r}async function S(t,e="stripe",r={}){let a=new URLSearchParams;t&&a.set("currency",t),a.set("payment_provider",e),r.customerDocument&&a.set("customer_document",r.customerDocument);let n=a.toString(),i=await (0,o.nr)(`/api/v1/checkout${n?`?${n}`:""}`,{method:"POST",headers:h(),body:JSON.stringify((0,c.gx)())},{auth:!0});if(!i.ok){let t=await w(i),e=m(t.errors),r="string"==typeof t.error?t.error:e||`Checkout request failed: ${i.status}`;if("string"==typeof t.code)throw new p(t.code,r);throw Error(r)}return await i.json()}let O=null;async function q(){return O??=N().catch(t=>{throw O=null,t})}async function N(){let t=await (0,o.nr)("/api/v1/payments/config",{method:"GET",headers:h()});if(!t.ok)throw Error(`Payments config failed: ${t.status}`);return await t.json()}async function $(t,e={}){let r=await (0,o.nr)("/api/v1/wallet_intents",{method:"POST",headers:h(t),body:JSON.stringify({save_card:!!e.saveCard,scope:e.scope??"wallet",...(0,c.gx)()})},{auth:!0});if(!r.ok){let t=await w(r);throw Error("string"==typeof t.message?t.message:`Wallet intent failed: ${r.status}`)}return await r.json()}function T(t,e,r,a="card",n={}){var i;let u=((i=e)instanceof Error?`${i.name}: ${i.message}`:"string"==typeof i?i:i&&"object"==typeof i?JSON.stringify(Object.fromEntries(P.flatMap(t=>{let e=i[t];return"string"==typeof e||"number"==typeof e?[[t,e]]:[]}))):"unknown_payment_error").replace(/\bpi_[A-Za-z0-9]+_secret_[A-Za-z0-9]+\b/g,"[FILTERED]").replace(/\bBearer\s+[^\s"']+/gi,"Bearer [FILTERED]"),s=!!n.guestCheckoutSessionId;(0,o.nr)("/api/v1/payments/client_errors",{method:"POST",headers:h(),body:JSON.stringify({stage:t,source:a,detail:u.slice(0,500),order_number:r,...s?{guest_checkout_session_id:n.guestCheckoutSessionId}:{}})},s?{}:{auth:!0}
1).catch(()=>{})}let P=["type","code","decline_code","message","intentStatus","intent","screen","at"];async function I(t){let e=await (0,o.nr)(`/api/v1/checkout/pix/${encodeURIComponent(t)}`,{method:"GET",headers:h(),cache:"no-store"},{auth:!0});if(!e.ok){let t=await w(e);throw Error("string"==typeof t.error?t.error:`Pix checkout request failed: ${e.status}`)}return await e.json()}async function j(t){let e=await (0,o.nr)("/api/v1/paypal/checkout/capture",{method:"POST",headers:h(),body:JSON.stringify({order_id:t})},{auth:!0});if(!e.ok){let t=await w(e);throw Error("string"==typeof t.error?t.error:`PayPal capture failed: ${e.status}`)}return await e.json()}async function J(t,e,r){let a=await (0,o.nr)("/api/v1/guest_checkouts",{method:"POST",headers:h(t),body:JSON.stringify({items:r.items,payment_provider:e,...r.couponCode?{coupon_code:r.couponCode}:{},...r.wallet?{wallet:!0}:{},...(0,c.gx)()})});if(!a.ok){let t=await w(a),e=m(t.errors),r="string"==typeof t.error?t.error:e||`Guest checkout request failed: ${a.status}`;if("string"==typeof t.code)throw new p(t.code,r);throw Error(r)}return await a.json()}async function x(t){let e=await (0,o.nr)(`/api/v1/guest_checkouts/${encodeURIComponent(t)}`,{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!e.ok)throw Error(`Guest checkout status failed: ${e.status}`);return await e.json()}async function U(t,e){let r=await (0,o.nr)(`/api/v1/guest_checkouts/${encodeURIComponent(t)}/paypal/capture`,{method:"POST",headers:h(),body:JSON.stringify({order_id:e})});if(!r.ok){let t=await w(r);throw new p("string"==typeof t.code?t.code:"string"==typeof t.status?t.status:"capture_failed","string"==typeof t.error?t.error:`Guest PayPal capture failed: ${r.status}`)}return await r.json()}let R="wavee_guest_cart";function A(t){return!!t&&"object"==typeof t&&"string"==typeof t.purchase_token&&t.purchase_token.length>0&&"number"==typeof t.quantity&&Number.isFinite(t.quantity)&&t.quantity>0}function D(){try{let t=window.localStorage.getItem(R);if(!t)return[];let e=JSON.parse(t);if(!Array.isArray(e))return[];return e.filter(A).slice(0,20)}catch{return[]}}function M(t){try{if(0===t.length)return void window.localStorage.removeItem(R);window.localStorage.setItem(R,JSON.stringify(t.slice(0,20)))}catch{}}function L(){M([])}function Q(t,e){return t.filter(t=>t.purchase_token!==e)}function G(t,e=t.quantity){let r=Math.max(1,Number(t.quantity)),a=Number(t.discount||0)/r,n=Math.max(0,Number(t.unit_price)-a);return{...(0,s.UN)({productName:t.product_name,planLabel:t.data.formatted??(t.data.unlimited?"Unlimited":null),durationDays:t.duration_days,destinationType:t.destination?.type,destinationCode:t.destination?.code,featureType:t.feature_type,journey:"Initial Purchase",price:n,quantity:e}),discount:a>0?a:void 0}}function H(t){return{currency:t.price_currency.toUpperCase(),value:Number(t.total_price),affiliation:s.kQ,coupon:t.coupon?.code||void 0,items:t.items.map(t=>G(t))}}function B(t,e,r){let a=G(e,r);return{currency:e.price_currency.toUpperCase(),value:Number(a.price??0)*r,affiliation:s.kQ,coupon:t.coupon?.code||void 0,items:[a]}}var F=r(65832);let X=(0,n.createContext)(void 0);function Z(t,e=!1){return t?{...t,itemCount:t.item_count,isLocal:e,items:e?t.items.map((t,e)=>({...t,id:e+1})):t.items}:null}function z({children:t}){let{status:e}=(0,o.Q8)(),{activeCurrency:r}=(0,i.Zy)(),{trackEvent:c}=(0,s.X1)(),[l,p]=(0,n.useState)(null),h=(0,n.useRef)(null),w=(0,n.useCallback)(t=>{h.current=t,p(t)}
1,[]),[y,m]=(0,n.useState)(!1),[S,O]=(0,n.useState)(!1),[q,N]=(0,n.useState)(!1),[$,T]=(0,n.useState)(!1),[P,I]=(0,n.useState)(!1),[j,J]=(0,n.useState)(null),x=(0,n.useRef)(!1),U=(0,n.useCallback)(async(t,e)=>{if(x.current)return null;x.current=!0,I(!0),J(t);try{return await e()}finally{x.current=!1,I(!1),J(null)}},[]),R=(0,n.useCallback)(async t=>{if(M(t),0===t.length)return w(null),null;try{let e=await g(t,r,void 0,(0,F.qO)()),a=Z(e,!0);return w(a),a}catch{return w(null),null}},[r,w]),A=(0,n.useCallback)(async()=>{if("loading"===e)return void O(!0);O(!0),T(!1);try{if("unauthenticated"===e)return void await R(D());try{let t=await _(r);w(Z(t))}catch(t){throw T(!0),t}}finally{O(!1)}},[r,w,R,e]),L=(0,n.useRef)(null),G=(0,n.useCallback)(async()=>{if(L.current)return void await L.current;let t=(async()=>{let t=D();if(0===t.length)return;let e=await _(r);if(!e)return;let a=new Map((e.items??[]).filter(t=>t.purchase_token).map(t=>[t.purchase_token,t])),n=[];for(let[e,o]of t.entries()){let i=a.get(o.purchase_token);try{i?await k(i.id,o.quantity,r):await v(o.purchase_token,o.quantity,r)}catch(a){let r=a instanceof d?a.status:0;if(401===r||403===r)return void M([...n,...t.slice(e)]);if(r>=400&&r<500&&408!==r&&429!==r)continue;n.push(o)}}M(n)})().finally(()=>{L.current=null});L.current=t,await t},[r]);(0,n.useEffect)(()=>{async function t(){if("authenticated"===e)try{await G()}catch{}try{await A()}finally{N(!0)}}"loading"!==e&&t()},[G,A,e]),(0,n.useEffect)(()=>{let t=()=>{A()};return window.addEventListener(u.MOBILE_CHECKOUT_EVENT,t),()=>{window.removeEventListener(u.MOBILE_CHECKOUT_EVENT,t)}},[A]);let H=(0,n.useRef)(e),K=(0,n.useRef)([]);(0,n.useEffect)(()=>{if(H.current=e,"loading"===e)return;let t=K.current;K.current=[],t.forEach(t=>t())},[e]);let V=(0,n.useCallback)(async()=>("loading"===H.current&&await new Promise(t=>{K.current.push(t)}),"unauthenticated"===H.current),[]),W=(0,n.useCallback)(t=>h.current?.items.find(e=>e.id===t)?.purchase_token??null,[]),Y=(0,n.useCallback)(async(t,e,a)=>{await U(null,async()=>{let n,o=h.current?.items.find(e=>e.purchase_token===t)?.quantity??0;if(await V()){var i;n=await R((i=D(),e<=0?i:!i.find(e=>e.purchase_token===t)?[...i,{purchase_token:t,quantity:e}].slice(0,20):i.map(r=>r.purchase_token===t?{...r,quantity:r.quantity+e}:r)))}else w(n=Z(await v(t,e,r)));let u=n?.items.find(e=>e.purchase_token===t),s=Math.max(0,(u?.quantity??0)-o);n&&u&&s>0&&c("add_to_cart",B(n,u,s)),(a?.openDrawer??!0)&&m(!0)})},[r,V,U,w,R,c]),tt=(0,n.useCallback)(async(t,e)=>{await U(t,async()=>{let a,n=h.current?.items.find(e=>e.id===t);if(await V()){var o;let r=W(t);if(!r)return;a=await R((o=D(),e<=0?Q(o,r):o.map(t=>t.purchase_token===r?{...t,quantity:e}:t)))}else w(a=Z(await k(t,e,r)));let i=h.current;if(!n||!i)return;let u=(a?.items.find(t=>t.purchase_token===n.purchase_token)?.quantity??0)-n.quantity;0!==u&&c(u>0?"add_to_cart":"remove_from_cart",B(a??i,n,Math.abs(u)))})},[r,V,U,w,R,W,c]),te=(0,n.useCallback)(async t=>{await U(t,async()=>{let e=h.current,a=e?.items.find(e=>e.id===t);if(await V()){let e=W(t);if(!e)return;await R(Q(D(),e))}else w(Z(await E(t,r)));e&&a&&c("remove_from_cart",B(e,a,a.quantity))})},[r,V,U,w,R,W,c]),tr=(0,n.useCallback)(async t=>{if("authenticated"!==e){(0,F.UJ)(t);let e=await R(D());if(e?.coupon_error)throw(0,F.fQ)(),new f(e.coupon_error);return}await U(null,async()=>{w(Z(await C(t,r)))})},[r,U,w,R,e]),ta=(0,n.useCallback)(async()=>{((0,F.fQ)(),"authenticated"!==e)?await R(D()):await U(null,async()=>{w(Z(await b(r)))})},[r,U,w,R,e]),tn=(0,n.useMemo)(()=>({cart:l,isOpen:y,isLoading:S,hasLoaded:q,loadFailed:$,isMutating:P,pendingItemId:j,openCart:()=>m(!0),closeCart:()=>m(!1),refreshCart:A,addItem:Y,updateItemQuantity:tt,removeItem:te,applyCoupon:tr,removeCoupon:ta}),[Y,tr,l,S,q,$,P,y,j,A,ta,te,tt]);return(0,a.jsx)(X.Provider,{value:tn,children:t})}function K(){let t=(0,n.useContext)(X);if(!t)throw Error("useCartSession must be used inside CartSessionProvider");return t}},65832:(t,e,r)=>{r.d(e,{UJ:()=>i,fQ:()=>o,qO:()=>n});let a="wavee_coupon_code";function n(){try{let t=window.localStorage.getItem(a);if(!t)return null;let e=JSON.parse(t);if(!e?.code||"number"!=typeof e.expiresAt)return null;if(Date.now()>e.expiresAt)return window.localStorage.removeItem(a),null;return e.code}catch{return null}}function o(){try{window.localStorage.removeItem(a)}catch{}}function i(t){try{let e={code:t,expiresAt:Date.now()+2592e6};window.localStorage.setItem(a,JSON.stringify(e))}catch{}}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.