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