/* eslint-disable react/no-danger */ /* eslint-disable jsx-a11y/click-events-have-key-events */ import { Divider } from 'antd'; import React, { FC } from 'react'; import { formatDistanceToNow } from 'date-fns'; import dynamic from 'next/dynamic'; import classNames from 'classnames'; import { useTranslation } from 'next-export-i18n'; import { Translation } from '../Translation/Translation'; import { Localization } from '../../../types/localization'; 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(); const handleSpanClick = (event: React.MouseEvent) => { const target = event.target as HTMLSpanElement; if (target.classList.contains('notify-link')) { onNotifyClick?.(); } else if (target.classList.contains('follow-link')) { onFollowClick?.(); } }; let text; if (customText) { text = customText; } else if (!customText && notificationsEnabled && fediverseAccount) { text = ( ); } else if (!customText && notificationsEnabled) { text = ( ); } else if (!customText && fediverseAccount) { text = ( ); } else { text = ( ); } return (
{showsHeader && ( <>
{streamName}
)} {customText ? (
) : (
{text}
)} {lastLive && (
{`${t(Localization.Frontend.lastLiveAgo, { timeAgo: formatDistanceToNow(new Date(lastLive)) })}`}
)}
); };