import{Gt as e,Ht as n,It as a,J as t,Jt as r,Lt as o,Pt as s,Qt as i,Vt as l,Wt as u,Xt as d,en as c,ft as m,jt as p,nn as h,pt as v,yt as f,zt as y}from"./630ba094.L_X-5TXi.js";import{AO as g,Bu as b,Cb as _,Ed as A,Gb as S,Gg as C,Hn as O,Jx as P,Kg as E,Mo as R,SC as B,ST as T,Tp as I,UA as N,Un as H,Vw as w,Vx as k,WE as M,Wd as L,Xg as V,Yf as D,al as U,bp as x,fy as F,hC as j,hg as Y,hy as q,jO as K,jo as W,ku as z,lh as G,lk as J,mu as $,nh as Q,no as X,ow as Z,ru as ee,ry as ne,th as ae,ud as te,vx as re,wb as oe,xO as se,zh as ie,zl as le}from"./6ec9a0fa.rdcQt2v8.js";import{t as ue}from"./1befea5c.DNUfNYYr.js";import{i as de,o as ce}from"./9a493f3d.BU4_4NVs.js";import{r as me,t as pe}from"./e1177f6f.BdwRWO6B.js";import{r as he}from"./83f74304.Bpuuq40R.js";import{d as ve,o as fe,r as ye}from"./674595ba.CBCkPO6g.js";import{c as ge}from"./16138b9e.CcOfuQrQ.js";import{t as be}from"./542b75cf.C-_S3LI1.js";import{u as _e}from"./74e5a557.CRSHWf3c.js";import{c as Ae,n as Se,r as Ce,s as Oe,t as Pe}from"./f4d0afee.CBQgxqHw.js";import{t as Ee}from"./0b704646.CbhE_p2Q.js";function Re(){const{embed:e}=se();return n=>!e?.isFlagshipPartner||B(e.embedder)||j({embedder:e.embedder})?n:f(x,{children:n})}function Be(e){switch(e){case"payment_method_pay_now":return G.SHOP_PAY_PAY_NOW;case"default_payment_method_installments":return G.SHOP_PAY_INSTALLMENTS_DEFAULTED;case"default_payment_method_pay_now":return G.SHOP_PAY_PAY_NOW_DEFAULTED;default:return G.SHOP_PAY_INSTALLMENTS}}function Te(){const{userEvents:e}=se(),n=X();return{recordRetailEvent:d(a=>{const t=n.value;t&&e.monorailEvent({schemaId:"retail_shop_pay/2.0",payload:{...t,stage:Be(a)}})},[e,n])}}function Ie({storageKey:e,when:n,run:t}){const{source:o,persistence:s}=se(),i=r(!1);a(()=>{i.current||n.value&&y(()=>{i.current=!0;const n={scope:P(o)};s?.get(e,n)||(s?.createUpdate(e,n)(!0),t())})})}var Ne={id:"51513157511e655d494a79d188b83239264a5fe8a674f340b135dd735b56c4b6",type:"mutation",name:"ExperimentExposed",source:"mutation ExperimentExposed($experiments:[String!]!){experimentExposed(experiments:$experiments){userErrors{message __typename}__typename}}"};function He({experiment:e,storageKey:n,exposed:a}){const{graphql:{shopPayGraphql:t}}=se();Ie({storageKey:n,when:a,run:()=>{t.mutate(Ne,{variables:{experiments:[e]}})}})}var we="e_spi_checkout_badging",ke=e=>(e=>"amount"in e&&"string"==typeof e.amount)(e)?{amount:Number(e.amount),currencyCode:e.currencyCode}:{amount:Number(e.value),currencyCode:e.currency},Me=e=>{if(!e)return null;const n=ke(e);return(e=>Boolean(e.amount>0&&e.currencyCode&&z[e.currencyCode]))(n)?n:null},Le=e=>"redeemable"===e.method.type&&"SHOP_CASH"===e.method.redemptionSource,Ve=e=>{if(!e)return Se;if(!e.method.redemptionContent?.details)return Se;const n={...Se};for(const a of e.method.redemptionContent.details){const e=Oe.find(e=>e===a.redemptionType);if(void 0===e)continue;const t={id:a.redemptionId??e,promotionId:"SHOP_PROMOTION"===e?a.redemptionId:void 0,type:e,destinationAmount:ke(a.destinationAmount),sourceAmount:Me(a.sourceAmount)};"SHOP_PROMOTION"===e?n.SHOP_PROMOTION=[...n.SHOP_PROMOTION,t]:n[e]=t}return n},De=(e,n)=>{const a=e[n];return Array.isArray(a)?a.length>0:null!=a},Ue=()=>{const{checkout:{negotiator:e}}=se(),{paymentLines:n}=e.current.fields;return s(()=>Ve(n.value?.lines.find(Le)))},xe=()=>{const{checkout:{negotiator:e}}=se(),{paymentLines:n}=e.parts;return s(()=>Ve(n.value?.find(Le)))};function Fe(e,n){return e&&(t=n,(a=e).eligible===t.eligible&&a.nonEligibleReason===t.nonEligibleReason&&a.serverConfirmed===t.serverConfirmed)?e:n;var a,t}var je={eligible:!1,nonEligibleReason:Ae.ShopCashNotAvailable,serverConfirmed:!0},Ye={eligible:!0,nonEligibleReason:null,serverConfirmed:!1},qe=new Map;function Ke(){const{shopPay:e,checkout:n}=se(),a=ve(),t=s(()=>{if(!n.isShippingRequired.value)return{address:null,isShopPayVaultAddress:!1};const a=e.session.selectedShippingAddress.value;return a?.address?{address:a.address,isShopPayVaultAddress:!0}:{address:n.negotiator.parts.shippingAddress.value,isShopPayVaultAddress:!1}}),r=s(()=>{const r=e.session.selectedPaymentMethods.value[0],o=!n.negotiator.parts.paymentLines.value.some(e=>!Z(e))&&null!=r&&$(r);return("APPLE_PAY"===a.value||o)&&null!=t.value.address}),o=s(()=>{const a=e.session.selectedPaymentMethods.value[0];if(r.value&&t.value.address){const a=t.value.address,r=a.phone||n.negotiator.parts.billingAddress.value.phone||e.user.phoneNumber.value;return{address:r&&r!==a.phone?{...a,phone:r}:a,isShopPayVaultAddress:t.value.isShopPayVaultAddress}}const o=ee(a);if(o){const e=o.billingAddress.address;return{address:e.phone?e:{...e,phone:n.negotiator.parts.billingAddress.value.phone},isShopPayVaultAddress:!0}}const s=e.session.selectedBillingAddress.value;return s?.address?{address:s.address,isShopPayVaultAddress:!0}:"shipping"===n.negotiator.parts.billingAddressOption.value&&t.value.address?t.value:{address:n.negotiator.parts.billingAddress.value,isShopPayVaultAddress:!1}}),i=s(()=>t.value.address?.countryCode),l=s(()=>t.value.isShopPayVaultAddress),u=s(()=>o.value.address.countryCode),d=s(()=>o.value.isShopPayVaultAddress),c=m(re(i.value,void 0,n.configuration.addressSettings.nonBillingAddressSettings.value,l.value?null:void 0)),p=m(re(u.value,void 0,n.configuration.addressSettings.billingAddressSettings.value,d.value?null:void 0));return s(()=>{const e=t.value.address,n=o.value.address,a=e?We(c.value(e,"shipping")):qe,s=We(p.value(n,"billing"));return{selectedBillingAddress:n,selectedShippingAddress:e,isUsingApplePayShippingFallback:r.value,billingAddressErrors:s,shippingAddressErrors:a}})}function We(e){return 0===e.size?qe:e}function ze({requiresAvailableBalance:e=!0}={}){const n=function({requiresAvailableBalance:e=!0}={}){const{checkout:{negotiator:n}}=se(),a=n.current.fields.shopCashBalance,t=r(null),o=r(null);return s(()=>{const n=a.value;if("filled"===n?.status){const e=Fe(t.current,{eligible:n.eligible,nonEligibleReason:n.eligible?null:n.nonEligibleReason??"SHOP_CASH_NOT_AVAILABLE",serverConfirmed:!0});return t.current=e,o.current=null,e}if("unavailable"===n?.status&&e)return t.current=je,o.current=null,je;if(!t.current)return Ye;const r=Fe(o.current,{...t.current,serverConfirmed:!1});return o.current=r,r})}({requiresAvailableBalance:e}),{checkout:{negotiator:a}}=se(),t=a.current.fields.deliveryNext,o=oe("deliveryNext"),i=Ke(),l=r(null),u=s(()=>n.value.nonEligibleReason),d=s(()=>n.value.serverConfirmed),c=s(()=>i.value.billingAddressErrors.size>0),m=s(()=>{const e=t.value,n=o.value,{selectedShippingAddress:a,shippingAddressErrors:r}=i.value;return r.size>0||Boolean(a&&!n&&"unavailable"===e?.status)});return s(()=>{let e=null;u.value?e=u.value:m.value?e=Ae.ShopCashInvalidShippingAddress:c.value&&(e=Ae.ShopCashInvalidBillingAddress);const n=Fe(l.current,{eligible:null==e,nonEligibleReason:e,serverConfirmed:d.value});return l.current=n,n})}var Ge=()=>{const{userEvents:e,source:n,checkout:a,shop:t,shopPay:r}=se(),o=r.user.publicId.value,s=c(()=>({publicId:o}),[o]),i=d(r=>e.monorailEvent({schemaId:"shopify_pay_payment_page_shop_cash_redemption_visibility/1.1",payload:{...A(n,a,t),...s,...r}}),[e,n,a,t,s]),l=d(r=>e.monorailEvent({schemaId:"shopify_pay_payment_page_shop_cash_redemption_eligibility/3.1",payload:{...A(n,a,t),...s,...r}}),[e,n,a,t,s]);return{recordRedemptionActionEvent:d(r=>e.monorailEvent({schemaId:"shopify_pay_payment_page_shop_cash_redemption_actions/1.0",payload:{...A(n,a,t),...s,...r}}),[e,n,a,t,s]),recordRedemptionVisibilityEvent:i,recordRedemptionEligibilityEvent:l,recordRewardEligibilityEvent:d(r=>e.monorailEvent({schemaId:"shopify_pay_payment_page_shop_cash_reward_eligibility/5.1",payload:{...A(n,a,t),...s,...r}}),[e,n,a,t,s])}},Je="treatment",$e=["paymentDue","taxes","deliveryNext","paymentMethods"];function Qe(){const{checkout:e,shopPay:n}=se(),a=Q(),t=function(){const{checkout:{installments:e,proposal:n,negotiator:a},shop:t,shopPay:r}=se();return e.getCartAboveSpiThreshold(()=>function({threshold:e,paymentDue:n,merchantCountry:a,negotiationLoading:t}){let r;return o(()=>{const o=e.value,s=n.value;if(!o||!s)return;const i=t.value;return $e.some(e=>i.has(e))||(r="US"===a.value&&s.currencyCode===o.amount.currencyCode&&s.amount>=o.amount.amount),r})}({threshold:r.user.installments.spiPreselectionThreshold,paymentDue:n.negotiated.fields.paymentDue,merchantCountry:o(()=>e.config.value?.merchantCountry??t.countryCode),negotiationLoading:a.loading}))}();return s(()=>{if(!e.installments.isSupported.value)return{spiPreselected:!1,preselectionReason:void 0,preselectionReasons:[],shouldExposeThreshold:!1};const r=[];a.value&&r.push(W.PointOfSale),n.config.shouldPreSelectInstallments&&r.push(W.SpiBanner);const o=n.user.installments.preselectReason.value;o&&r.push(o);const s=n.user.installments.spiPreselectionThreshold.value,i=null!==s&&n.installments.isServiceAvailable.value&&!n.session.hasSelectedPaymentMethodOption.value&&!0===t.value;i&&"treatment"===s?.variant&&r.push(W.ReturningSpiBuyerThreshold);const l=r.length>0;return{spiPreselected:l,preselectionReason:l?r.join(","):void 0,preselectionReasons:r,shouldExposeThreshold:i&&!e.installments.isUnavailable.value&&!n.session.isInternalProgressing.value}})}function Xe(e){if("filled"!==e?.status)return null;const{discountOffer:n}=e;if(!n.offerAmount||!n.campaignHandle)return null;const a=n.minimumOrderValue?{amount:n.minimumOrderValue,satisfied:Boolean(n.minimumOrderValueSatisfied),remainingAmount:n.minimumOrderValueRemainder??null}:null;return{adType:"SHOP_CASH_OFFER",campaignHandle:n.campaignHandle,offerAmount:n.offerAmount,redeemableAmount:!a||a.satisfied?n.offerAmount:null,minimumOrderValue:a}}function Ze(){const{checkout:e}=se(),n=r(null);return s(()=>{const a=e.proposal.negotiated.fields.shopDiscountOffer.value;return"unavailable"===a?.status?(n.current=null,null):("filled"!==a?.status||(n.current=Xe(a)),n.current)})}var en={eligible:!0},nn=({requiresAvailableBalance:e=!0}={})=>{const n=function({requiresAvailableBalance:e=!0}={}){const n=ze({requiresAvailableBalance:e}),a=r(null),{checkout:{negotiator:t}}=se(),{paymentMethods:o,shopCashBalance:i}=t.current.fields;return s(()=>{const{nonEligibleReason:t}=n.value,r=Boolean(o.value?.some(e=>"redeemable"===e.type&&"SHOP_CASH"===e.redemptionSource)),s=i.value,l=null==s||"unavailable"===s.status;let u;u=e&&l?Ae.ShopCashNotAvailable:r?t:Ae.ShopCashMerchantNotSupported;const d=a.current?.nonEligibleReason===u?a.current:{nonEligibleReason:u};return a.current=d,d})}({requiresAvailableBalance:e}),a=r(null);return s(()=>{const{nonEligibleReason:e}=n.value;if(e){const n=e,t={eligible:!1,reason:n},r=!1===a.current?.eligible&&a.current.reason===n?a.current:t;return a.current=r,r}return a.current=null,en})};function an(){return nn({requiresAvailableBalance:!1})}function tn(a,t){e(()=>{if(!t)return;const e=n(()=>{const e=a.value;y(()=>t(e))});return()=>{e(),t(!1)}},[a,t])}function rn(e,n,a){u(()=>{if(e&&a)return e.recordPresentation({component:n,displayLabel:a})},[n,a,e])}var on=()=>{const{embed:e,i18n:n,shop:a,shopPay:t}=se(),r=B(e?.embedder),o=t.app.config.surface,s=a.hasFlagEnabled(M),i=le();return"shop_app"===o||!r&&s?f(E,{tone:"monochrome",onClick:()=>{r?function(e){if("undefined"==typeof window)return;const n=function(e){if(e)try{return new URL(e).origin}catch{return}}(e);n&&window.parent.postMessage({jsonrpc:"2.0",method:"ec.keep_shopping"},n)}(e?.client?.embedderOrigin):i.notify({keep_shopping:!0})},children:f(g,{type:"small",children:n.translate("shop_cash.minimum_order_value_banner_keep_shopping")})}):null},sn=({adType:e,offerAmount:n,minimumOrderValueAmount:a,remainingAmount:t,incentivePresentation:r})=>{const{i18n:o}=se(),i=Ee(),l=(()=>{const{checkout:{negotiator:e}}=se(),n=e.current.fields.discountLines;return s(()=>{const e=n.value;return{hasMerchandiseDiscounts:!!e&&e.lines.some(e=>!!ne(e)&&e.allocations.some(e=>"MERCHANDISELINE"===e.target.type)),orderDiscountAmount:e?e.lines.filter(ne).filter(e=>"CART"===e.discount.presentationLevel&&e.allocations.some(e=>"MERCHANDISELINE"===e.target.type)).reduce((e,n)=>{const a=n.amount?.amount;return a?e+a:e},0):0}})})(),u=s(()=>l.value.hasMerchandiseDiscounts),d=o.formatCurrency(n.amount,{currency:n.currencyCode,form:"short"}),c=o.formatCurrency(a.amount,{currency:a.currencyCode,form:"short"}),m=t?o.formatCurrency(t.amount,{currency:t.currencyCode,form:"short"}):void 0,h=ln({adType:e,formatMinimumOrderAmount:c,formatRemainingAmount:m,formatOfferAmount:d,hasMerchandiseDiscounts:u.value});return rn(r,"minimumOrderValueBanner","FLAT_AMOUNT_CASHBACK_OFFER"===e?h:void 0),f(V,{padding:"small-200 small-100",borderRadius:"base",accessibilityRole:"status",className:p("dark"===i?"dHa7y":"O9AXs","automatic"===i&&"RbxJj"),children:[f(D,{type:"small",children:h}),f(on,{})]})},ln=({adType:e,formatMinimumOrderAmount:n,formatRemainingAmount:a,formatOfferAmount:t,hasMerchandiseDiscounts:r})=>{const{i18n:o}=se(),s=r||!a;return"SHOP_CASH_OFFER"===e?s?o.translate("shop_cash.minimum_order_value_banner_discounts_offer_amount",{formatBoostedAmount:t,formatMinimumOrderAmount:n}):o.translate("shop_cash.minimum_order_value_banner",{formatRemainingAmount:a,formatBoostedAmount:t}):"FLAT_AMOUNT_CASHBACK_OFFER"===e?s?o.translate("shop_cash.minimum_order_value_banner_discounts_flat_cashback",{formatOfferAmount:t,formatMinimumOrderAmount:n}):o.translate("shop_cash.minimum_order_value_banner_flat_cashback",{formatRemainingAmount:a,formatOfferAmount:t}):""};function un({eligibility:e,offerEligibility:n,discountOffer:a}){const t=i(pe),r=t?.cashback?.incentive;if(!e.eligible&&!n.eligible)return[];const o=[];var s;return n.eligible&&a?.minimumOrderValue&&!a.minimumOrderValue.satisfied&&o.push(f(sn,{adType:a.adType,offerAmount:a.offerAmount,minimumOrderValueAmount:a.minimumOrderValue.amount,remainingAmount:a.minimumOrderValue.remainingAmount},"mov-discount")),e.eligible&&(s=r,Boolean("ShopCashCheckoutFlatAmountCashbackIncentive"===s?.__typename&&s.minimumOrderValue&&!s.minimumOrderValueSatisfied))&&o.push(f(sn,{adType:"FLAT_AMOUNT_CASHBACK_OFFER",offerAmount:r.cashbackAmount,minimumOrderValueAmount:r.minimumOrderValue,remainingAmount:r.minimumOrderValueRemainder,incentivePresentation:t?.incentivePresentation},"mov-cashback")),o}function dn({onDrawsChange:e}){const{checkout:n,embed:a}=se(),t=B(a?.embedder),r=s(()=>t&&!n.configuration.visibility.showCashRedemption.value);return f(v,{when:r,children:f(cn,{onDrawsChange:e})})}function cn({onDrawsChange:e}){const n=nn(),a=an(),t=Ze(),r=s(()=>n.value.eligible||a.value.eligible);return f(v,{when:r,children:f(mn,{eligibility:n,offerEligibility:a,discountOffer:t.value,onDrawsChange:e})})}function mn({eligibility:e,offerEligibility:n,discountOffer:a,onDrawsChange:t}){const r=ae(se().checkout).main,o=U(),i=s(()=>o.value.payment),l=s(()=>function(e){const[n,a]=(t=e,Array.isArray(t)?2===t.length?[t[1],t[1]]:[t[1],t[3]]:[t,t]);var t;return`small-200 ${I(n)??"none"} small-200 ${I(a)??"none"}`}(r.value.section?.padding)),u=un({eligibility:e.value,offerEligibility:n.value,discountOffer:a});return tn(m(u.length>0),t),0===u.length?null:f(v,{when:i,fallback:f(fe,{padding:"none large-200",children:f(C,{padding:"small-200 none",gap:"small-200",children:u})}),children:()=>f(C,{padding:l.value,gap:"small-200",children:u})})}function pn({checked:e,onChange:n,disabled:a}){return f(ue,{checked:e,onChange:n,icon:"none",className:"mu1NS",accessibilityLabel:"Shop Cash",disabled:a})}function hn(e,n){return null==e&&null==n||null!=e&&null!=n&&e.amount===n.amount&&e.currencyCode===n.currencyCode}function vn({enabled:e=!0}={}){const{shopPay:n,checkout:{negotiator:a}}=se(),t=m(e),r=m(i(pe)?.redemption);return s(()=>{const e=a.current.fields.buyerIdentity.value?.shopUser?.publicId;return t.value&&Boolean(e)&&!n.session.isInternalProgressing.value&&!1===r.value?.applying?.value})}var fn=e=>({type:e.type,amount:e.destinationAmount,promotionId:e.promotionId}),yn=({enabled:e=!0}={})=>{const{shopPay:n,checkout:{negotiator:a}}=se(),t=xe(),r=i(pe)?.redemption.applying,o=a.parts.paymentLines,s=Ke(),u=ve();return d(async(i,{onNegotiateAccepted:d}={})=>{const{SHOP_CASH_BALANCE:c,SHOP_DISCOUNT_OFFER:m,SHOP_PROMOTION:p}=t.value,{SHOP_CASH_BALANCE:h=(c?fn(c):null),SHOP_DISCOUNT_OFFER:v=(m?fn(m):null),SHOP_PROMOTION:f=p.map(fn)}=i,y=n.session.isInternalProgressing.value,g=a.current.fields.buyerIdentity.value?.shopUser?.publicId;if(!e)return;if(!r)return;if(y)return;if(!g)return;if(r.value)return;l(()=>{r.value=!0});const b=o.value.filter(e=>"redeemable"!==e.method.type||"SHOP_CASH"!==e.method.redemptionSource),_=Object.values(i).flatMap(e=>Array.isArray(e)?e:[e]).find(e=>null!=e)?.amount.currencyCode,A=[h,v,...f??[]].filter(e=>null!==e&&(!_||e.amount.currencyCode===_)),{selectedBillingAddress:S,selectedShippingAddress:C,isUsingApplePayShippingFallback:O}=s.value,P=!S.address1||"APPLE_PAY"===u.value,E=function(e,n,a){const[t]=e;if(!t)return null;const r=e.reduce((e,n)=>e+n.amount.amount,0),o=t.amount.currencyCode;return{cost:{amount:r,currencyCode:o},method:{type:"redeemable",redemptionSource:"SHOP_CASH",redemptionContent:{redemptionId:a,billingAddress:{streetAddress:n?{address1:n.address1??"",address2:n.address2,city:n.city??"",company:n.company,firstName:n.firstName,lastName:n.lastName??"",phone:n.phone,postalCode:n.postalCode,zoneCode:n.zoneCode,countryCode:n.countryCode??""}:null},destinationAmount:{amount:r.toString(),currencyCode:o},sourceAmount:{amount:r.toString(),currencyCode:o},redemptionPaymentOptionKind:"decoupled",details:e.map(e=>({sourceAmount:{amount:e.amount.amount.toString(),currencyCode:e.amount.currencyCode},destinationAmount:{amount:e.amount.amount.toString(),currencyCode:e.amount.currencyCode},redemptionId:e.promotionId??e.type,redemptionType:e.type}))}}}}(A,!O&&C&&P?C:S,g);E&&b.push(E),o.value=b;try{d?.(),await a.negotiate({withResultHandling:!0,silenceViolations:["non-shop-cash",...F(["paymentLines","billingAddress"])]})}finally{l(()=>{r.value=!1})}},[r,e,a,u,o,t,s,n.session.isInternalProgressing])},gn=()=>{const{checkout:{negotiator:e}}=se(),n=e.current.fields.subtotalAfterMerchandiseDiscounts,a=_(),r=bn(),o=_n();return s(()=>{const e=a.value,s=e?{amount:O(e.amount-r.value-o.value,t(e.currencyCode)),currencyCode:e.currencyCode}:void 0;return{orderTotal:e,orderSubtotal:n.value,redeemableTotal:s}})},bn=()=>{const{checkout:{negotiator:e}}=se(),{paymentLines:n}=e.current.fields;return s(()=>(n.value?.lines??[]).reduce((e,n)=>n.cost&&Z(n)&&!Le(n)?e+n.cost.amount:e,0))},_n=()=>{const e=Ue();return s(()=>Object.values(e.value).flatMap(e=>Array.isArray(e)?e:[e]).reduce((e,n)=>n?"SHOP_CASH_BALANCE"===n.type?e:e+n.destinationAmount.amount:e,0))},An=Ce,Sn=e=>{const{i18n:n,shopPay:a,webMcp:t,checkout:o}=se(),s=vn(),i=yn(),l=xe(),c=Ue(),{applying:m}=me().redemption,{buyerIdentity:p,shopCashBalance:h}=o.negotiator.current.fields,v=gn(),f=Cn(p.value),y=Cn(h.value),g=(b=h.value,"filled"===b?.status&&b.eligible&&(b.redeemableBalance?.amount??0)>0?void 0:Cn(v.value));var b;const _=Boolean(l.value[An]),A=c.value[An]?.destinationAmount||null,S=r(e);S.current=e;const C=d(async n=>{if(m.value)return;const a=n?e:null;hn(A,a)&&hn(l.value[An]?.destinationAmount,a)||await i({[An]:a?{type:"SHOP_CASH_BALANCE",amount:a,promotionId:null}:null})},[A,e,i,m,l]);u(()=>{if(t&&e.amount>0)return t.unstable_registerDeclaredField({key:"shop_cash",read(){const e=o.latestReceipt.value?.status;if(!e||!["processed","processing","processing_remote_checkouts","polling_for_order","action_required"].includes(e))return{key:"shop_cash",purpose:"dev.shopify.shopping.declared_fields.generic",title:"Shop Cash",description:"Apply the available Shop Cash balance. Resend true to retain it in a checkout update; omission or null removes it.",value_schema:{type:"boolean"},required:!1,value:Boolean(l.value[An])}},prepare(n){if(null!==n&&"boolean"!=typeof n)return{requirement:"must be a boolean or null"};const t=!0===n;return{phase:"negotiate",changed:!0,async apply(){if(!s.value||m.value||a.session.isInternalProgressing.value||Cn(p.value)!==f||Cn(h.value)!==y||void 0!==g&&Cn(v.value)!==g)return!1;if(await C(t),m.value)return!1;const n=c.value[An]?.destinationAmount??null;return hn(n,t?e:null)&&hn(n,t?S.current:null)}}}})},[t,o,a.session,e,l,c,s.value,m,p,f,h,y,v,g,C]);const O=r(null);u(()=>{m.value||O.current!==e&&(O.current=e,A&&(hn(A,e)||C(!0)))},[e,m.value]);const P=n.formatCurrency(e.amount,{currency:e.currencyCode,form:"short"});return{title:n.translate("order_summary.shop_cash_title"),amount:_?n.translate("shop_cash.redemption.balance.applied",{formattedAmount:P}):n.translate("shop_cash.redemption.balance.available",{formattedAmount:P}),checked:_,handleChange:C,disabled:m.value}};function Cn(e){return JSON.stringify(e)??""}var On={rollup:{blockAlignment:"center"}},Pn=({redeemableBalance:e})=>{const{title:n,amount:a,checked:t,handleChange:r,disabled:o}=Sn(e);return f("div",{className:"yY3sV",children:f(he,{theme:On,children:f(ge,{label:n,primaryContent:a,primaryAction:f(pn,{checked:t,onChange:r,disabled:o})})})})},En=()=>{const{i18n:e}=se(),n=Ee(),a=e.translate("payment_errors.vaulted_card_required_error");return f(V,{padding:"small-200 small-100",borderRadius:"base",accessibilityRole:"status",className:p("Q9An4","dark"===n&&"K92xU","automatic"===n&&"HTvo7"),children:f(D,{type:"small",children:a})})},Rn={availableBalance:null,redeemableBalance:null};function Bn(){const e=r([]),{checkout:n}=se(),a=n.proposal.negotiated.fields.shopPromotion;return s(()=>{const n=a.value;return"filled"===n?.status?e.current=n.promotions.flatMap(e=>e.redeemableBalance&&e.redeemableBalance.amount>0?[{...e,availableBalance:e.redeemableBalance}]:[]):"unavailable"===n?.status&&(e.current=[]),e.current})}var Tn=()=>{const{recordRedemptionActionEvent:e}=Ge(),{observability:n,shop:a,shopPay:t}=se(),r=a.hasFlagEnabled(M),o=t.app.config.surface,s=Boolean("undefined"!=typeof window&&window.ReactNativeWebView),i=c(()=>({shopPayCheckoutSurface:o,isReactNativeWebview:s,isShopCashBalanceBetaEnabled:r,isOnePageCheckout:!0,nEnabledCreditCards:0}),[o,s,r]),l=d(a=>{e({...i,...a}),n.counter({name:"shop_cash_redemption_action",value:1,attributes:{action:a.action,redemption_type:a.redemptionType,hook:a.source}})},[i,e,n]);return{recordRedemptionAutomaticallyApplied:d((e,n)=>{l({action:"auto-apply",redemptionType:e,source:n})},[l]),recordRedemptionAutomaticallyRemoved:d((e,n)=>{l({action:"auto-remove",redemptionType:e,source:n})},[l])}},In=({enabled:e=!0,redemptionTypes:n=Oe}={})=>{const a=Ue(),t=i(pe)?.cashbackState.stale,{recordRedemptionAutomaticallyRemoved:r}=Tn(),o=yn({enabled:e}),s=te(ie(T)).value;u(()=>{if(!e||!t||!s)return;let i=!1;for(const e of n)De(a.value,e)&&(i=!0,r(e,"useRemoveRedemptionsOnViolation"));i&&(t.value=!0,o(Object.fromEntries(n.map(e=>[e,null]))))},[e,s])},Nn=(e,{enabled:n=!0}={})=>{const t=vn({enabled:n}),r=yn({enabled:n}),{recordRedemptionAutomaticallyRemoved:o}=Tn(),i=xe(),l=m(e.filter(e=>!e.eligibility.eligible).flatMap(e=>e.redemptionTypes??Oe).join(",")),u=m(n),d=s(()=>l.value?l.value.split(","):[]),c=s(()=>d.value.filter(e=>De(i.value,e)).join(","));a(()=>{const e=d.value;if(!u.value||0===e.length)return;if(!t.value)return;const n=c.value;if(!n)return;const a=n.split(",");y(()=>{r(Object.fromEntries(e.map(e=>[e,null])),{onNegotiateAccepted:()=>{for(const e of a)o(e,"useRemoveRedemptionsWhenIneligible")}})})})},Hn=class extends Error{constructor(){super("Multiple Shop Cash payment lines present in negotiation response"),this.name="MultipleShopCashPaymentLinesAnomaly"}},wn=({message:e})=>f(K,{gridAutoFlow:"column",gridTemplateColumns:"minmax(auto, max-content) minmax(0, 1fr)",gridTemplateRows:"minmax(0, 1fr)",borderRadius:"base",borderWidth:"base",padding:"small-400 small-200",gap:"small-200",accessibilityRole:"alert",alignItems:"center",alignContent:"center",children:[f(J,{type:"alert-circle",size:"small"}),f(D,{color:"subdued",type:"small",children:e})]});function kn(){const{eligibility:e,shopCashBalance:n,discountOffer:t,messages:o,showVaultedCardBanner:i,vaulted:l,isBalanceRedemptionEligible:d,balanceRedemptionEligibility:m}=Mn(),p=s(()=>n.value.redeemableBalance).value,h=s(()=>n.value.availableBalance).value;return function(e){const n=r(!1),a=r(performance.now()),{observability:t}=se();u(()=>{if(!n.current&&e&&e.amount>0){const e=performance.now()-a.current;t.histogram({name:"new_performance_shop_cash_balance_display_time",value:Math.round(e)}),n.current=!0}},[e,t])}(h),Nn([{eligibility:m,redemptionTypes:[Ce]}]),In(),(e=>{const{client:n,shop:a,shopPay:t}=se(),{recordRedemptionVisibilityEvent:r}=Ge(),o=n.unstable_getSerialization("apiClientId"),s=a.hasFlagEnabled(M),i=t.app.config.surface,l=Boolean("undefined"!=typeof window&&window.ReactNativeWebView),d=U();u(()=>{r({visibility:"visible",reason:e.reason??"none",position:d.value.payment?"vaulted":"unvaulted",shopPayCheckoutSurface:i,isReactNativeWebview:l,isShopCashBalanceBetaEnabled:s,apiClientId:o,isOnePageCheckout:!0,nEnabledCreditCards:0})},[r,e.reason])})(e),(({eligibility:e,availableBalance:n,redeemableBalance:a,discountOffer:t})=>{const{recordRedemptionEligibilityEvent:r}=Ge(),o=gn(),s=c(()=>t?t.minimumOrderValue&&!t.minimumOrderValue.satisfied?"BELOW_MOV":void 0:"NO_CAMPAIGN",[t]);u(()=>{const{orderTotal:i,orderSubtotal:l}=o.value;i&&r({balance:n?.amount??0,balanceCurrency:n?.currencyCode??"USD",totalPrice:i.amount,totalPriceCurrency:i.currencyCode,subtotalPrice:l?.amount??0,subtotalPriceCurrency:l?.currencyCode??"USD",maxTotalRedemptionAllowed:a?.amount??0,isBoostAvailable:Boolean(t),boostCampaignId:t?.campaignHandle,offerAmountBelowMov:t?.minimumOrderValue?.remainingAmount?.amount,offerMinimumOrderValueRequired:t?.minimumOrderValue?.amount.amount,maxPostOfferRemainingAmount:0,maxOfferRedemptionAmount:t?.offerAmount?.amount,boostIneligibilityReason:s,redemptionIneligibilityReason:e.reason})},[r,e.reason,n,a,t])})({eligibility:e,availableBalance:h,redeemableBalance:p,discountOffer:t.value}),(()=>{const{observability:e,source:n,checkout:t}=se(),o=r(!1);a(()=>{const a=t.negotiator.current.fields.paymentLines.value?.lines.filter(Le)??[];if(a.length<=1)return;if(o.current)return;const r=JSON.stringify(a.map(e=>e.method.redemptionContent?.details?.map(n=>({redemptionPaymentGroupId:e.method.redemptionContent?.redemptionId,redemptionId:n.redemptionId,type:n.redemptionType,amount:n.destinationAmount}))));o.current=!0,y(()=>{e.error(new Hn,{severity:"error",metadata:{shopCash:{redemptions:r},source:{type:n.type},checkout:{token:n.checkoutSessionIdentifier||n.sourceId}}})})})})(),{eligibility:e,redeemableBalance:p,messages:o,showVaultedCardBanner:i,vaulted:l.value,isBalanceRedemptionEligible:d}}function Mn(){const e=U(),n=s(()=>e.value.payment),a=nn().value,o=an().value,i=(()=>{const{checkout:{negotiator:e}}=se(),{shopCashBalance:n}=e.current.fields,a=gn(),o=r(null);return s(()=>{const e=n.value,{redeemableTotal:r}=a.value;"filled"===e?.status?o.current=e.availableBalance:"unavailable"===e?.status&&(o.current=null);const s=o.current;if("filled"===e?.status&&e.eligible&&null!=e.redeemableBalance&&e.redeemableBalance.amount>0)return{availableBalance:e.availableBalance,redeemableBalance:e.redeemableBalance};if(!s)return Rn;if(s.amount<=0)return Rn;if(!r)return Rn;const i=Pe(r.currencyCode);if(r.amount<=i)return Rn;if(r.amount=i?{availableBalance:s,redeemableBalance:s}:{availableBalance:s,redeemableBalance:H({amount:s.amount-(i-l),currencyCode:s.currencyCode})}})})(),l=s(()=>null!=i.value.redeemableBalance).value,u=Ze(),d=s(()=>{const e=u.value;return e?.minimumOrderValue&&!e.minimumOrderValue.satisfied?e:null}),c=Bn(),m=un({eligibility:a,offerEligibility:o,discountOffer:d.value}),{eligibilityMessage:p,showVaultedCardBanner:h}=(e=>{const n=(()=>{const{i18n:e}=se();return n=>{if(n)switch(n){case"SHOP_CASH_INVALID_BILLING_ADDRESS":return e.translate("shop_cash.redemption_invalid_billing_address");case"SHOP_CASH_INVALID_SHIPPING_ADDRESS":return e.translate("shop_cash.redemption_invalid_shipping_address");case"SHOP_CASH_MERCHANT_NOT_SUPPORTED":case"PAYMENTS_SHOP_CASH_UNSUPPORTED_CURRENCY":return e.translate("shop_cash.redemption_unsupported_merchant");case"SHOP_CASH_UNSUPPORTED_DELIVERY_METHOD_TYPE":return e.translate("shop_cash.redemption_unsupported_delivery_method");case"PAYMENTS_SHOP_CASH_UNSUPPORTED_SHIPPING":return e.translate("shop_cash.redemption_unsupported_shipping");case"PAYMENTS_SHOP_CASH_GIFT_CARD_NOT_ALLOWED":return e.translate("shop_cash.redemption_unsupported_gift_cards");case"INSUFFICIENT_FUNDING_LEDGER_BALANCE":return e.translate("shop_cash.redemption_error_exclusive_campaign_out_of_funds");case"BUYER_BALANCE_HOLD_ERROR":return e.translate("shop_cash.redemption_balance_hold",{shopRewardsTermsLink:f(E,{target:"_blank",href:"https://shop.app/shop-cash-terms",children:e.translate("shop_cash.shop_rewards_terms")})});case"DISCOUNT_OFFER_ERROR":return e.translate("shop_cash.exclusive_offer_error");case"SHOP_CASH_NOT_AVAILABLE":case"PAYMENTS_SHOP_CASH_ORDER_TOTAL_TOO_LOW":return;default:return e.translate("shop_cash.redemption_error")}}})(),{checkout:a}=se(),{paymentLines:t}=a.negotiator.current.fields,r=Y(),o=s(()=>r.value&&Boolean(t.value?.lines.find(Le)));return{eligibilityMessage:n(e.reason),showVaultedCardBanner:o}})(a),v="PAYMENTS_SHOP_CASH_UNSUPPORTED_SHIPPING"===a.reason,y=a.eligible||v&&l,g=y&&!a.eligible?{eligible:!0}:a,b=[];return p&&!v&&b.push(f(wn,{message:p},"eligibility-banner")),b.push(...m),{eligibility:a,shopCashBalance:i,hasRedeemableBalance:l,discountOffer:u,shopPromotionDiscounts:c,messages:b,showVaultedCardBanner:h,vaulted:n,isBalanceRedemptionEligible:y,balanceRedemptionEligibility:g}}function Ln(){const{eligibility:e,messages:n,hasRedeemableBalance:a,discountOffer:t,shopPromotionDiscounts:r,isBalanceRedemptionEligible:o}=Mn(),i=Ue(),l=s(()=>Boolean(t.value?.redeemableAmount)),u=s(()=>r.value.length>0),d=s(()=>Oe.some(e=>De(i.value,e)));if(o&&a)return!0;const c=u.value;return!(!e.eligible||!l.value&&!c)||!!d.value||n.length>0}var Vn=({onDrawsChange:e})=>{const{redeemableBalance:n,messages:a,showVaultedCardBanner:t,vaulted:r,isBalanceRedemptionEligible:o}=kn(),i=m(r),l=m(a.length>0),u=s(()=>t.value&&!i.value),d=s(()=>l.value||u.value),c=m(Boolean(o&&n));return tn(s(()=>c.value||d.value),e),f(h,{children:[o&&n&&f(ye,{hideDivider:r,condition:!r,children:f(Pn,{redeemableBalance:n})}),f(v,{when:d,children:f(ye,{hideDivider:r,condition:!r,padding:"none large-200",children:f(C,{padding:"small-200 none",gap:"small-200",children:[a,f(v,{when:u,children:f(En,{})})]})})})]})};function Dn(e,n){return e.currentUrl.value.hash===`#${n}`}function Un(){const{i18n:e,checkout:{negotiator:n}}=se(),{paymentLines:a}=n.parts,{violations:t}=ie(w),{message:r,tone:o}=de(),i=s(()=>{const e=[...t.value][0];return e&&(e.localizedMessage||e.nonLocalizedMessage)}).value,l=s(()=>{const e=a.value.find(e=>"giftCard"!==e.method.type&&"redeemable"!==e.method.type)?.method;return"customOnsite"===e?.type?e.name:void 0}).value,d=void 0!==l,c=d?e.translate("payment_errors.local_payment_method_unavailable",{payment_method:l}):void 0,m=Boolean(r)&&("critical"===o||"warning"===o),p=i&&c&&m?`${c}. ${i}`:void 0;return u(()=>{if(p)return N({content:p})},[p]),i&&d?f(ce,{errorType:L.PaymentError,bannerId:"LocalPaymentMethodUnavailableBanner",tone:"warning",heading:c,autoFocus:!m,children:i}):null}function xn({onAutoExpand:e}={}){const{source:n,checkout:t,shop:o,observability:i,userEvents:l,shopPay:d,client:c}=se(),{visibility:m}=d,p=t.installments.isSupported.value,h=t.installments.isUnavailable.value,v=s(()=>t.installments.isUnavailable.value||d.user.installments.wasRejected.value),f=Q(),g=s(()=>"SHOPIFY_INSTALLMENTS"===be(d)&&t.installments.isSupported.value&&t.installments.isUnavailable.value),{paymentMethods:_}=t.negotiator.current.fields,A=s(()=>S(_.value)),C=s(()=>t.installments.isSupported.value?A.value?.availableLoanTypes:void 0),O=r(),P=Qe(),E=s(()=>P.value.spiPreselected).value,B=s(()=>P.value.shouldExposeThreshold),{recordRetailEvent:T}=Te();He({experiment:"e_spi_preselection_cart_threshold",storageKey:k.SpiPreselectionThresholdExposure,exposed:B}),a(()=>{g.value&&y(()=>{d.session.unstable_updatePaymentMethodOption({type:"wallet",name:"SHOP_PAY"})})}),u(()=>{d.session.isInternalProgressing.value||p&&!h&&(!f.value&&m.showAutoExpandedPaymentMethods&&e?.(),E&&(d.session.unstable_updatePaymentMethodOption({type:"wallet",name:"SHOPIFY_INSTALLMENTS"}),d.user.installments.unstable_recordSpiAutoSelection(P.peek().preselectionReasons),i.leaveErrorBreadcrumb("SPI preselected",{})))},[p,h,f.value,E,P,d.session,d.user.installments,i,m.showAutoExpandedPaymentMethods,e]),a(()=>{const e=t.installments.isSupported.value,n=t.installments.isUnavailable.value;f.value&&e&&y(()=>{T(n?"default_payment_method_pay_now":"default_payment_method_installments")})}),a(()=>{const e=C.value;!v.value&&e&&JSON.stringify(O.current)!==JSON.stringify(e)&&(y(()=>{l.monorailEvent({schemaId:"shopify_pay_payment_page_installments/1.4",payload:{..._e(n,t,o,c.userAgentDetails),eventType:R.InterestEligibility,success:b(e),errorMessage:b(e)?void 0:JSON.stringify(["amount"])}}),l.monorailEvent({schemaId:"shopify_pay_payment_page_installments/1.4",payload:{..._e(n,t,o,c.userAgentDetails),eventType:R.SplitPayEligibility,success:Boolean(e.includes("SPLIT_PAY")),errorMessage:e.includes("SPLIT_PAY")?void 0:JSON.stringify(["amount"])}})}),O.current=e)})}function Fn(){const{checkout:{negotiator:e}}=se(),{generalPaymentError:n,generalPaymentErrorCode:a}=e.parts,{violations:t}=ie(w);return s(()=>!!n.value&&(!q(a.value)||t.value.size>0))}var jn={DivideChildren:"K6vpG",noVaultedDividers:"_5hYUU",ShowTopDivider:"CU3YS",ShowBottomDivider:"_5HWz9",StripBlockStartPadding:"r8rqQ",StripBlockEndPadding:"_2Ojsq",HideBottomDividerUnlessFollowed:"KxbnS",StripBlockEndPaddingUnlessFollowed:"hYBKK",VaultedTrailingContent:"_6hTcn","VaultedTrailingContent-spacedStart":"_9MUb8"};function Yn({active:e=!0,spaceStart:n=!0,children:a}){const t=qn({spaceStart:n});return e?f("div",{...t,className:p(jn.VaultedTrailingContent,t.className),children:a}):f(h,{children:a})}function qn({spaceStart:e=!0}={}){const{embed:n}=se();return{className:e&&B(n?.embedder)?jn["VaultedTrailingContent-spacedStart"]:void 0,"data-after-vaulted":!0}}export{ke as A,Ze as C,Ge as D,Je as E,Te as F,Re as I,we as M,He as N,ze as O,Ie as P,an as S,Qe as T,vn as _,xn as a,dn as b,Vn as c,Nn as d,In as f,yn as g,Sn as h,Fn as i,Me as j,Ue as k,kn as l,Bn as m,qn as n,Un as o,Tn as p,jn as r,Dn as s,Yn as t,Ln as u,hn as v,Xe as w,rn as x,pn as y};