Loading
function(l,t,e){e.d(t,{default:()=>T});var n=e(627968),a=e(64700),r=e(96337),i=e(997101),s=e(17928),u=e(189213),o=e(783878),d=e(292666),c=e(683071),h=e(753390),C=e(500380),g=e(423764),p=e(295405),f=e(174459),E=e(99696),m=e(667455),y=e(652215),A=e(818348),b=e(375708),_=e(133112);let I=r.A.filter(l=>i.M.EU_COUNTRIES.has(l.alpha2)).map(l=>({id:l.alpha2,value:l.alpha2,label:(0,g.Gw)(l.alpha2),leading:(0,n.jsx)("img",{alt:"",src:(0,C.t)(l.alpha2),style:{height:18}})}));function S(l){let{codeInput:t,isEU:e,postalCodeInput:a,selectedBillingCountry:r,redemptionError:i,codeError:s,billingError:u,onCodeInputChange:h,onPostalCodeChange:C,onBillingCountryChange:g}=l;return(0,n.jsxs)("div",{className:_.Cl,children:[null!=i&&(0,n.jsx)(c.w,{type:"critical",children:i}),(0,n.jsx)("span",{className:_.ZY,children:(0,n.jsx)(d.k,{label:b.intl.string(b.t["3Ujv7z"]),type:"text",value:t,onChange:h,placeholder:b.intl.string(b.t.wgFgAA),error:s,fullWidth:!0})}),e?(0,n.jsx)(o.Z,{selectionMode:"single",label:b.intl.string(b.t.eDdrAD),placeholder:b.intl.string(b.t.eDdrAD),value:r,onSelectionChange:g,options:I,errorMessage:u}):(0,n.jsx)(d.k,{label:b.intl.string(b.t.mfpJ9m),type:"text",value:a,onChange:C,placeholder:b.intl.string(b.t["9xLNmi"]),error:u,fullWidth:!0})]})}function T(l){let{transitionState:t,onClose:e,onComplete:r,initialCode:i="",withRedemptionSuccessModal:o=!1,source:d,loadId:c}=l,[I,T]=a.useState(i),[k,x]=a.useState(!1),[v,D]=a.useState(""),[R,M]=a.useState(null),[N,j]=a.useState(null),[U,w]=a.useState(null),[P,O]=a.useState(null),{isEU:F,displayCountry:L,savedPostalCode:G}=(0,m.A)(),z=(0,s.bG)([p.A],()=>p.A.hasFetchedPaymentSources);a.useEffect(()=>{z||(0,h.$o)()},[z]),a.useEffect(()=>{f.default.track(y.HAw.GIFT_CARD_REDEMPTION_START,{source:d,load_id:c})},[d,c]);let H=a.useRef(!1);a.useEffect(()=>{H.current||null==G||""!==v||(H.current=!0,D(G),O(null))},[G,v]);let W=b.intl.string(b.t.ToslbL),B=a.useMemo(()=>{if(null!=L)return{text:(0,g.Gw)(L),leadingIcon:()=>(0,n.jsx)("img",{alt:"",src:(0,C.t)(L),className:_.IM})}},[L]),Y=a.useCallback(l=>{T(l),w(null),j(null)},[]),Z=a.useCallback(async()=>{let l=I.trim(),t=F?null==R:""===v.trim(),n=!1;if(""===l&&(w(b.intl.string(b.t.NeFzT7)),n=!0),t&&(O(F?b.intl.string(b.t["+bm+zE"]):b.intl.string(b.t.LRlhb1)),n=!0),!n){x(!0),j(null);try{let t=await (0,E.Ng)(l,F?void 0:v.trim(),F?R??void 0:void 0);r?.(t),e(),f.default.track(y.HAw.GIFT_CARD_REDEMPTION_COMPLETED,{source:d,load_id:c}),o&&(0,E.cV)({amountRedeemed:t.amount,currencyCode:t.currency,loadId:c}),(0,h.$o)().then(l=>{let t=(l?.body??[]).find(l=>l.type===A.he.TDS_WALLET);null!=t&&(0,h.YP)(t.id)})}catch(l){j((0,E.tn)(l)),f.default.track(y.HAw.GIFT_CARD_REDEMPTION_FAILED,{source:d,load_id:c});return}finally{x(!1)}}},[I,F,R,v,r,e,o,d,c]),$=a.useCallback(l=>{D(l),O(null),j(null)},[]),J=a.useCallback(l=>{M(l),O(null),j(null)},[]);return(0,n.jsx)(u.Modal,{transitionState:t,onClose:e,title:W,subtitle:B,input:(0,n.jsx)(S,{codeInput:I,isEU:F,postalCodeInput:v,selectedBillingCountry:R,redemptionError:N,codeError:U,billingError:P,onCodeInputChange:Y,onPostalCodeChange:$,onBillingCountryChange:J}),actions:[{variant:"secondary",size:"md",text:b.intl.string(b.t["13/7kX"]),onClick:e},{variant:"primary",size:"md",text:b.intl.string(b.t.H2hHyf),loading:k,onClick:Z}]})}}