// SPDX-License-Identifier: AGPL-3.0-or-later import {useAnimatedMediaVideoPlayback} from '@app/features/app/hooks/useAnimatedMediaPlayback'; import {useShouldAnimate} from '@app/features/app/hooks/useShouldAnimate'; import {type AutocompleteOption, isGif} from '@app/features/channel/components/Autocomplete'; import styles from '@app/features/channel/components/AutocompleteGif.module.css'; import * as KlipyUtils from '@app/features/expressions/utils/KlipyUtils'; import {GIFS_DESCRIPTOR} from '@app/features/i18n/utils/CommonMessageDescriptors'; import {buildStaticGifPreviewURL} from '@app/features/messaging/utils/MediaProxyUtils'; import {Scroller, type ScrollerHandle} from '@app/features/ui/components/Scroller'; import {msg} from '@lingui/core/macro'; import {useLingui} from '@lingui/react/macro'; import {observer} from 'mobx-react-lite'; import type React from 'react'; import {useEffect, useMemo, useRef} from 'react'; const NO_GIFS_FOUND_DESCRIPTOR = msg({ message: 'No GIFs match', comment: 'Empty-state text in the channel and chat autocomplete gif.', }); const PLAYABLE_PREVIEW_EXTENSION_PATTERN = /\.(mp4|webm|mov|m4v)(?:$|\?)/iu; function isPlayablePreviewSource(value: string): boolean { try { return PLAYABLE_PREVIEW_EXTENSION_PATTERN.test(new URL(value).pathname); } catch { return PLAYABLE_PREVIEW_EXTENSION_PATTERN.test(value); } } const AutocompleteGifVideo = ({src, motionAllowed}: {src: string; motionAllowed: boolean}) => { const videoRef = useRef(null); const playbackAllowed = useAnimatedMediaVideoPlayback(videoRef, {shouldPlay: motionAllowed}); return (