1import{u as n,T as t,q as e,k as a,$ as i,z as o,a0 as r,h as s,S as c,a1 as u}from"./2c1ab0fe.B2yRRyAW.js";import{a as l,b as p,f as d,j as m,v as y,ch as g,H as f,d as h,i as T,ci as b,S as v,ai as C,bU as I,aa as N,bG as _,B as O}from"./164ad2e3.-hfWY9cN.js";import{b as S,a as A,C as E}from"./efa0389a.DgBvBH2e.js";import{N as j}from"./33d2e4fc.Cd6g6AsB.js";import{c as k,ad as F}from"./4b4bc88f.JFrEI7LU.js";import{r as R}from"./dae24aab.xiAL8T3Q.js";import"./d0bb51ec.CiN57OqX.js";import"./app.C_W8kcQ4.js";import"./f67abd2c.Boj0gJpa.js";import"./60a453ce.aSs2kW8G.js";import"./e12db40c.ZpKYxNRe.js";import"./9dba8418.BqWu-Ch9.js";import"./22345fd4.CQJ0n-1P.js";const L="0",G="tipping_list_options";function z({label:t}){const e=l(),a=k().checkout.configuration.layout.isOnePage.value;return n(S,{id:L,value:L,ref:e("tipping_none"),children:n(p,{inlineAlignment:"center",blockAlignment:"center",minBlockSize:"100%",children:n(d,{children:a?t:n(m,{type:"strong",children:t})})})})}function B({tipOption:t}){const{amount:e,percentage:a}=t,{i18n:i}=k(),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(d,{children:o.format(a)}),n(d,{type:"small",color:"subdued",children:i.formatCurrency(e.amount,{currency:e.currencyCode,form:"short"})})]})})}function H({tipOptions:a,onChange:i,proposedTip:o}){const{i18n:r}=k(),s=t(()=>[o?.amount?.amount?.toString()??L],[o?.amount?.amount]),c=e(([n])=>{i(n)},[i]);return n(E,{padding:"small200",children:n(A,{name:"tipping_options",values:s,onChange:c,variant:"inline",children:a.map(t=>t.amount.amount>0?n(B,{tipOption:t},t.amount.amount.toString()):n(z,{label:r.translate("tips.no_tip_label")},"zero-amount"))})})}function w(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===L)&&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 x(n){if("success"===n.status||"error"===n.status)return n.negotiated.tipLines?.[0]}function P(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 U(n,t){return String(n)===L?[]:[{amount:{amount:Number(n),currencyCode:t}}]}function V({currencyCode:n,tipOptions:t}){return`currency: ${n}, tipOptions: ${JSON.stringify(t)}`}const $=[];function D({renderInSection:t,hideHeading:e,headingLevel:a=2}){const{i18n:i}=k(),o=n(c,{children:[!e&&n(c,{children:[n(f,{level:a,children:i.translate("tips.title")}),n(h,{blockSize:"base"})]}),n(J,{})]});return R(t)?n(T,{accessibilityLabel:i.translate("tips.title"),children:n(p,{paddingBlockEnd:"base",children:o})}):n(p,{paddingBlockEnd:"base",children:o})}function J(){return n(b,{children:n(Y,{})})}function M({amount:{amount:n}}){return n>0}function Y(){const{i18n:t,shop:{name:c,showTipPayments:p},shopPay:f,checkout:{negotiator:h}}=k(),T="SHOPIFY_INSTALLMENTS"===f.session.paymentMethodOption.value?.name,b=function(){const{shop:n,checkout:{negotiator:t}}=k(),e=t.current.fields.buyerIdentity,i=F();return a(()=>e.value?.presentmentCurrency??i.value?.currencyCode??n.currencyCode)}(),{symbol:E,prefixed:R}=u(b.value,t),{value:z=$}=h.current.fields.tipOptions,{state:B,invalidTipValue:D,negotiatedTip:J,proposedTip:Y,onChange:Q,onInput:Z,onSubmit:q,clear:K}=function(n,t){i({currencyCode:n,tipOptions:t},V);const{i18n:a,checkout:{negotiator:c}}=k(),{value:u}=c.current.fields.tipLines,l=u?.[0],p=P(t,l,a),{tipLines:d}=c.parts,m=d.value[0],[f,h]=o(""),{negotiate:T}=y(),b=g(),[v,C]=r(w,{loading:!1,dirty:!1,negotiatedTip:l,customTip:{amount:p,currencyCode:n}}),I=e(()=>{C({type:"CLEAR",payload:{amount:"",currencyCode:n}})},[n]),N=e(async n=>{if(!n)return;const e=t?.find(({amount:t})=>t.amount===Number(n));if(!e)return;const a=U(e.amount.amount,e.amount.currencyCode),i={amount:n,currencyCode:e.amount.currencyCode};d.value=a,await T({onComplete:n=>{const t=x(n);C({type:"NEGOTIATION_FINISH",payload:{customTip:i,negotiatedTip:t}}),I()}})},[t,d,T,I]),_=e(async()=>{C({type:"NEGOTIATION_START"});const e=U(v.customTip.amount,n);d.value=e,await T({onComplete:e=>{const i=function(n){return"success"===n.status||"error"===n.status?n.violations.find(n=>"ConfirmChangeViolation"===n.__typename)?.localizedMessage??null:null}(e),o={amount:P(t,x(e),a),currencyCode:n},r=x(e),s=a.formatCurrency(Number(v.customTip.amount),{currency:o.currencyCode,form:"short"}),c=i?{type:"NEGOTIATION_ERROR",payload:{customTip:o,error:i}}:{type:"NEGOTIATION_FINISH",payload:{customTip:o,negotiatedTip:r}};i&&(h(s),b()),C(c)}})},[v.customTip.amount,n,d,T,t,a,b]),O=e(t=>{C({type:"INPUT",payload:{amount:"undefined"===t?L:t,currencyCode:n}})},[n]),S=e(async()=>{d.value=[],await T({onComplete:t=>{C({type:"NEGOTIATION_FINISH",payload:{customTip:{amount:"",currencyCode:n},negotiatedTip:x(t)}})}})},[n,T,d]);return s(()=>{""===p&&C({type:"CLEAR",payload:{amount:"",currencyCode:n}})},[p,n]),{state:v,negotiatedTip:l,invalidTipValue:f,proposedTip:m,onChange:N,onInput:O,onSubmit:_,clear:S}}(b.value,z),W=l(),X=J??Y,nn=X&&X.amount.amount>0,{loading:tn,dirty:en,customTip:an,error:on}=B,[rn,sn]=o(p||nn?[G]:[]),cn=R?{prefix:E}:{suffix:E},un="TipsInput",ln=e(n=>{sn(n),0===n.length&&K()},[K]);if(s(()=>{T&&nn&&K()},[T,nn,K]),T)return n(A,{name:"tipping_list",values:[],variant:"block",children:n(S,{value:G,disabled:!0,tertiaryContent:n(m,{c
1olor:"subdued",type:"small",children:t.translate("tips.not_available_with_spi")}),children:t.translate("tips.description",{shop_name:c})})});const pn=parseFloat(an.amount),dn=isNaN(pn)||0===pn?void 0:pn.toString();return n(A,{name:"tipping_list",values:rn,multiple:!0,onChange:ln,variant:"block",children:n(S,{value:G,selectedContent:n(v,{gap:"small-100",children:[(mn=z,Boolean(mn?.some(M))&&n(H,{tipOptions:z,onChange:Q,proposedTip:Y})),n(C,{onSubmit:q,children:n("div",{className:"YUcQZ",children:[n("div",{className:"AJiNi",children:n(j,{controls:"stepper",error:Boolean(on),id:un,name:"tipping_custom",label:t.translate("tips.custom_label"),value:dn,onInput:Z,...cn})}),on&&n("div",{className:"FfxlI",children:n(I,{errorType:N.InputInvalid,message:on,errorValue:D,children:n(_,{controlID:un,children:on})})}),n("div",{className:"bzJb9",children:n(O,{variant:"primary",type:"submit",inlineSize:"fill",loading:tn,disabled:!en,ref:W("tipping_custom_submit"),children:J&&J.amount.amount>0?t.translate("tips.update_tip"):t.translate("tips.add_tip")})})]})}),n(d,{children:t.translate("tips.message")})]}),children:t.translate("tips.description",{shop_name:c})})});var mn}export{$ as EMPTY_TIP_OPTIONS,D 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.