1import{u as n,T as t,s as e,t as a,P as i,x as o,Q as r,m as s,S as u,R as c}from"./2c1ab0fe.GMbxnz74.js";import{ae as l,B as p,P as m,o as d,i as y,b_ as g,H as f,b as T,a3 as h,b$ as b,c as v,_ as C,by as I,F as _,c0 as N,l as O}from"./164ad2e3.B4L1MRYB.js";import{b as S,a as A,C as E}from"./efa0389a.ZcaEqvMP.js";import{N as j}from"./33d2e4fc.99-2I_X4.js";import{S as R,T as F,cf as k,W as L}from"./4c290a1e.DMQ9xOwP.js";import{r as G}from"./dfca5da5.BJQx_CCE.js";import"./9f047e05.DwjCPgK0.js";import"./app.DGSHpWaV.js";import"./0a7dffce.BcNpdEJk.js";import"./5fda1420.BLaDhoyL.js";import"./60a453ce.Cg9T1Gj2.js";import"./21cc90a2.Ccyorzx_.js";import"./bb728e1c.CHt2JlPY.js";const P="0",w="tipping_list_options";function B({label:t}){const e=l(),a=R().checkout.configuration.layout.isOnePage.value;return n(S,{id:P,value:P,ref:e("tipping_none"),children:n(p,{inlineAlignment:"center",blockAlignment:"center",minBlockSize:"100%",children:n(m,{children:a?t:n(d,{type:"strong",children:t})})})})}function H({tipOption:t}){const{amount:e,percentage:a}=t,{i18n:i}=R(),o=i.numberFormatter({style:"percent",minimumFractionDigits:0,maximumFractionDigits:2}),r=l();return n(S,{id:e.amount.toString(),value:e.amount.toString(),ref:r(`tipping_percent_${a}`),children:n(p,{inlineAlignment:"center",blockAlignment:"center",minBlockSize:"100%",children:[n(m,{children:o.format(a)}),n(m,{type:"small",color:"subdued",children:i.formatCurrency(e.amount,{currency:e.currencyCode,form:"short"})})]})})}function x({tipOptions:a,onChange:i,proposedTip:o}){const{i18n:r}=R(),s=t(()=>[o?.amount?.amount?.toString()??P],[o?.amount?.amount]),u=e(([n])=>{i(n)},[i]);return n(E,{padding:"small200",children:n(A,{name:"tipping_options",values:s,onChange:u,variant:"inline",children:a.map(t=>t.amount.amount>0?n(H,{tipOption:t},t.amount.amount.toString()):n(B,{label:r.translate("tips.no_tip_label")},"zero-amount"))})})}function z(n,t){switch(t.type){case"NEGOTIATION_START":return{...n,loading:!0};case"INPUT":return{...n,customTip:t.payload,dirty:(e=t.payload,a=n.negotiatedTip,!(!a&&e.amount===P)&&parseFloat(e.amount)!==a?.amount.amount),error:void 0};case"NEGOTIATION_ERROR":return{...n,loading:!1,dirty:!1,...t.payload};case"NEGOTIATION_FINISH":return{...n,customTip:t.payload.customTip,loading:!1,dirty:!1,negotiatedTip:t.payload.negotiatedTip};case"CLEAR":return{...n,customTip:t.payload};default:return n}var e,a}function V(n){if("success"===n.status||"error"===n.status)return n.negotiated.tipLines?.[0]}function $(n,t,e){return t&&n&&n.some(n=>n.amount.amount===t.amount.amount)||!t?"":e.formatCurrency(t.amount.amount,{currency:t.amount.currencyCode,form:"plain"})}function D(n,t){return String(n)===P?[]:[{amount:{amount:Number(n),currencyCode:t}}]}function M({currencyCode:n,tipOptions:t}){return`currency: ${n}, tipOptions: ${JSON.stringify(t)}`}const Q=[];function U({renderInSection:t,hideHeading:e,headingLevel:a=2}){const{i18n:i}=R(),o=n(u,{children:[!e&&n(u,{children:[n(f,{level:a,children:i.translate("tips.title")}),n(T,{blockSize:"base"})]}),n(W,{})]});return G(t)?n(h,{accessibilityLabel:i.translate("tips.title"),children:n(p,{paddingBlockEnd:"base",children:o})}):n(p,{paddingBlockEnd:"base",children:o})}function W(){return n(b,{children:n(X,{})})}function J({amount:{amount:n}}){return n>0}function X(){const{i18n:t,shop:{name:u,showTipPayments:p},shopPay:f}=R(),T="SHOPIFY_INSTALLMENTS"===f.session.paymentMethodOption.value?.name,h=function(){const{shop:n}=R(),t=F().buyerIdentity,e=k();return a(()=>t.value?.presentmentCurrency??e.value?.currencyCode??n.currencyCode)}(),{symbol:b,prefixed:E}=c(h.value,t),{value:G=Q}=F().tipOptions,{state:B,invalidTipValue:H,negotiatedTip:U,proposedTip:W,onChange:X,onInput:Y,onSubmit:Z,clear:q}=function(n,t){i({currencyCode:n,tipOptions:t},M);const{value:a}=F().tipLines,u=a?.[0],{i18n:c}=R(),l=$(t,u,c),{tipLines:p}=L(),m=p.value[0],[d,f]=o(""),{negotiate:T}=y(),h=g(),[b,v]=r(z,{loading:!1,dirty:!1,negotiatedTip:u,customTip:{amount:l,currencyCode:n}}),C=e(()=>{v({type:"CLEAR",payload:{amount:"",currencyCode:n}})},[n]),I=e(async n=>{if(!n)return;const e=t?.find(({amount:t})=>t.amount===Number(n));if(!e)return;const a=D(e.amount.amount,e.amount.currencyCode),i={amount:n,currencyCode:e.amount.currencyCode};p.value=a,await T({onComplete:n=>{const t=V(n);v({type:"NEGOTIATION_FINISH",payload:{customTip:i,negotiatedTip:t}}),C()}})},[t,p,T,C]),_=e(async()=>{v({type:"NEGOTIATION_START"});const e=D(b.customTip.amount,n);p.value=e,await T({onComplete:e=>{const a=function(n){return"success"===n.status||"error"===n.status?n.violations.find(n=>"ConfirmChangeViolation"===n.__typename)?.localizedMessage??null:null}(e),i={amount:$(t,V(e),c),currencyCode:n},o=V(e),r=c.formatCurrency(Number(b.customTip.amount),{currency:i.currencyCode,form:"short"}),s=a?{type:"NEGOTIATION_ERROR",payload:{customTip:i,error:a}}:{type:"NEGOTIATION_FINISH",payload:{customTip:i,negotiatedTip:o}};
1a&&(f(r),h()),v(s)}})},[b.customTip.amount,n,p,T,t,c,h]),N=e(t=>{v({type:"INPUT",payload:{amount:"undefined"===t?P:t,currencyCode:n}})},[n]),O=e(async()=>{p.value=[],await T({onComplete:t=>{v({type:"NEGOTIATION_FINISH",payload:{customTip:{amount:"",currencyCode:n},negotiatedTip:V(t)}})}})},[n,T,p]);return s(()=>{""===l&&v({type:"CLEAR",payload:{amount:"",currencyCode:n}})},[l,n]),{state:b,negotiatedTip:u,invalidTipValue:d,proposedTip:m,onChange:I,onInput:N,onSubmit:_,clear:O}}(h.value,G),K=l(),nn=U??W,tn=nn&&nn.amount.amount>0,{loading:en,dirty:an,customTip:on,error:rn}=B,[sn,un]=o(p||tn?[w]:[]),cn=E?{prefix:b}:{suffix:b},ln="TipsInput",pn=e(n=>{un(n),0===n.length&&q()},[q]);if(s(()=>{T&&tn&&q()},[T,tn,q]),T)return n(A,{name:"tipping_list",values:[],variant:"block",children:n(S,{value:w,disabled:!0,tertiaryContent:n(d,{color:"subdued",type:"small",children:t.translate("tips.not_available_with_spi")}),children:t.translate("tips.description",{shop_name:u})})});const mn=parseFloat(on.amount),dn=isNaN(mn)||0===mn?void 0:mn.toString();return n(A,{name:"tipping_list",values:sn,multiple:!0,onChange:pn,variant:"block",children:n(S,{value:w,selectedContent:n(v,{gap:"small-100",children:[(yn=G,Boolean(yn?.some(J))&&n(x,{tipOptions:G,onChange:X,proposedTip:W})),n(C,{onSubmit:Z,children:n("div",{className:"QEtOP",children:[n("div",{className:"_0ZWye",children:n(j,{controls:"stepper",error:Boolean(rn),id:ln,name:"tipping_custom",label:t.translate("tips.custom_label"),value:dn,onInput:Y,...cn})}),rn&&n("div",{className:"_7Twg0",children:n(I,{errorType:_.InputInvalid,message:rn,errorValue:H,children:n(N,{controlID:ln,children:rn})})}),n("div",{className:"RdIOQ",children:n(O,{variant:"primary",type:"submit",inlineSize:"fill",loading:en,disabled:!an,ref:K("tipping_custom_submit"),children:U&&U.amount.amount>0?t.translate("tips.update_tip"):t.translate("tips.add_tip")})})]})}),n(m,{children:t.translate("tips.message")})]}),children:t.translate("tips.description",{shop_name:u})})});var yn}export{Q as EMPTY_TIP_OPTIONS,U as default};
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.