import React, { memo, useMemo, useRef } from '../../../lib/teact/teact'; import type { ApiFactCheck } from '../../../api/types'; import buildClassName from '../../../util/buildClassName'; import { renderTextWithEntities } from '../../common/helpers/renderTextWithEntities'; import useCollapsibleLines from '../../../hooks/element/useCollapsibleLines'; import useLastCallback from '../../../hooks/useLastCallback'; import useOldLang from '../../../hooks/useOldLang'; import Icon from '../../common/icons/Icon'; import PeerColorWrapper from '../../common/PeerColorWrapper'; import Separator from '../../ui/Separator'; import styles from './FactCheck.module.scss'; type OwnProps = { factCheck: ApiFactCheck; isToggleDisabled?: boolean; }; const COLOR = { color: 0, }; const MAX_LINES = 4; const FactCheck = ({ factCheck, isToggleDisabled }: OwnProps) => { const lang = useOldLang(); // eslint-disable-next-line no-null/no-null const ref = useRef(null); // eslint-disable-next-line no-null/no-null const cutoutRef = useRef(null); const { isCollapsed, isCollapsible, setIsCollapsed, } = useCollapsibleLines(ref, MAX_LINES, cutoutRef); const countryLocalized = useMemo(() => { if (!factCheck.countryCode || !lang.code) return undefined; const displayNames = new Intl.DisplayNames([lang.code], { type: 'region' }); return displayNames.of(factCheck.countryCode); }, [factCheck.countryCode, lang.code]); const canExpand = !isToggleDisabled && isCollapsed; const handleExpand = useLastCallback(() => { setIsCollapsed(false); }); const handleToggle = useLastCallback(() => { setIsCollapsed((prev) => !prev); }); if (!factCheck.text) { return undefined; } return (
{lang('FactCheck')}
{renderTextWithEntities({ text: factCheck.text.text, entities: factCheck.text.entities, })}
{lang('FactCheckFooter', countryLocalized)}
{isCollapsible && (
)}
); }; export default memo(FactCheck);