Build 576754stable
Module 606267
3,440 characters · in a47768fc7477158e.jsDependencies
Source Raw
function(e,t,n){n.d(t,{A:()=>S,Y0:()=>y,iB:()=>A});var l=n(64700),i=n(702841),r=n(364995),a=n(666646),s=n(6938),o=n(166403),u=n(459357),c=n(176095),d=n(11939),p=n(237299),m=n(652215),C=n(375708),h=n(743292);function E(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=f(o),C=f(u),h=null!=m&&0===m&&null!=C,E=0===m&&p,A=h?C:m,y=h?u?.total??null:o?.total,S=(0,i.bG)([c.A],()=>t&&null!=r?c.A.getBalance(r):null,[t,r]);return t&&null!=S?{walletCoversSubtotal:null!=A&&S.amount>=A,walletCoversTotal:null!=y&&S.amount>=y,walletId:r,isWalletBalanceLoaded:null!=A&&!E,isWalletCoverageLoading:E}:{walletCoversSubtotal:!1,walletCoversTotal:!1,walletId:r,isWalletBalanceLoaded:!1,isWalletCoverageLoading:!1}}function A(e){let{checkoutPaymentSources:t,paymentSourceId:n,location:l}=e,{enabled:i}=(0,u.c)({location:l}),{walletCoversTotal:r,walletId:a,isWalletBalanceLoaded:s}=E({giftCardsEnabled:i,checkoutPaymentSources:t});return s&&null!=n&&n===a&&!r}function f(e){return null==e?null:e.taxInclusive?e.total:e.total-e.tax}function y(e){let{checkoutPaymentSources:t,paymentSourceId:n,setPaymentSourceId:i,location:r,isReady:a=!0,subscriptionPaymentSourceId:o}=e,{enabled:c}=(0,u.c)({location:r}),A=(0,s.t4)(e=>e.pendingPaymentSourceId),{dropdownPaymentSources:f,giftCardWallet:y}=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]),[S,P]=l.useState(null),T=null!=y&&n===y.id,I=l.useMemo(()=>null!=S?S:(0,p.ut)({giftCardWallet:null,dropdownPaymentSources:f,subscriptionPaymentSourceId:o}),[f,o,S]),_=l.useMemo(()=>T?I:n??null,[I,T,n]),g=l.useMemo(()=>({checkoutPaymentSources:t,dropdownPaymentSources:f,subscriptionPaymentSourceId:o,giftCardWallet:y,isReady:a,pendingPaymentSourceId:A,paymentSourceId:n,giftCardsEnabled:c}),[t,f,o,y,a,A,n,c]);(0,p.ws)(i,g);let x=l.useCallback(e=>{i(null!=e?e.id:null)},[i]),v=l.useCallback(e=>{if(e&&null!=y){n!==y.id&&P(n??null),i(y.id);return}i(I)},[i,y,n,I]),{walletCoversSubtotal:N,walletCoversTotal:b,isWalletBalanceLoaded:R,isWalletCoverageLoading:M}=E({giftCardsEnabled:c,checkoutPaymentSources:t}),O=null!=o&&null!=y&&o===y.id;l.useEffect(()=>{!O&&R&&!N&&T&&i(I)},[O,R,N,T,i,I]);let j=l.useMemo(()=>null==y?null:{giftCardWallet:y,checked:T,onChange:v,loading:M,disabled:!M&&!N,disabledTooltip:M||N?void 0:C.intl.string(h.default.ccWIdu)},[y,T,v,N,M]);return{giftCardsEnabled:c,dropdownPaymentSources:f,dropdownPaymentSourceId:_,giftCardWallet:y,isGiftCardCreditsChecked:T,isSubscriptionPaidByWallet:O,handleGiftCardCreditsToggle:v,handleDropdownPaymentSourceChange:x,giftCardCheckboxProps:j,walletCoversSubtotal:N,walletCoversTotal:b,isWalletBalanceLoaded:R,isWalletCoverageLoading:M}}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}),p=l.useMemo(()=>c?(0,d.N)(s):null,[s,c]),m=null!=a&&null!=p&&a===p.id,{walletCoversTotal:C,isWalletBalanceLoaded:h}=E({giftCardsEnabled:c,checkoutPaymentSources:s});return l.useMemo(()=>{if(m&&h&&!C)return{type:"warning",key:"wallet-insufficient-balance",message:n}},[m,h,C,n])}}