import { memo, useEffect, useMemo, useRef, } from '../../../lib/teact/teact'; import { getActions } from '../../../global'; import type { TabState } from '../../../global/types'; import { requestMeasure, requestMutation } from '../../../lib/fasterdom/fasterdom'; import buildClassName from '../../../util/buildClassName'; import useLastCallback from '../../../hooks/useLastCallback'; import useOldLang from '../../../hooks/useOldLang'; import SafeLink from '../../common/SafeLink'; import Button from '../../ui/Button'; import ListItem from '../../ui/ListItem'; import Modal from '../../ui/Modal'; import Transition, { ACTIVE_SLIDE_CLASS_NAME, TO_SLIDE_CLASS_NAME } from '../../ui/Transition'; import styles from './ReportAdModal.module.scss'; const ADDED_PADDING = 56; export type OwnProps = { modal: TabState['reportAdModal']; }; const ReportAdModal = ({ modal, }: OwnProps) => { const { reportSponsored, closeReportAdModal, openPreviousReportAdModal, } = getActions(); const lang = useOldLang(); const isOpen = Boolean(modal); const transitionRef = useRef(); const handleOptionClick = useLastCallback((e, option: string) => { const { chatId, randomId } = modal!; reportSponsored({ peerId: chatId, randomId, option }); }); const [renderingSection, renderingDepth] = useMemo(() => { if (!modal) return [undefined, 0]; const sectionDepth = modal.sections.length - 1; return [modal.sections[sectionDepth], sectionDepth]; }, [modal]); const handleBackClick = useLastCallback(() => { if (!renderingDepth) { closeReportAdModal(); return; } openPreviousReportAdModal(); }); const bottomText = useMemo(() => { if (!modal) return undefined; const template = lang('lng_report_sponsored_reported_learn'); const parts = template.split('{link}'); return [ parts[0], , parts[1], ]; }, [lang, modal]); const header = useMemo(() => { if (!modal) { return undefined; } const hasSubtitle = Boolean(renderingSection?.subtitle); return (
); }, [lang, modal, renderingDepth, renderingSection?.subtitle]); useEffect(() => { if (!modal) return; const slide = document.querySelector(`.${ACTIVE_SLIDE_CLASS_NAME} > .${styles.slide}`); if (!slide) return; const height = slide.scrollHeight; requestMutation(() => { transitionRef.current!.style.height = `${height + ADDED_PADDING}px`; }); }, [modal]); const handleAnimationStart = useLastCallback(() => { const slide = document.querySelector(`.${TO_SLIDE_CLASS_NAME} > .${styles.slide}`)!; requestMeasure(() => { const height = slide.scrollHeight; requestMutation(() => { transitionRef.current!.style.height = `${height + ADDED_PADDING}px`; }); }); }); return (

{renderingSection?.title}

{renderingSection?.options.map((option) => (
{option.text}
))}

{bottomText}

); }; export default memo(ReportAdModal);