Loading
function(e,t,n){n.d(t,{A:()=>y,Y0:()=>A,iB:()=>E});var l=n(582128),i=n(702841),r=n(364995),a=n(666646),s=n(316915),o=n(166403),u=n(459357),c=n(176095),d=n(11939),p=n(237299),m=n(652215),C=n(375708),h=n(776409);function f(e){let{giftCardsEnabled:t,checkoutPaymentSources:n}=e,r=l.useMemo(()=>(0,d.N)(n)?.id,[n]),o=(0,a.sw)(),u=(0,a.IK)(),p=(0,s.t4)(e=>{let{fetchRenewalInvoicePreviewRequest:t,renewalInvoicePreview:n,renewalInvoiceError:l}=e;return null!=t&&null==n&&null==l}),m=S(o),C=S(u),h=null!=m&&0===m&&null!=C,f=0===m&&p,E=h?C:m,A=h?u?.total??null:o?.total,y=(0,i.bG)([c.A],()=>t&&null!=r?c.A.getBalance(r):null,[t,r]);return t&&null!=y?{walletCoversSubtotal:null!=E&&y.amount>=E,walletCoversTotal:null!=A&&y.amount>=A,walletId:r,isWalletBalanceLoaded:null!=E&&!f,isWalletCoverageLoading:f}:{walletCoversSubtotal:!1,walletCoversTotal:!1,walletId:r,isWalletBalanceLoaded:!1,isWalletCoverageLoading:!1}}function E(e){let{checkoutPaymentSources:t,paymentSourceId:n,location:l}=e,{enabled:i}=(0,u.c)({location:l}),{walletCoversTotal:r,walletId:a,isWalletBalanceLoaded:s}=f({giftCardsEnabled:i,checkoutPaymentSources:t});return s&&null!=n&&n===a&&!r}function S(e){return null==e?null:e.taxInclusive?e.total:e.total-e.tax}function A(e){let{checkoutPaymentSources:t,paymentSourceId:n,setPaymentSourceId:i,location:r,isReady:a=!0,subscriptionPaymentSourceId:o}=e,{enabled:c}=(0,u.c)({location:r}),E=(0,s.t4)(e=>e.pendingPaymentSourceId),S=(0,s.t4)(e=>null!=e.initialPaymentSourceId),A=(0,s.t4)(e=>e.hasAddedPaymentSourceThisSession),{dropdownPaymentSources:y,giftCardWallet:P}=l.useMemo(()=>{let e=t.filter(e=>e.type!==m.hes.TDS_WALLET);return c?{dropdownPaymentSources:e,giftCardWallet:(0,d.N)(t)}:{dropdownPaymentSources:e,giftCardWallet:null}},[t,c]),[I,g]=l.useState(null),v=null!=P&&n===P.id,_=l.useMemo(()=>null!=I?I:(0,p.ut)({giftCardWallet:null,dropdownPaymentSources:y,subscriptionPaymentSourceId:o}),[y,o,I]),T=l.useMemo(()=>v?_:n??null,[_,v,n]),x=l.useMemo(()=>({checkoutPaymentSources:t,dropdownPaymentSources:y,subscriptionPaymentSourceId:o,giftCardWallet:P,isReady:a,pendingPaymentSourceId:E,paymentSourceId:n,giftCardsEnabled:c,hasInitialPaymentSourceSeed:S,hasAddedPaymentSourceThisSession:A}),[t,y,o,P,a,E,n,c,S,A]);(0,p.ws)(i,x);let N=l.useCallback(e=>{i(null!=e?e.id:null)},[i]),b=l.useCallback(e=>{if(e&&null!=P){n!==P.id&&g(n??null),i(P.id);return}i(_)},[i,P,n,_]),{walletCoversSubtotal:R,walletCoversTotal:j,isWalletBalanceLoaded:M,isWalletCoverageLoading:O}=f({giftCardsEnabled:c,checkoutPaymentSources:t}),L=null!=o&&null!=P&&o===P.id;l.useEffect(()=>{!L&&M&&!R&&v&&i(_)},[L,M,R,v,i,_]);let w=l.useMemo(()=>null==P?null:{giftCardWallet:P,checked:v,onChange:b,loading:O,disabled:!O&&!R,disabledTooltip:O||R?void 0:C.intl.string(h.default.ccWIdu)},[P,v,b,R,O]);return{giftCardsEnabled:c,dropdownPaymentSources:y,dropdownPaymentSourceId:T,giftCardWallet:P,isGiftCardCreditsChecked:v,isSubscriptionPaidByWallet:L,handleGiftCardCreditsToggle:b,handleDropdownPaymentSourceChange:N,giftCardCheckboxProps:w,walletCoversSubtotal:R,walletCoversTotal:j,isWalletBalanceLoaded:M,isWalletCoverageLoading:O}}function y(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}),p=l.useMemo(()=>c?(0,d.N)(s):null,[s,c]),m=null!=a&&null!=p&&a===p.id,{walletCoversTotal:C,isWalletBalanceLoaded:h}=f({giftCardsEnabled:c,checkoutPaymentSources:s});return l.useMemo(()=>{if(m&&h&&!C)return{type:"warning",key:"wallet-insufficient-balance",message:n}},[m,h,C,n])}}