Loading
function(e,t,n){"use strict";n.d(t,{A:()=>C,Y0:()=>A,iB:()=>f});var l=n(64700),i=n(702841),s=n(364995),r=n(666646),a=n(166403),o=n(459357),u=n(176095),c=n(11939),d=n(652215),m=n(375708),h=n(776409);function p(e){let{giftCardsEnabled:t,checkoutPaymentSources:n}=e,s=l.useMemo(()=>(0,c.N)(n)?.id,[n]),a=(0,r.sw)(),o=(0,r.IK)(),d=g(a),m=g(o),h=null!=d&&0===d&&null!=m,p=h?m:d,f=h?o?.total??null:a?.total,E=(0,i.bG)([u.A],()=>t&&null!=s?u.A.getBalance(s):null,[t,s]);return t&&null!=E?{walletCoversSubtotal:null!=p&&E.amount>=p,walletCoversTotal:null!=f&&E.amount>=f,walletId:s,isWalletBalanceLoaded:null!=p}:{walletCoversSubtotal:!1,walletCoversTotal:!1,walletId:s,isWalletBalanceLoaded:!1}}function f(e){let{checkoutPaymentSources:t,paymentSourceId:n,location:l}=e,{enabled:i}=(0,o.c)({location:l}),{walletCoversTotal:s,walletId:r,isWalletBalanceLoaded:a}=p({giftCardsEnabled:i,checkoutPaymentSources:t});return a&&null!=n&&n===r&&!s}function g(e){return null==e?null:e.taxInclusive?e.total:e.total-e.tax}function E(e){let{giftCardWallet:t,dropdownPaymentSources:n,subscriptionPaymentSourceId:l,defaultPaymentSourceId:i}=e;if(null!=t&&(null==l||l===t.id))return t.id;if(null!=l){let e=n.find(e=>e.id===l);if(null!=e&&e.enabled)return l}if(null!=i){let e=n.find(e=>e.id===i);if(null!=e&&e.enabled)return i}return n.find(e=>e.enabled)?.id??null}function A(e){let{checkoutPaymentSources:t,paymentSourceId:n,setPaymentSourceId:i,location:s,isReady:r=!0,subscriptionPaymentSourceId:a}=e,{enabled:u}=(0,o.c)({location:s}),{dropdownPaymentSources:f,giftCardWallet:g}=l.useMemo(()=>{let e=t.filter(e=>e.type!==d.hes.TDS_WALLET);return u?{dropdownPaymentSources:e,giftCardWallet:(0,c.N)(t)}:{dropdownPaymentSources:e,giftCardWallet:null}},[t,u]),[A,C]=l.useState(null),x=null!=g&&n===g.id,I=l.useMemo(()=>null!=A?A:E({giftCardWallet:null,dropdownPaymentSources:f,subscriptionPaymentSourceId:a}),[f,a,A]),_=l.useMemo(()=>x?I:n??null,[I,x,n]),S=l.useRef(!1);l.useEffect(()=>{if(!r||0===t.length||S.current)return;S.current=!0;let e=E({giftCardWallet:g,dropdownPaymentSources:f,subscriptionPaymentSourceId:a,defaultPaymentSourceId:n});e!==n&&i(e)},[r,t,f,g,n,a,i]),l.useEffect(()=>{r&&0!==t.length&&null!=n&&S.current&&(t.some(e=>(function(e){let{paymentSource:t,paymentSourceId:n,giftCardsEnabled:l}=e;return(t.type!==d.hes.TDS_WALLET||!!l)&&null!=n&&t.id===n&&t.enabled})({paymentSource:e,paymentSourceId:n,giftCardsEnabled:u}))||i(E({giftCardWallet:g,dropdownPaymentSources:f,subscriptionPaymentSourceId:a,defaultPaymentSourceId:n})))},[r,u,t,f,g,n,a,i]);let y=l.useCallback(e=>{i(null!=e?e.id:null)},[i]),v=l.useCallback(e=>{if(e&&null!=g){n!==g.id&&C(n??null),i(g.id);return}i(I)},[i,g,n,I]),{walletCoversSubtotal:T,walletCoversTotal:N,isWalletBalanceLoaded:j}=p({giftCardsEnabled:u,checkoutPaymentSources:t}),b=null!=a&&null!=g&&a===g.id;l.useEffect(()=>{!b&&j&&!T&&x&&i(I)},[b,j,T,x,i,I]);let R=l.useMemo(()=>null==g?null:{giftCardWallet:g,checked:x,onChange:v,disabled:!T,disabledTooltip:T?void 0:m.intl.string(h.default.ccWIdu)},[g,x,v,T]);return{giftCardsEnabled:u,dropdownPaymentSources:f,dropdownPaymentSourceId:_,giftCardWallet:g,isGiftCardCreditsChecked:x,isSubscriptionPaidByWallet:b,handleGiftCardCreditsToggle:v,handleDropdownPaymentSourceChange:y,giftCardCheckboxProps:R,walletCoversSubtotal:T,walletCoversTotal:N,isWalletBalanceLoaded:j}}function C(e){let{location:t,message:n}=e,r=(0,i.bG)([a.A],()=>{let e=a.A.getPremiumTypeSubscription();return null!=e?e.paymentSourceId:null}),{checkoutPaymentSources:u}=(0,s.t)(),{enabled:d}=(0,o.c)({location:t}),m=l.useMemo(()=>d?(0,c.N)(u):null,[u,d]),h=null!=r&&null!=m&&r===m.id,{walletCoversTotal:f,isWalletBalanceLoaded:g}=p({giftCardsEnabled:d,checkoutPaymentSources:u});return l.useMemo(()=>{if(h&&g&&!f)return{type:"warning",key:"wallet-insufficient-balance",message:n}},[h,g,f,n])}}