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