import{dR as fe,a as n,V as Q,a9 as oe,b3 as tn,y as j,jG as Fe,bd as Le,dm as on,c as z,jH as rn,jI as an,jJ as Ve,gV as Pe,aR as be,jK as ye,jc as sn,jL as ln,i3 as cn,z as ie,ah as L,C as we,jw as un,jM as mn,q as O,ap as N,l as re,aB as ae,a8 as te,S as Be,av as De,jN as dn,jO as pn,jP as hn,bB as Ge,B as W,a6 as _n,jQ as fn,aE as je,c2 as bn,a1 as yn,ax as gn,fd as ze,jR as vn,ee as se,jS as le,ao as ce,hk as de,at as Pn,jT as ue,cm as In,jU as Tn,bP as En,v as pe,d as Ue,aq as Sn,ar as Ie,T as He,co as On,jV as Ye,bN as $e,iV as We,ix as qe,jW as Je,dp as Ke,jX as Xe,jY as Ze,jZ as Qe,j_ as Cn,n as Nn,aW as Rn,s as xn,E as An,w as kn,t as Mn,x as Fn,j$ as Ln,h8 as Vn,p as Te,r as Ee,ac as Se,k0 as Oe,cC as wn,gx as Bn,L as Ce,k1 as he,a_ as Ne,I as Dn,k2 as Gn,dK as jn,am as zn,k3 as Un,aO as Hn}from"./app.BTSv6d-3.js";import{R as Yn,u as $n}from"./RememberMeDescriptionText.DrLJIc9M.js";import{u as ge}from"./ShopPayOptInDisclaimer.e7mZhwXa.js";const ee="0";function Wn({label:e}){const t=fe();return n(Fe,{id:ee,ref:t("tipping_none"),children:n(Q,{inlineAlignment:"center",blockAlignment:"center",minBlockSize:"fill",children:n(oe,{children:tn()?e:n(j,{type:"strong",children:e})})})})}function qn({tipOption:e}){const{amount:t,percentage:a}=e,r=Le(),s=on().numberFormatter({style:"percent",minimumFractionDigits:0,maximumFractionDigits:2}),o=fe();return n(Fe,{id:t.amount.toString(),ref:o(`tipping_percent_${a}`),children:n(Q,{inlineAlignment:"center",blockAlignment:"center",minBlockSize:"fill",children:[n(oe,{children:s.format(a)}),n(oe,{type:"small",color:"subdued",children:r(t.amount,{currency:t.currencyCode,form:"short"})})]})})}function Jn({tipOptions:e,onChange:t,proposedTip:a}){const r=z();return n("div",{style:rn({[Pe.toggleButtonGroup.blockPadding]:Pe.spacing.small200}),children:n(an,{value:a?.amount?.amount?.toString()??ee,onChange:t,children:n(Ve,{columns:e.map(()=>"fill"),spacing:"none",children:e.map(i=>i.amount.amount>0?n(qn,{tipOption:i},i.amount.amount.toString()):n(Wn,{label:r("tips.no_tip_label")},"zero-amount"))})})})}function Kn(){const{currencyCode:e}=be(),{value:t}=ye(),{value:a}=sn();return t?.presentmentCurrency??a?.currencyCode??e}function Xn(e,t){switch(t.type){case"NEGOTIATION_START":return{...e,loading:!0};case"INPUT":return{...e,customTip:t.payload,dirty:nt(t.payload,e.negotiatedTip),error:void 0};case"NEGOTIATION_ERROR":return{...e,loading:!1,dirty:!1,...t.payload};case"NEGOTIATION_FINISH":return{...e,customTip:t.payload.customTip,loading:!1,dirty:!1,negotiatedTip:t.payload.negotiatedTip};case"CLEAR":return{...e,customTip:t.payload};default:return e}}function Zn(e,t){ln({currencyCode:e,tipOptions:t},et);const{value:a}=cn(),r=a?.[0],i=Le(),s=Re(t,r,i),{tipLines:o}=ie(),c=o.value[0],[p,C]=L(""),{negotiate:u}=we(),v=un(),[f,m]=mn(Xn,{loading:!1,dirty:!1,negotiatedTip:r,customTip:{amount:s,currencyCode:e}}),_=O(()=>{m({type:"CLEAR",payload:{amount:"",currencyCode:e}})},[e]),d=O(async g=>{const b=t?.find(({amount:P})=>P.amount===Number(g));if(!b)return;const E=xe(b.amount.amount,b.amount.currencyCode),M={amount:g,currencyCode:b.amount.currencyCode};o.value=E,await u({onComplete:P=>{const w=_e(P);m({type:"NEGOTIATION_FINISH",payload:{customTip:M,negotiatedTip:w}}),_()}})},[t,o,u,_]),l=O(async()=>{m({type:"NEGOTIATION_START"});const g=xe(f.customTip.amount,e);o.value=g,await u({onComplete:b=>{const E=Qn(b),P={amount:Re(t,_e(b),i),currencyCode:e},w=_e(b),I=i(Number(f.customTip.amount),{currency:P.currencyCode,form:"short"}),B=E?{type:"NEGOTIATION_ERROR",payload:{customTip:P,error:E}}:{type:"NEGOTIATION_FINISH",payload:{customTip:P,negotiatedTip:w}};E&&(C(I),v()),m(B)}})},[f.customTip.amount,e,o,u,t,i,v]),k=O(g=>{m({type:"INPUT",payload:{amount:g==="undefined"?ee:g,currencyCode:e}})},[e]),V=O(async()=>{o.value=[],await u({onComplete:_})},[_,u,o]);return N(()=>{s===""&&m({type:"CLEAR",payload:{amount:"",currencyCode:e}})},[s,e]),{state:f,negotiatedTip:r,invalidTipValue:p,proposedTip:c,onChange:d,onInput:k,onSubmit:l,clear:V}}function Qn(e){return e.status==="success"||e.status==="error"?e.violations.find(t=>t.__typename==="ConfirmChangeViolation")?.localizedMessage??null:null}function _e(e){if(e.status==="success"||e.status==="error")return e.negotiated.tipLines?.[0]}function Re(e,t,a){return!(t&&e?e.some(i=>i.amount.amount===t.amount.amount):!1)&&t?a(t.amount.amount,{currency:t.amount.currencyCode,form:"plain"}):""}function xe(e,t){return String(e)===ee?[]:[{amount:{amount:Number(e),currencyCode:t}}]}function et({currencyCode:e,tipOptions:t}){return`currency: ${e}, tipOptions: ${JSON.stringify(t)}`}function nt(e,t){return!t&&e.amount===ee?!1:parseFloat(e.amount)!==t?.amount.amount}const Ae="tipping_list_options",tt=[];function vt({renderInSection:e,hideHeading:t}){const a=z(),r=n(re,{children:[!t&&n(re,{children:[n(ae,{level:2,children:a("tips.title")}),n(te,{})]}),n(ot,{})]});return e?n(De,{accessibilityLabel:a("tips.title"),padding:Be.default("base large-200").when({viewportInlineSize:{min:"extraSmall"}},"none none large-200 none"),children:r}):n(Q,{accessibilityLabel:a("tips.title"),children:r})}function ot(){return n(dn,{children:n(it,{})})}function rt({amount:{amount:e}}){return e>0}function at(e){return!!e?.some(rt)}function it(){const{name:e,showTipPayments:t}=be(),a=Kn(),{symbol:r,prefixed:i}=pn(a),s=z(),{value:o=tt}=hn(),{state:c,invalidTipValue:p,negotiatedTip:C,proposedTip:u,onChange:v,onInput:f,onSubmit:m,clear:_}=Zn(a,o),d=C??u,l=d&&d.amount.amount>0,{loading:k,dirty:V,customTip:g,error:b}=c,[E,M]=L(t||l?[Ae]:[]),P=i?{prefix:r}:{suffix:r},w="TipsInput",I=O(U=>{M(U),U.length===0&&_()},[_]),B=fe(),R=parseFloat(g.amount),S=isNaN(R)||R===0?void 0:R.toString();return n(ze,{name:"tipping_list",value:E,onChange:I,variant:"group",hideRadioButton:t,children:n(Ge,{id:Ae,details:n(W,{children:[at(o)&&n(Jn,{tipOptions:o,onChange:v,proposedTip:u}),n(_n,{onSubmit:m,children:[n(Ve,{columns:st(),children:[n(fn,{controls:"stepper",error:!!b,id:w,name:"tipping_custom",label:s("tips.custom_label"),value:S,onInput:f,...P}),n(je,{variant:"primary",type:"submit",loading:k,disabled:!V,ref:B("tipping_custom_submit"),children:C&&C.amount.amount>0?s("tips.update_tip"):s("tips.add_tip")})]}),b&&n(bn,{errorType:yn.InputInvalid,message:b,errorValue:p,children:n(gn,{controlID:w,children:b})})]}),n(j,{children:s("tips.message")})]}),children:s("tips.description",{shop_name:e})})})}function st(){return Be.default([]).when({viewportInlineSize:{min:"small"}},["fill","auto"])}function lt({defaultEmail:e}){const{record:t}=se(),{autoOptIn:a,isOptedIn:r}=le(),[i,s]=L(e),o=ce(void 0),c=O(()=>{i!==o.current&&(o.current=i,t({schemaId:"shopify_pay_user_optin_ui_interaction/3.2",payload:{action:"update_email_input",email:i,source:"order_created",trigger:a&&r?"auto":"manual"}}))},[a,r,i,t]);return{value:i,handleInput:p=>{s(p)},handleBlur:()=>{c()}}}function en({value:e,onInput:t,onBlur:a,showOptionalLabel:r=!1}){const i=z(),{value:s,handleInput:o,handleBlur:c}=lt({defaultEmail:e});return n(vn,{id:"email",name:"email",label:i(r?"shop_pay_remember_me.email_label_optional":"shop_pay_remember_me.email_label"),value:s,onInput:p=>{o(p),t?.(p)},onBlur:()=>{c(),a?.()},required:!1})}function ct(){const e=de(void 0),t=de(void 0),a=z(),{wallets:r}=Pn(),i=ie(),[,s]=ue(),o=In(),c=i.shippingAddress.fields.firstName.value,p=Tn("shipping"),u=!En(()=>p??o,[p,o]).isRequired("firstName")&&!pe(c),v=O(l=>{if(!pe(l))return a("field_errors.address_first_name_blank")},[a]),f=O(l=>{if(!u||r.activeSession)return;if(!pe(l))return t.value=Ie.InvalidOptInName,a("field_errors.address_first_name_blank");const V=e.peek()||"";s({optInFirstName:V})},[u,e,s,a,t,r]),m=de(void 0),_=r.activeSession?m:t,d=Ue(e,t,v);return Sn(e,_,f,Ie.InvalidOptInName),u?n(W,{children:n(He,{name:"shopFirstName",label:a("contact.first_name_label"),required:!0,...d})}):null}function nn({countryCode:e,validationError:t,value:a,accessoryVariant:r="country",errorVariant:i="long",showOptionalLabel:s=!1,onBlur:o=()=>{},onInput:c=()=>{}}){const p=z(),{record:C}=se(),u=ce(""),v=O(d=>{C({schemaId:"shopify_pay_user_optin_ui_interaction/3.2",payload:{action:"update_phone_input",phoneNumber:u.current,source:"order_created",trigger:d}})},[C]);N(()=>{u.current!==a&&(u.current=a,v("auto"))},[v,a]);const f=r==="clear"?n(je,{variant:"plain",onClick:()=>{c?.("",e),u.current=""},textDecoration:"none",children:p("shop_pay_remember_me.clear")}):void 0,m=p(s?"shop_pay_remember_me.mobile_phone_optional":"shop_pay_remember_me.mobile_phone_number"),_=p(i==="short"?"shop_pay_remember_me.mobile_phone_invalid":"general.errors.buyer_identity.phone_number_does_not_match_expected_pattern");return n(On,{error:t?n(j,{children:_}):void 0,countryCode:e,label:m,value:a,icon:"mobile",prefillCountryCode:!!e,accessory:f,hideCountries:!!f,onInputValueChange:d=>{c?.(d,e),u.current=d},onBlur:()=>{v("manual"),o?.()},onSelectedCountryChange:(d,l)=>{c?.(l,d),u.current=l}})}const K="RememberMeCheckbox";function ut(){const{record:e}=se(),t=ie(),{value:a}=ye(),{autoOptIn:r,isOptedIn:i}=le(),{storeOptOutPreference:s}=Ye(),[o,c]=ue(),p=o||r&&o===void 0,u=$e(We)&&!!qe(t.paymentLines.value,"APPLE_PAY"),v=t.phone.value,f=t.email.value,m=!v,{shopPayOptInPhone:_}=a||{},d=Je(),[l,k]=L(d),V=Ke(),[g,b]=L([]),E=g.includes(K)||!!o,M=!m||u,{validate:P,error:w}=Xe(l,E,M),I=Ze(),B=Qe(l),R=ce(B),[S,U]=L(o&&o.vaultPhone||_||B||""),[F,T]=L(o&&o?.vaultEmail||f||""),$=O((y,h)=>{e({schemaId:"shopify_pay_user_optin_ui_interaction/3.2",payload:{action:y,phoneNumber:h.phone,email:h.email,source:"order_created",trigger:r&&i?"auto":"manual"}})},[e,r,i]),H=O(y=>{P(y,l)||V("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,P,V]),X=O((y,h)=>{if(!g.includes(K))return;k(h),U(y);const G=I(y,h);c({optInPhone:G??y,optInEmail:""})},[c,I,g]),D=O(y=>{T(y);const h=I(v,l);c({optInPhone:h??v,optInEmail:y})},[I,v,c,l]),Z=O(y=>{b(y);const h=y.includes(K),G=o&&o.vaultPhone||_||B||S,Y=o&&o.vaultEmail||F;U(G),T(Y);const q=I(G,l);c(h?{optInPhone:q??G,optInEmail:m?"":Y}:!1),s(!h),h&&G&&P(G,l),$(h?"click_remember_me_box":"unclick_remember_me_box",{phone:G,email:Y})},[l,F,I,P,S,$,c,_,B,o,m,s]);return N(()=>{if(!g.includes(K)||!r)return;const y=!S||S==="",h=B||_||void 0;y&&h&&h!==R.current?(X(h,l),H(h),R.current=h):y||(R.current=h)},[g,S,l,B,_,o,X,r,$,H]),N(()=>{k(d)},[d]),N(()=>{b(p?[K]:[])},[p]),N(()=>{E&&S&&P(S,l)},[]),N(()=>{if(e({schemaId:"shopify_pay_user_optin_ui_impression/1.0",payload:{elementType:"remember_me_box",source:"order_created"}}),r&&i){const y=m?"":F;$("click_remember_me_box",{phone:S,email:F}),c({optInPhone:S,optInEmail:y})}},[r,e,$]),n(ze,{name:"RememberMe",value:g,variant:"group",onChange:Z,children:n(Ge,{id:K,details:u?void 0:n(W,{children:[n(ct,{}),m?n(nn,{countryCode:l,validationError:w,value:S,onInput:X,onBlur:()=>H(S)}):n(en,{value:F,onInput:D}),i?null:n(re,{children:n(Yn,{field:m?"phone":"email",link:null})})]}),children:n(mt,{})})})}function mt(){const e=z(),t=Cn(),{autoOptIn:a}=le();return a?n(j,{children:e("shop_pay_remember_me.label_shop_account")}):t?n(j,{children:e("shop_pay_remember_me.payment_information_only_label")}):n(j,{children:e("shop_pay_remember_me.label")})}function dt(){const{geolocation:e}=Nn(),t=Rn(),a=xn(An),r=a?.find(o=>o.clientHandle===kn)?.variant,i=a?.find(o=>o.clientHandle===Mn)?.variant,s=!Fn(e.country.code);N(()=>{s&&i&&t.counter({name:"remember_me_experiment_issue",value:1,attributes:{type:"non_gdpr_experiment_assignment_to_user_inside_gdpr_protection",is_inside_gdpr_protection:s,country_code:e.country.code,gdpr_variant:r,non_gdpr_variant:i}}),r&&i&&t.counter({name:"remember_me_experiment_issue",value:1,attributes:{type:"conflict_between_experiments",is_inside_gdpr_protection:s,country_code:e.country.code,gdpr_variant:r,non_gdpr_variant:i}})},[s,i,r,t,e.country.code])}function pt(){const{record:e}=se(),t=ie(),{value:a}=ye(),r=ge();dt();const{autoOptIn:i}=le(),{storeOptOutPreference:s}=Ye(),[o,c]=ue(),C=$e(We)&&!!qe(t.paymentLines.value,"APPLE_PAY"),u=t.phone.value,v=t.email.value,f=!u,{shopPayOptInPhone:m}=a||{},_=Je(),[d,l]=L(_),k=Ke(),V=!f||C||!o,{validate:g,error:b}=Xe(d,!0,V),E=Ze(),M=z(),{name:P}=be(),[w,I]=Ln(Vn.ShopPayRememberMeOptInAuto),B=o?!!w:!1,R=Qe(d),S=ce(R),U=o&&o.vaultPhone;let F="";U?F=U:m?F=m:r.segment==="GDPR"?F=R||"":r.segment==="Non-GDPR"?F=i&&R||"":F=R||"";const[T,$]=L({value:F,isPrefilled:B||!U&&F.trim().length>0}),[H,X]=L(o&&o?.vaultEmail||v||""),[D,Z]=L({visible:r.segment==="GDPR"&&T.isPrefilled,checked:!!o}),y=D.visible,h=O(x=>{g(x,d)||k("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})},[d,g,k]);N(()=>{const x=T.value.trim().length===0,A=R||m||void 0,ne=A!==S.current&&!!A,ve=r.segment==="Non-GDPR"?i:!0;A&&ne&&f&&x&&ve&&(S.current=A,h(A),$({value:A,isPrefilled:!0}),I(!0),r.segment==="GDPR"&&Z(J=>J.visible?J:{...J,visible:!0}))},[I,f,r.segment,i,D.checked,T.value,R,m,h]),N(()=>{let x;if(y?x=D.checked:x=f?T.value.trim().length>0:H.trim().length>0,!x){o&&(c(!1),s(!0),I(!1));return}if(!f){const J=E(u,d)??u??"";(!o||o.vaultPhone!==J||o.vaultEmail!==H)&&(c({optInPhone:J,optInEmail:H}),s(!1),I(!1));return}const ne=E(T.value,d)??T.value;(!o||o.vaultPhone!==ne||(o.vaultEmail??"")!=="")&&(c({optInPhone:ne,optInEmail:""}),s(!1),I(T.isPrefilled))},[y,D.checked,f,T.value,T.isPrefilled,H,d,o,E,u,c,s,I,r.segment]),N(()=>{l(_)},[_]),N(()=>{D.visible&&e({schemaId:"shopify_pay_user_optin_ui_impression/1.0",payload:{elementType:"remember_me_experimental_checkbox",source:"order_created"}})},[D.visible,e]),N(()=>{e({schemaId:"shopify_pay_user_optin_ui_impression/1.0",payload:{elementType:"remember_me_box",source:"order_created"}}),T.value&&h(T.value)},[]);let G="country";r.segment==="Non-GDPR"&&T.isPrefilled&&(G="clear");let Y,q;r.segment==="GDPR"?y?(Y=!1,q="consent_with_checkbox_html_optional_no_brackets"):(Y=!0,q="consent_with_checkbox_html"):(Y=!0,q="consent_with_phone_html");const me=f?n(nn,{countryCode:d,validationError:b,value:T.value,accessoryVariant:G,errorVariant:"short",showOptionalLabel:Y,onInput:(x,A)=>{$({value:x,isPrefilled:!1}),l(A)},onBlur:()=>h(T.value)}):n(en,{value:H,onInput:X,showOptionalLabel:Y});return r.variant===Te.Treatment1||r.variant===Ee.Treatment1?n(W,{children:[n(Se,{children:D.visible?n(Oe,{id:"remember_me_checkbox",checked:D.checked,onChange:x=>Z(A=>({...A,checked:x})),label:M("shop_pay_remember_me.label")}):n(j,{children:M("shop_pay_remember_me.label")})}),me,n(ke,{variant:q})]}):r.variant===Te.Treatment2||r.variant===Ee.Treatment2?n(Q,{border:"base",cornerRadius:"base",padding:"base",children:n(W,{spacing:"base",children:[n(W,{spacing:"small100",children:[n(wn,{direction:"inline",justifyContent:"space-between",children:[n(Se,{spacing:"base",blockAlignment:"center",children:[D.visible&&n(Oe,{id:"remember_me_checkbox",checked:D.checked,onChange:x=>Z(A=>({...A,checked:x}))}),n("label",{htmlFor:"remember_me_checkbox",children:n(ae,{level:3,children:M("shop_pay_remember_me.save_once_shop_everywhere")})})]}),n(Bn,{color:"branded",size:"medium"})]}),n(j,{color:"subdued",children:M("shop_pay_remember_me.value_prop_shop_name",{shop_name:P})})]}),me,n(ke,{variant:q})]})}):null}function ke({variant:e}){const t=z(),a={terms_href:n(Ce,{target:"_blank",href:"https://www.shopify.com/legal/privacy/app-users",tone:"monochrome",children:t("shop_pay_remember_me.terms")}),privacy_href:n(Ce,{target:"_blank",href:"https://shop.app/terms-of-service",tone:"monochrome",children:t("shop_pay_remember_me.privacy_policy")})};return e==="consent_with_phone_html"?n(j,{color:"subdued",type:"small",children:n(he,{children:t("shop_pay_remember_me.consent_with_phone_html",a)})}):e==="consent_with_checkbox_html"?n(j,{color:"subdued",type:"small",children:n(he,{children:t("shop_pay_remember_me.consent_with_checkbox_html",a)})}):n(j,{color:"subdued",type:"small",children:n(he,{children:t("shop_pay_remember_me.consent_with_checkbox_html_optional_no_brackets",a)})})}function Me(){return ge().isTreatment?n(pt,{}):n(ut,{})}const ht={"aria-label":"Shop",style:{fill:"var(--x-default-color-icon)",width:44,height:17}};function _t(){const t=z()("shop_pay_remember_me.secure_label");return n(Ne,{columns:["fill","auto"],children:[n(Ne,{columns:["auto","fill"],spacing:"small400",blockAlignment:"center",children:[n(Dn,{size:"small-200",type:"lock"}),n(oe,{color:"subdued",type:"small",children:t})]}),n(Q,{children:n(Gn,{...ht})})]})}function Pt({variant:e}){const t=z(),a=$n(),[r,i]=ue(),s=ge();if(N(()=>{!a&&r&&i(!1)},[a,i,r]),!a)return null;if(e==="minimal")return n(re,{children:[n(te,{spacing:"small100"}),n(Me,{})]});const o=n(jn,{sectionId:"rememberMe",children:n(Me,{})}),c=s.isTreatment?t("shop_pay_remember_me.label"):t("shop_pay_remember_me.title");return e==="compact"?n(De,{accessibilityLabel:c,children:n(W,{children:[n(ae,{level:2,children:c}),o]})}):n(W,{spacing:"none",children:[!s.isTreatment&&n(ae,{level:2,children:c}),n(te,{}),o,n(te,{spacing:"small100"}),!s.isTreatment&&n(_t,{})]})}function It({localizationExtension:e,index:t}){const a=zn(),{negotiate:r}=we(),[i,s]=L(),[o,c]=L(),p=Ue(e.fields.value,a),C=e.fields.title.value,{localizedFieldErrors:u}=Un(),v=`$.cart.localizedField.${e.peek().key}`,f=`$.localizationExtension[${t}]`,m=u.find(({target:l})=>l===v),_=l=>{const k=l.violations?.find(b=>{const{code:E,localizedMessage:M,nonLocalizedMessage:P,target:w}=b,I=M??P;if(E==="LOCALIZATION_EXTENSION_FIELD_ERROR"&&w===f)return I});if(!k)return;const{localizedMessage:V,nonLocalizedMessage:g}=k;return V??g};N(()=>{if(m){a.value=m.message;return}if(o){a.value=o;return}a.value=void 0},[a,m,o,i]);const d=()=>{p.onBlur(),s(void 0),c(void 0),r({fieldsToResolve:["localizationExtensions"],include:[],onComplete:l=>{c(_(l)),s("blur")}})};return Hn(l=>{c(_(l)),s("submit")}),n(He,{...p,label:C,name:C,onBlur:d,value:p.value??void 0})}export{It as L,Pt as R,vt as T};