import{dK as ee,a as t,d as Y,a2 as W,b3 as Fe,a6 as w,hK as fe,bd as ge,df as Re,e as M,hL as Le,hM as Me,hN as _e,hs as le,aR as ye,hO as be,hP as xe,hQ as Be,hR as ke,ai as ne,ab as L,p as Ie,hS as Ve,hT as we,q as I,ak as R,ax as j,a1 as U,n as te,S as Te,ar as ve,hU as ze,hV as De,hW as Ge,bB as Pe,B as $,$ as $e,hX as He,aA as Ue,c2 as We,Q as Ye,at as Je,f7 as Se,hY as qe,e8 as oe,hZ as ae,aj as re,gC as K,ao as Ze,h_ as ie,cm as Ke,h$ as Qe,bO as Xe,v as Q,f as Ee,al as je,am as ce,T as Ne,co as en,i0 as nn,bM as tn,i1 as on,i2 as an,i3 as rn,dh as sn,i4 as ln,i5 as cn,i6 as un,i7 as dn,i8 as mn,a_ as ue,I as pn,i9 as hn,dD as fn,ag as gn,ia as _n,aO as yn}from"./app.owqgWGYv.js";import{u as bn}from"./ShopPayOptInDisclaimer.Bl8MpR5A.js";const H="0";function In({label:e}){const n=ee();return t(fe,{id:H,ref:n("tipping_none"),children:t(Y,{inlineAlignment:"center",blockAlignment:"center",minBlockSize:"fill",children:t(W,{children:Fe()?e:t(w,{type:"strong",children:e})})})})}function Tn({tipOption:e}){const{amount:n,percentage:o}=e,i=ge(),s=Re().numberFormatter({style:"percent",minimumFractionDigits:0,maximumFractionDigits:2}),a=ee();return t(fe,{id:n.amount.toString(),ref:a(`tipping_percent_${o}`),children:t(Y,{inlineAlignment:"center",blockAlignment:"center",minBlockSize:"fill",children:[t(W,{children:s.format(o)}),t(W,{type:"small",color:"subdued",children:i(n.amount,{currency:n.currencyCode,form:"short"})})]})})}function vn({tipOptions:e,onChange:n,proposedTip:o}){const i=M();return t("div",{style:Le({[le.toggleButtonGroup.blockPadding]:le.spacing.small200}),children:t(Me,{value:o?.amount?.amount?.toString()??H,onChange:n,children:t(_e,{columns:e.map(()=>"fill"),spacing:"none",children:e.map(r=>r.amount.amount>0?t(Tn,{tipOption:r},r.amount.amount.toString()):t(In,{label:i("tips.no_tip_label")},"zero-amount"))})})})}function Pn(){const{currencyCode:e}=ye(),{value:n}=be(),{value:o}=xe();return n?.presentmentCurrency??o?.currencyCode??e}function Sn(e,n){switch(n.type){case"NEGOTIATION_START":return{...e,loading:!0};case"INPUT":return{...e,customTip:n.payload,dirty:Cn(n.payload,e.negotiatedTip),error:void 0};case"NEGOTIATION_ERROR":return{...e,loading:!1,dirty:!1,...n.payload};case"NEGOTIATION_FINISH":return{...e,customTip:n.payload.customTip,loading:!1,dirty:!1,negotiatedTip:n.payload.negotiatedTip};case"CLEAR":return{...e,customTip:n.payload};default:return e}}function En(e,n){Be({currencyCode:e,tipOptions:n},On);const{value:o}=ke(),i=o?.[0],r=ge(),s=de(n,i,r),{tipLines:a}=ne(),c=a.value[0],[h,y]=L(""),{negotiate:u}=Ie(),T=Ve(),[P,d]=we(Sn,{loading:!1,dirty:!1,negotiatedTip:i,customTip:{amount:s,currencyCode:e}}),f=I(()=>{d({type:"CLEAR",payload:{amount:"",currencyCode:e}})},[e]),S=I(async g=>{const m=n?.find(({amount:b})=>b.amount===Number(g));if(!m)return;const E=me(m.amount.amount,m.amount.currencyCode),x={amount:g,currencyCode:m.amount.currencyCode};a.value=E,await u({onComplete:b=>{const A=X(b);d({type:"NEGOTIATION_FINISH",payload:{customTip:x,negotiatedTip:A}}),f()}})},[n,a,u,f]),l=I(async()=>{d({type:"NEGOTIATION_START"});const g=me(P.customTip.amount,e);a.value=g,await u({onComplete:m=>{const E=Nn(m),b={amount:de(n,X(m),r),currencyCode:e},A=X(m),N=r(Number(P.customTip.amount),{currency:b.currencyCode,form:"short"}),F=E?{type:"NEGOTIATION_ERROR",payload:{customTip:b,error:E}}:{type:"NEGOTIATION_FINISH",payload:{customTip:b,negotiatedTip:A}};E&&(y(N),T()),d(F)}})},[P.customTip.amount,e,a,u,n,r,T]),O=I(g=>{d({type:"INPUT",payload:{amount:g==="undefined"?H:g,currencyCode:e}})},[e]),C=I(async()=>{a.value=[],await u({onComplete:f})},[f,u,a]);return R(()=>{s===""&&d({type:"CLEAR",payload:{amount:"",currencyCode:e}})},[s,e]),{state:P,negotiatedTip:i,invalidTipValue:h,proposedTip:c,onChange:S,onInput:O,onSubmit:l,clear:C}}function Nn(e){return e.status==="success"||e.status==="error"?e.violations.find(n=>n.__typename==="ConfirmChangeViolation")?.localizedMessage??null:null}function X(e){if(e.status==="success"||e.status==="error")return e.negotiated.tipLines?.[0]}function de(e,n,o){return!(n&&e?e.some(r=>r.amount.amount===n.amount.amount):!1)&&n?o(n.amount.amount,{currency:n.amount.currencyCode,form:"plain"}):""}function me(e,n){return String(e)===H?[]:[{amount:{amount:Number(e),currencyCode:n}}]}function On({currencyCode:e,tipOptions:n}){return`currency: ${e}, tipOptions: ${JSON.stringify(n)}`}function Cn(e,n){return!n&&e.amount===H?!1:parseFloat(e.amount)!==n?.amount.amount}const pe="tipping_list_options",An=[];function Yn({renderInSection:e}){const n=M(),o=t(te,{children:[t(j,{level:2,children:n("tips.title")}),t(U,{}),t(Fn,{})]});return e?t(ve,{accessibilityLabel:n("tips.title"),padding:Te.default("base large-200").when({viewportInlineSize:{min:"extraSmall"}},"none none large-200 none"),children:o}):t(Y,{accessibilityLabel:n("tips.title"),children:o})}function Fn(){return t(ze,{children:t(Mn,{})})}function Rn({amount:{amount:e}}){return e>0}function Ln(e){return!!e?.some(Rn)}function Mn(){const{name:e,showTipPayments:n}=ye(),o=Pn(),{symbol:i,prefixed:r}=De(o),s=M(),{value:a=An}=Ge(),{state:c,invalidTipValue:h,negotiatedTip:y,proposedTip:u,onChange:T,onInput:P,onSubmit:d,clear:f}=En(o,a),S=y??u,l=S&&S.amount.amount>0,{loading:O,dirty:C,customTip:g,error:m}=c,[E,x]=L(n||l?[pe]:[]),b=r?{prefix:i}:{suffix:i},A="TipsInput",N=I(z=>{x(z),z.length===0&&f()},[f]),F=ee(),k=parseFloat(g.amount),v=isNaN(k)||k===0?void 0:k.toString();return t(Se,{name:"tipping_list",value:E,onChange:N,variant:"group",hideRadioButton:n,children:t(Pe,{id:pe,details:t($,{children:[Ln(a)&&t(vn,{tipOptions:a,onChange:T,proposedTip:u}),t($e,{onSubmit:d,children:[t(_e,{columns:xn(),children:[t(He,{controls:"stepper",error:!!m,id:A,name:"tipping_custom",label:s("tips.custom_label"),value:v,onInput:P,...b}),t(Ue,{variant:"primary",type:"submit",loading:O,disabled:!C,ref:F("tipping_custom_submit"),children:y&&y.amount.amount>0?s("tips.update_tip"):s("tips.add_tip")})]}),m&&t(We,{errorType:Ye.InputInvalid,message:m,errorValue:h,children:t(Je,{controlID:A,children:m})})]}),t(w,{children:s("tips.message")})]}),children:s("tips.description",{shop_name:e})})})}function xn(){return Te.default([]).when({viewportInlineSize:{min:"small"}},["fill","auto"])}function Bn({defaultEmail:e}){const{record:n}=oe(),{autoOptIn:o,isOptedIn:i}=ae(),[r,s]=L(e),a=re(void 0),c=I(()=>{r!==a.current&&(a.current=r,n({schemaId:"shopify_pay_user_optin_ui_interaction/3.2",payload:{action:"update_email_input",email:r,source:"order_created",trigger:o&&i?"auto":"manual"}}))},[o,i,r,n]);return{value:r,handleInput:h=>{s(h)},handleBlur:()=>{c()}}}function kn({value:e,onInput:n,onBlur:o}){const i=M(),{value:r,handleInput:s,handleBlur:a}=Bn({defaultEmail:e});return t(qe,{id:"email",name:"email",label:i("shop_pay_remember_me.email_label"),value:r,onInput:c=>{s(c),n?.(c)},onBlur:()=>{a(),o?.()},required:!1})}function Vn(){const e=K(void 0),n=K(void 0),o=M(),{wallets:i}=Ze(),r=ne(),[,s]=ie(),a=Ke(),c=r.shippingAddress.fields.firstName.value,h=Qe("shipping"),u=!Xe(()=>h??a,[h,a]).isRequired("firstName")&&!Q(c),T=I(l=>{if(!Q(l))return o("field_errors.address_first_name_blank")},[o]),P=I(l=>{if(!u||i.activeSession)return;if(!Q(l))return n.value=ce.InvalidOptInName,o("field_errors.address_first_name_blank");const C=e.peek()||"";s({optInFirstName:C})},[u,e,s,o,n,i]),d=K(void 0),f=i.activeSession?d:n,S=Ee(e,n,T);return je(e,f,P,ce.InvalidOptInName),u?t($,{children:t(Ne,{name:"shopFirstName",label:o("contact.first_name_label"),required:!0,...S})}):null}function wn({countryCode:e,validationError:n,value:o,onBlur:i=()=>{},onInput:r=()=>{}}){const s=M(),{record:a}=oe(),c=re(""),h=I(y=>{a({schemaId:"shopify_pay_user_optin_ui_interaction/3.2",payload:{action:"update_phone_input",phoneNumber:c.current,source:"order_created",trigger:y}})},[a]);return R(()=>{c.current!==o&&(c.current=o,h("auto"))},[h,o]),t(en,{error:n?t(w,{children:s("general.errors.buyer_identity.phone_number_does_not_match_expected_pattern")}):void 0,countryCode:e,label:s("shop_pay_remember_me.mobile_phone_number"),value:o,icon:"mobile",prefillCountryCode:!!e,onInputValueChange:y=>{r?.(y,e),c.current=y},onBlur:()=>{h("manual"),i?.()},onSelectedCountryChange:(y,u)=>{r?.(u,y),c.current=u}})}const V="RememberMeCheckbox";function he(){const{record:e}=oe(),n=ne(),{value:o}=be(),{autoOptIn:i,isOptedIn:r}=ae(),{storeOptOutPreference:s}=nn(),[a,c]=ie(),h=a||i&&a===void 0,u=tn(on)&&!!an(n.paymentLines.value,"APPLE_PAY"),T=n.phone.value,P=n.email.value,d=!T,{shopPayOptInPhone:f}=o||{},S=rn(),[l,O]=L(S),C=sn(),[g,m]=L([]),E=g.includes(V)||!!a,x=!d||u,{validate:b,error:A}=ln(l,E,x),N=cn(),F=un(l),k=re(F),[v,z]=L(a&&a.vaultPhone||f||F||""),[D,se]=L(a&&a?.vaultEmail||P||""),G=I((_,p)=>{e({schemaId:"shopify_pay_user_optin_ui_interaction/3.2",payload:{action:_,phoneNumber:p.phone,email:p.email,source:"order_created",trigger:i&&r?"auto":"manual"}})},[e,i,r]),J=I(_=>{b(_,l)||C("violationError",{error:{message:"The specified phone number does not match the expected pattern",code:"remember_me_phone_error",field:"phone",origin:"client",type:"inline-validation"},timestamp:new Date})},[l,b,C]),q=I((_,p)=>{if(!g.includes(V))return;O(p),z(_);const B=N(_,p);c({optInPhone:B??_,optInEmail:""})},[c,N,g]),Oe=I(_=>{se(_);const p=N(T,l);c({optInPhone:p??T,optInEmail:_})},[N,T,c,l]),Ce=I(_=>{m(_);const p=_.includes(V),B=a&&a.vaultPhone||f||F||v,Z=a&&a.vaultEmail||D;z(B),se(Z);const Ae=N(B,l);c(p?{optInPhone:Ae??B,optInEmail:d?"":Z}:!1),s(!p),p&&B&&b(B,l),G(p?"click_remember_me_box":"unclick_remember_me_box",{phone:B,email:Z})},[l,D,N,b,v,G,c,f,F,a,d,s]);return R(()=>{if(!g.includes(V)||!i)return;const _=!v||v==="",p=F||f||void 0;_&&p&&p!==k.current?(q(p,l),J(p),k.current=p):_||(k.current=p)},[g,v,l,F,f,a,q,i,G,J]),R(()=>{O(S)},[S]),R(()=>{m(h?[V]:[])},[h]),R(()=>{E&&v&&b(v,l)},[]),R(()=>{if(e({schemaId:"shopify_pay_user_optin_ui_impression/1.0",payload:{elementType:"remember_me_box",source:"order_created"}}),i&&r){const _=d?"":D;G("click_remember_me_box",{phone:v,email:D}),c({optInPhone:v,optInEmail:_})}},[i,e,G]),t(Se,{name:"RememberMe",value:g,variant:"group",onChange:Ce,children:t(Pe,{id:V,details:u?void 0:t($,{children:[t(Vn,{}),d?t(wn,{countryCode:l,validationError:A,value:v,onInput:q,onBlur:()=>J(v)}):t(kn,{value:D,onInput:Oe}),r?null:t(te,{children:t(dn,{field:d?"phone":"email",link:null})})]}),children:t(zn,{})})})}function zn(){const e=M(),n=mn(),{autoOptIn:o}=ae();return o?t(w,{children:e("shop_pay_remember_me.label_shop_account")}):n?t(w,{children:e("shop_pay_remember_me.payment_information_only_label")}):t(w,{children:e("shop_pay_remember_me.label")})}const Dn={"aria-label":"Shop",style:{fill:"var(--x-default-color-icon)",width:44,height:17}};function Gn(){const n=M()("shop_pay_remember_me.secure_label");return t(ue,{columns:["fill","auto"],children:[t(ue,{columns:["auto","fill"],spacing:"small400",blockAlignment:"center",children:[t(pn,{size:"small-200",type:"lock"}),t(W,{color:"subdued",type:"small",children:n})]}),t(Y,{children:t(hn,{...Dn})})]})}function Jn({variant:e}){const n=M(),o=bn(),[i,r]=ie();if(R(()=>{!o&&i&&r(!1)},[o,r,i]),!o)return null;if(e==="minimal")return t(te,{children:[t(U,{spacing:"small100"}),t(he,{})]});const s=t(fn,{sectionId:"rememberMe",children:t(he,{})});return e==="compact"?t(ve,{accessibilityLabel:n("shop_pay_remember_me.title"),children:t($,{children:[t(j,{level:2,children:n("shop_pay_remember_me.title")}),s]})}):t($,{spacing:"none",children:[t(j,{level:2,children:n("shop_pay_remember_me.title")}),t(U,{}),s,t(U,{spacing:"small100"}),t(Gn,{})]})}function qn({localizationExtension:e,index:n}){const o=gn(),{negotiate:i}=Ie(),[r,s]=L(),[a,c]=L(),h=Ee(e.fields.value,o),y=e.fields.title.value,{localizedFieldErrors:u}=_n(),T=`$.cart.localizedField.${e.peek().key}`,P=`$.localizationExtension[${n}]`,d=u.find(({target:l})=>l===T),f=l=>{const O=l.violations?.find(m=>{const{code:E,localizedMessage:x,nonLocalizedMessage:b,target:A}=m,N=x??b;if(E==="LOCALIZATION_EXTENSION_FIELD_ERROR"&&A===P)return N});if(!O)return;const{localizedMessage:C,nonLocalizedMessage:g}=O;return C??g};R(()=>{if(d){o.value=d.message;return}if(a){o.value=a;return}o.value=void 0},[o,d,a,r]);const S=()=>{h.onBlur(),s(void 0),c(void 0),i({fieldsToResolve:["localizationExtensions"],include:[],onComplete:l=>{c(f(l)),s("blur")}})};return yn(l=>{c(f(l)),s("submit")}),t(Ne,{...h,label:y,name:y,onBlur:S,value:h.value??void 0})}export{qn as L,Jn as R,Yn as T};