/* eslint-disable react/no-danger */ /* eslint-disable jsx-a11y/click-events-have-key-events */ import { Divider } from 'antd'; import { FC } from 'react'; import formatDistanceToNow from 'date-fns/formatDistanceToNow'; import dynamic from 'next/dynamic'; import classNames from 'classnames'; import { useTranslation } from 'next-export-i18n'; import styles from './OfflineBanner.module.scss'; // Lazy loaded components const ClockCircleOutlined = dynamic(() => import('@ant-design/icons/ClockCircleOutlined'), { ssr: false, }); export type OfflineBannerProps = { streamName: string; customText?: string; lastLive?: Date; notificationsEnabled: boolean; fediverseAccount?: string; showsHeader?: boolean; onNotifyClick?: () => void; onFollowClick?: () => void; className?: string; }; export const OfflineBanner: FC = ({ streamName, customText, lastLive, notificationsEnabled, fediverseAccount, showsHeader = true, onNotifyClick, onFollowClick, className, }) => { const { t } = useTranslation(); let text; if (customText) { text = customText; } else if (!customText && notificationsEnabled && fediverseAccount) { text = ( {t('This stream is offline. You can')}{' '} be notified {' '} the next time {streamName} goes live or{' '} follow {' '} {fediverseAccount} on the Fediverse. ); } else if (!customText && notificationsEnabled) { text = ( {t('This stream is offline')}.{' '} Be notified {' '} {t('the next time goes live', { streamer: streamName })}. ); } else if (!customText && fediverseAccount) { text = ( {t('This stream is offline.')}{' '} {t('Follow')} {' '} {t('on the Fediverse to see the next time goes live', { fediverseAccount, streamer: streamName, })} . ); } else { text = `This stream is offline. Check back soon!`; } return (
{showsHeader && ( <>
{streamName}
)} {customText ? (
) : (
{text}
)} {lastLive && (
{`${(t('Last live ago'), { timeAgo: formatDistanceToNow(new Date(lastLive)) })}`}
)}
); };