import React, { memo } from '../../../../lib/teact/teact'; import { getActions } from '../../../../global'; import type { ApiStarsSubscription, } from '../../../../api/types'; import type { GlobalState } from '../../../../global/types'; import { getPeerTitle } from '../../../../global/helpers'; import { selectPeer } from '../../../../global/selectors'; import { formatDateToString } from '../../../../util/dates/dateFormat'; import { formatInteger } from '../../../../util/textFormat'; import renderText from '../../../common/helpers/renderText'; import useSelector from '../../../../hooks/data/useSelector'; import useLastCallback from '../../../../hooks/useLastCallback'; import useOldLang from '../../../../hooks/useOldLang'; import Avatar from '../../../common/Avatar'; import StarIcon from '../../../common/icons/StarIcon'; import styles from './StarsSubscriptionItem.module.scss'; type OwnProps = { subscription: ApiStarsSubscription; }; function selectProvidedPeer(peerId: string) { return (global: GlobalState) => ( selectPeer(global, peerId) ); } const StarsSubscriptionItem = ({ subscription }: OwnProps) => { const { openStarsSubscriptionModal } = getActions(); const { peerId, pricing, until, isCancelled, title, photo, } = subscription; const lang = useOldLang(); const peer = useSelector(selectProvidedPeer(peerId))!; const handleClick = useLastCallback(() => { openStarsSubscriptionModal({ subscription }); }); if (!peer) { return undefined; } const hasExpired = until < Date.now() / 1000; const formattedDate = formatDateToString(until * 1000, lang.code, true, 'long'); return (

{renderText(getPeerTitle(lang, peer) || '')}

{title && (

{photo && } {renderText(title)}

)}

{lang( hasExpired ? 'StarsSubscriptionExpired' : isCancelled ? 'StarsSubscriptionExpires' : 'StarsSubscriptionRenews', formattedDate, )}

{(isCancelled || hasExpired) ? (
{lang(hasExpired ? 'StarsSubscriptionStatusExpired' : 'StarsSubscriptionStatusCancelled')}
) : ( <>
{formatInteger(pricing.amount)}
{lang('StarsParticipantSubscriptionPerMonth')}
)}
); }; export default memo(StarsSubscriptionItem);