import{u as e,M as t,m as r,t as n,v as a,w as s}from"./2c1ab0fe.Dbn2KvkT.js";import{f as o,k as i,e_ as u,ap as l,b as c,cl as p,eX as d,l as h,x as m,w as y,b_ as _,bA as g}from"./164ad2e3.FTBuhkTQ.js";import{d as v,d1 as f,dQ as P,d0 as b,k as E,dR as S,dS as k,dT as I,dU as A,dV as C,aK as R,dW as T,dX as B,bU as O,P as w,dY as N,a4 as L,dZ as G,N as x}from"./4b4bc88f.z1yoAwwH.js";import{S as U}from"./39921a74.bahNnP3U.js";import{u as M}from"./7a8217fd.qHfhLK3T.js";import{i as D}from"./2bac2c53.CBL7jHzd.js";import{a as F,U as K}from"./app.CooG55fE.js";import{g as j,u as W,a as q}from"./ec391382.Bx3C9xNN.js";import{c as J}from"./c6b02d73.Ba1sudbg.js";import{v as H}from"./2210eadb.DF0gIp_2.js";import{g as Y,a as $,b as Q}from"./9dba8418.NidtnoQ4.js";import{S as V}from"./71b60e0a.DfPLdYsH.js";import{d as X,U as Z}from"./24773686.CplnJ3xw.js";import{v as z,b as ee}from"./1f5e7811.a2EjfHnG.js";import{u as te}from"./22345fd4.DfRWVvfi.js";import{a as re,u as ne,b as ae,e as se}from"./e3e348f2.DlRIwDFx.js";function oe({line:r}){const{i18n:n,source:a}=v(),s="paymentCollection"===a.type,{title:u,lineAmount:l}=r,c=0===l.amount?n.translate("shipping.free_rate_label"):n.formatCurrency(l.amount,{currency:l.currencyCode,form:"short"}),p=0===l.amount?"uppercase":void 0;return e(o,{children:[u,s?null:e(t,{children:[" ยท ",e(i,{type:"strong",letterCase:p,children:c})]})]},u)}const ie="shop-pay-hsa-details",ue=`${ie}-description`;function le(){const{checkout:e,shop:t,shopPay:n}=v(),a=e.negotiator.current.fields.paymentMethods,{paymentLines:s}=e.negotiator.parts,o=M();return r(()=>{const r=P(a.value),i=t.hasFlagEnabled(b)&&function({identity:e}){return"shopPay"===e.current.value}({identity:e.identity})&&("ELIGIBLE"===r||"ELIGIBLE_LMN_REQUIRED"===r||"ELIGIBLE_LMN_NOT_REQUIRED"===r||"MIXED_CART"===r),{freeOrder:u,giftCard:l,storeCredit:c,redeemables:p}=o.value,d=u||l||c||p;if(!i||n.session.isInstallmentsSelected.value||d)return!1;const h=n.session.selectedPaymentMethod.value;if(h)return"CREDIT_CARD"===h.paymentMethod;const m=s.value[0]?.method,y="wallet"===m?.type&&"SHOP_PAY"===m.name?m.walletContent:void 0,_=null!=y&&"paymentMethod"in y&&"CREDIT_CARD"===y.paymentMethod;return"direct"===m?.type||_})}function ce(){const{checkout:e,shopPay:t}=v(),n=le();return r(()=>n.value&&f(e.proposal.negotiated.fields.paymentMethods.value)&&t.session.hsaRequested.value)}function pe(){const{i18n:a,shopPay:s,checkout:i}=v(),p=r(()=>P(i.proposal.negotiated.fields.paymentMethods.value)),d=r(()=>"ELIGIBLE"!==p.value&&"ELIGIBLE_LMN_REQUIRED"!==p.value&&"ELIGIBLE_LMN_NOT_REQUIRED"!==p.value),h="MIXED_CART"===p.value,m=r(()=>!d.value&&s.session.hsaRequested.value),y=h?a.translate("payment.shop_pay_hsa.mixed_cart_description"):a.translate("payment.shop_pay_hsa.description"),_=n(e=>{d.value||s.session.unstable_setHsaRequested(e)},[d,s.session]);return e(c,{background:"base",colorLayer:"control",border:"base",borderRadius:"base",children:[e("span",{id:ue,hidden:!0,children:y}),e(u,{id:ie,open:h||m.value,summary:e(c,{padding:"base",children:e(U,{label:a.translate("payment.shop_pay_hsa.label"),checked:m.value,disabled:d.value,onChange:_,icon:"none","aria-controls":`${ie}-content`,"aria-describedby":ue})}),content:e(t,{children:[e(l,{}),e(c,{padding:"base",children:e(o,{type:"small",color:"subdued",children:y})})]})})]})}function de(e){return a(()=>e.some(e=>{if("customField"===e.kind)return E(e).required.peek();const t=E(e);return t.behaviors.peek().blockProgress&&t.capabilities.blockProgress}),[e])}function he({enabled:e,userEvents:t,shop:r,source:n,shopPay:a,attempt:s,event:o}){if(!e||!s.id||a?.isSimulated||"shopPayExternal"!==n.type||!n.checkoutSessionIdentifier)return!1;try{const e={eventTypeName:F,idempotencyKey:H(),attemptId:s.id,presentation:"iframe"===s.presentation?"PRESENTATION_IFRAME":"PRESENTATION_POPUP"},a="STAGE_ATTEMPT"===o.stage?{...e,...o,...s.supersedesAttemptId&&{supersedesAttemptId:s.supersedesAttemptId}}:{...e,...o};return t.refineryEvent(J(a,{shopId:r.id,checkoutSessionIdentifier:n.checkoutSessionIdentifier,customerId:void 0}),{exportImmediately:!0}),!0}catch{return!1}}function me(e){switch(e){case"progress_continue":return"BLOCK_STAGE_PROGRESS_CONTINUE";case"progress_blocked":return"BLOCK_STAGE_PROGRESS_BLOCKED";case"progress_interceptor":return"BLOCK_STAGE_PROGRESS_INTERCEPTOR";case"progress_error":return"BLOCK_STAGE_PROGRESS_ERROR";case"unverified_user":return"BLOCK_STAGE_UNVERIFIED_USER";case"journey_blocked":return"BLOCK_STAGE_JOURNEY_BLOCKED";case"negotiation_queue":return"BLOCK_STAGE_NEGOTIATION_QUEUE";case"interceptor":return"BLOCK_STAGE_INTERCEPTOR";case"validation":return"BLOCK_STAGE_VALIDATION";case"payment_method_token":return"BLOCK_STAGE_PAYMENT_METHOD_TOKEN";case"missing_source":return"BLOCK_STAGE_MISSING_SOURCE";case"exception":return"BLOCK_STAGE_EXCEPTION"}}function ye(){const{source:e,shop:t,observability:r,shopPay:a,userEvents:s}=v(),o=a&&A(a)?a:void 0,i=o&&(t.hasFlagEnabled(S)||t.hasFlagEnabled(k)),u=n((n,a,i)=>!!o&&function({observability:e,userEvents:t,shop:r,source:n,shopPay:a,stage:s,reason:o="none",payNowAttempt:i}){const u=r.hasFlagEnabled(S),l=r.hasFlagEnabled(k);if(!u&&!l)return!1;if((r.hasFlagEnabled(I)||l)&&!i)return!1;const c=a.telemetry.paymentAttempt.finishPayNowAttempt(i);return!!c&&(u&&e.counter({name:"shop_pay_external_completion_blocked",value:1,attributes:{...j(a.clientSource),attempt:c.attempt,stage:s,reason:o}}),he({enabled:l,userEvents:t,shop:r,source:n,shopPay:a,attempt:c,event:{stage:"STAGE_PRE_DISPATCH",outcome:"OUTCOME_BLOCKED",blockStage:me(s)}}),!0)}({observability:r,userEvents:s,shop:t,source:e,shopPay:o,stage:n,reason:a,payNowAttempt:i}),[r,t,o,e,s]);return i?u:void 0}function _e(e){return Promise.resolve().then(()=>e())}function ge({existing:e,scope:t,next:r}){return[...e.filter(e=>!function(e,t){return!!e&&(e===t||e.startsWith(`${t}.`))}(e.target,t)),...r]}var ve=(e=>(e.BlankEmail="blank_email",e.BlankPhone="blank_phone",e.InvalidEmail="invalid_email",e.InvalidPhone="invalid_phone",e.ShopAccountsInvalidEmail="shop_accounts_invalid_email",e.ShopAccountsInvalidPhone="shop_accounts_invalid_phone",e.ShopAccountsPhoneLimitReached="shop_accounts_phone_limit_reached",e))(ve||{});function fe(){const{progressContinueWithResult:e}=Pe();return{progressContinue:n(async t=>"continue"===await e(t),[e])}}function Pe(){const{source:e,observability:t,shopPay:o,checkout:{negotiator:i}}=v(),{progressInterceptor:u}=o,l=ye(),{createUnverifiedUser:c}=function(){const e=function(){const{shopPay:e,checkout:{negotiator:t}}=v(),{email:n}=t.parts;return r(()=>{const t=n.value.trim(),r=e.userVerification.value,a=z(t,ve.BlankEmail),s=ee(t,ve.InvalidEmail),o="invalid"===r.status&&r.email===t?ve.InvalidEmail:void 0;return{email:t,emailError:a||s||o}})}(),{source:{checkoutSessionIdentifier:t},url:a,shopPay:o}=v(),i=o.user.phoneNumber,u=o.user.unstable_setPhoneNumber,{transactionParams:l}=o.config,c=o.user.isAuthenticatedUser,p=(()=>{const{shopPay:e}=v(),t=e.signup.phoneNumber,n=e.signup.phoneCountryCode,a=te(),o=s(a.isPhoneNumberUtilLoaded),i=s(a.validatePhoneNumber),u=e.user.isAuthenticatedUser;return r(()=>({missingRequiredMobilePhoneNumber:Boolean(!u.value&&(!t.value||o.value&&!i.value(t.value,n.value,!0)))}))})(),d=n(async(r=!0)=>{const{email:n,emailError:s}=e.value;if(c.value||i.value)return{status:"skipped"};if(!l)return{status:"failed",errors:[{field:[],code:"missing_content",message:"Transaction params are missing"}]};const h=[];if(s&&h.push({field:["email"],code:s,message:"email is blank or invalid"}),p.value.missingRequiredMobilePhoneNumber&&h.push({field:["phone"],code:ve.InvalidPhone,message:"Mobile phone number is missing or invalid"}),h.length>0)return{status:"failed",errors:h};let m=r?o.signup.hcaptchaToken.value:void 0;if(!m)try{const e=o.signup.captchaRef.value,t=await(e?.execute({async:!0}));t&&(m=t.response)}catch(g){return"challenge-closed"===g?{status:"failed",errors:[]}:{status:"failed",errors:[{field:["hcaptcha"],code:String(g),message:"A captcha error was caught and handled"}]}}let y=null;try{const e=o.signup.phoneNumber.value||"";y=await fetch(a.shopPayCreateUnverifiedUser(),{method:"POST",body:JSON.stringify({email:n,phone:e,hcaptcha_token:m,origin:"c1_unverified_user_signup",checkout_token:t,transaction_params:l}),headers:{"Content-Type":"application/json",accept:"application/json"}})}catch{return{status:"failed",errors:[{field:[],code:"unknown_error",message:"An error was caught and handled during API request"}]}}const _=await y.json();return 200!==y.status?Array.isArray(_?.errors)&&1===_?.errors.length&&"further_authorization_required"===_?.errors[0].code&&r?(o.signup.unstable_setHcaptchaToken(void 0),d(!1)):{status:"failed",errors:_?.errors||[{field:[],code:`response_with_http_error_${y.status}`,message:"Failed to create user"}]}:(u(_.parsed_phone),o.user.unstable_setEmail(n),o.user.unstable_updateFlow("authenticated_user"),{status:"success"})},[c,i,l,e,p,u,o,a,t]);return{createUnverifiedUser:d}}(),{handleCreateUnverifiedUserErrors:d}=function(){const{i18n:e,shopPay:t,checkout:{validation:{contactErrors:{emailInputError:r}}}}=v(),s=p(),{openModal:o}=X(),i=a(()=>({[ve.BlankEmail]:e.translate("field_errors.email_blank"),[ve.InvalidEmail]:e.translate("field_errors.email_invalid"),[ve.ShopAccountsInvalidEmail]:e.translate("field_errors.email_invalid")}),[e]),u=a(()=>({[ve.BlankPhone]:e.translate("mobile_phone_number.mobile_phone_invalid"),[ve.InvalidPhone]:e.translate("mobile_phone_number.mobile_phone_invalid"),[ve.ShopAccountsInvalidPhone]:e.translate("mobile_phone_number.mobile_phone_invalid"),[ve.ShopAccountsPhoneLimitReached]:e.translate("mobile_phone_number.phone_limit_reached")}),[e]);return{handleCreateUnverifiedUserErrors:n(e=>{if(0===e.length)return;const n=e.map(e=>e.code),a=i[n.find(e=>e in i)],l=u[n.find(e=>e in u)];return a||l?(r.value=a,t.signup.unstable_setPhoneError(l)):o({type:Z.Generic}),Promise.resolve().then(()=>s())},[i,r,s,o,u,t.signup])}}(),h=p(),m=n(async r=>{try{const e=await c(),n=await u.runInterceptors();i.setValidationErrors(ge({existing:i.validationErrors.value,scope:C,next:Y(n)}));const a=$(n);if(!a){const e=Q(n);t.log("shop_pay_progress_interceptor_error_reported","Shop Pay progress interceptor reported an error in useShopPayProgressContinue",{interceptorErrors:e})}if("failed"===e?.status)return l?.("unverified_user",void 0,r),d(e.errors),"blocked";if(!a)return l?.("progress_interceptor",void 0,r),_e(h),"blocked"}catch(a){l?.("progress_error",void 0,r);const s=a;return D(s.message)||function(e){return K.includes(e.name)}(s)?t.log("shop_pay_progress_continue_unactionable_error","Shop Pay progress continue swallowed an unactionable error in useShopPayProgressContinue",{errorName:s.name,errorMessage:(n=s.message,n?.slice(0,be)),sourceType:e.type}):t.error(s,{errorClass:V.ShopPayProgressIntercept,severity:"error",metadata:{source:{type:e.type},checkout:{token:e.checkoutSessionIdentifier??"checkout_identifier_undefined"}}}),"errored"}var n;return"continue"},[c,h,d,u,i,t,e,l]);return a(()=>({progressContinueWithResult:m}),[m])}const be=200;function Ee(){const{source:e,checkout:t,shop:r,shopPay:a,observability:s,userEvents:o}=v(),i=a.installments;return n(()=>{i.isServiceAvailable.value&&!t.installments.isBuyerBlocked.value&&(i.unstable_setFailedAttempt(null),i.unstable_setModalOpen(!0,"checkout_button"),s.log("installments_modal_opened","[Installments] Modal opened"),o.monorailEvent({schemaId:"shopify_pay_payment_page_ui_interaction/1.2",payload:{...R(e,t,r),action:"continue_with_installments"}}))},[i,s,o,e,t,r])}function Se(){const e=v(),{shop:t}=e,n=re(),a=O(),s=t.hasFlagEnabled(w);return r(()=>N(e.checkout,{showPayWithApplePayButton:n.value,paymentFullyCoveredByRedeemablesAndGiftCards:a.value,isApplePayInShopPayKillswitched:s}))}function ke(){const e=v(),{checkout:t,shopPay:n}=e,a="shopPay"===t.identity.current.value,s=ne().value,o=function(){const{checkout:{identity:e,negotiator:t}}=v(),{paymentLines:n}=t.parts,{inMemoryGooglePayParts:{paymentSheetOpenPromise:a}}=L(),s=function(){const{persistedGooglePaySignal:e}=L(),{checkout:t}=v();return r(()=>{const r=e.value?.receiptIdForPaymentFailure,n=t.latestReceipt.value;return Boolean("failed"===n?.status&&"payment"===n?.failure?.type&&r&&n?.id===r)})}();return r(()=>"googlePay"===e.current.value&&!!x(n.value,"GOOGLE_PAY")&&(void 0!==a?.value||s.value))}().value,i=ae().value,u=!a&&s&&!i,l=!a&&o,{showApplePay:c,isApplePayInShopPay:p}=Se().value,d=function({identity:e},{showPayWithPayPal:t,showApplePay:r,showPayWithGooglePay:n,isEmbeddedCheckout:a,shouldRenderCheckoutProtocolButton:s,isInstallmentsSupported:o,isInstallmentsSelected:i}){const u="shopPay"===e.current.value;return u&&o&&i?"installments":u&&s?"checkoutProtocol":t&&!u?"payPal":r?"applePay":n&&!u?"googlePay":!u&&a?"embedded":"default"}(t,{showPayWithPayPal:u,showApplePay:c&&!i,showPayWithGooglePay:l,isEmbeddedCheckout:se(),shouldRenderCheckoutProtocolButton:function(){const e=g(),t=e?.config;return"NATIVE"===t?.payActionType}(),isInstallmentsSupported:e.checkout.installments.isSupported.value,isInstallmentsSelected:n.session.isInstallmentsSelected.value});return{kind:d,showPayWithPayPal:u,isApplePayInShopPay:p,shouldDeferWalletToReview:i}}function Ie(e){const{kind:t}=ke(),r=function(){const{showApplePay:e}=Se().value,t=L().applePaySessionHandler.value,r=t?.onClickHandler??null,a=q({breadcrumbPrefix:G,isApplePay:!0}),s=n(()=>{r?.({validateButtonPress:a})},[r,a]);return e&&r?s:null}(),s=function(){const{checkout:{identity:e},observability:t,shopPay:r}=v(),s=d(),{nextPage:o}=m(),{progress:i}=y(),{progressContinue:u}=fe(),l=function(){const{observability:e,source:t,router:r}=v(),{currentDetour:n,currentPage:s}=h().value,{nextPage:o,previousPage:i}=m();return a(()=>({ensureShopPayURL:()=>{s||r.navigate("/shoppay",{replace:!0})},logError:(r,{result:a}={})=>{e.error(new T(r,{groupingHash:"ShopPayError::InvalidPageLogger"}),{severity:"error",metadata:{source:{type:t.type},checkout:{token:t.checkoutSessionIdentifier||t.sourceId},event:{currentDetour:JSON.stringify(n),currentPage:JSON.stringify(s),nextPage:JSON.stringify(o),previousPage:JSON.stringify(i),result:JSON.stringify(a)}}})}}),[n,s,e,o,i,r,t.checkoutSessionIdentifier,t.sourceId,t.type])}(),c=_(),p=W(),g=function(){const{source:e,shop:t,observability:r,shopPay:a,userEvents:s}=v(),o=a&&A(a)?a:void 0,i=t.hasFlagEnabled(S),u=t.hasFlagEnabled(k),l=t.hasFlagEnabled(I)||u,c=o&&(i||l),p=n(()=>{if(!o)return;const n=o.telemetry.paymentAttempt.startPayNowAttempt({correlate:l});return i&&r.counter({name:"shop_pay_external_pay_now_clicked",value:1,attributes:{...j(o.clientSource),attempt:n.attempt}}),he({enabled:u,userEvents:s,shop:t,source:e,shopPay:o,attempt:n,event:{stage:"STAGE_ATTEMPT",outcome:"OUTCOME_STARTED"}}),l?{payNowAttempt:n}:void 0},[i,l,r,u,t,o,e,s]);return c?p:void 0}(),f=ye(),P=q({breadcrumbPrefix:B}),b=n(async()=>{if(!P())return;const e=g?.(),n=t=>f?.(t,void 0,e?.payNowAttempt),a=async()=>{p();try{r.session.unstable_setButtonProgressing(!0),await u(e?.payNowAttempt)?(t.leaveErrorBreadcrumb(`${B} - progress`),await i("shop-pay-progress-button-press",e=>{t.leaveErrorBreadcrumb(`${B} - progression`,{status:e.status,nextPageId:o.id}),"thankYou"!==o.id&&l.logError("Shop Pay button triggered progression when next page is not `thankYou`",{result:e})},{...e,onProgressBlocked:()=>{n("progress_blocked"),t.leaveErrorBreadcrumb(`${B} - progress blocked`,{nextPageId:o.id}),l.ensureShopPayURL()}}),n("journey_blocked"),c.notify({checkout_in_progress:!0})):(n("progress_continue"),t.leaveErrorBreadcrumb(`${B} - progress continue failed`,{nextPageId:o.id}),"thankYou"!==o.id&&(l.logError("Shop Pay button is pressed when next page is not `thankYou`"),l.ensureShopPayURL()))}finally{r.session.unstable_setButtonProgressing(!1)}};if(!g)return a();try{return await a()}catch(s){throw n("exception"),s}},[P,g,p,f,r.session,u,t,i,o,l,c]);return"shopPay"!==e.current.value||s?null:b}(),o=function(){const{checkout:{identity:e},shopPay:t,observability:r}=v(),a=d(),{progressContinue:s}=fe(),o=Ee(),i=n(async()=>{t.session.unstable_setButtonProgressing(!0),r.log("installments_cta_clicked","[Installments] Continue to purchase button clicked");try{await s()&&o()}finally{t.session.unstable_setButtonProgressing(!1)}},[t.session,r,s,o]);return a||"shopPay"!==e.current.value||!t.session.isInstallmentsSelected.value?null:i}();return"applePay"===t&&r?r:"installments"===t&&o?o:"default"!==t&&"checkoutProtocol"!==t||!s?e:s}const Ae={Button:"liLqL",Sparkles:"b71fw"},Ce={Button:"OJbFq",WalletLogoContainer:"wNUaA"},Re={StickyFooter:"XR3sZ",StickyFooterExperiment:"_4fPUS",StickyFooterAtBottom:"_5FRe7",StickyFooterBuffer:"ZDqoP",SDKStickyFooterBuffer:"zANgR",EmbedStickyFooterBuffer:"_3A6oJ",ButtonContainer:"K8y4t",SDKButtonContainer:"_7S3NK",EmbedButtonContainer:"SdyJr"},Te={Wrapper:"GsMGr",Container:"eDhAI",Section:"P0xJW","Container-fixed":"iRlFp","Container-fixed-entering":"_24aJk","Container-fixed-exiting":"ktbnR","Container-fixed-enter":"PCKgT","Container-fixed-exited":"DvZWz",Shadow:"COpTB","Shadow-enter":"_0hDB9","Shadow-exiting":"P1NPi","Shadow-exited":"lQN1j"};export{oe as D,pe as H,le as a,Ce as b,Re as c,ce as d,fe as e,Ee as f,_e as g,ke as h,Se as i,Pe as j,de as k,Te as l,ge as r,Ae as s,Ie as u};