import {Pressable, ScrollView, View} from 'react-native'
import {moderateProfile, type ModerationOpts} from '@atproto/api'
import {Trans, useLingui} from '@lingui/react/macro'
import {createHitslop, HITSLOP_10} from '#/lib/constants'
import {makeProfileLink} from '#/lib/routes/links'
import {sanitizeDisplayName} from '#/lib/strings/display-names'
import {sanitizeHandle} from '#/lib/strings/handles'
import {useEnableSquareButtons} from '#/state/preferences/enable-square-buttons'
import {useModerationOpts} from '#/state/preferences/moderation-opts'
import {UserAvatar} from '#/view/com/util/UserAvatar'
import {BlockDrawerGesture} from '#/view/shell/BlockDrawerGesture'
import {atoms as a} from '#/alf'
import {Button, ButtonIcon} from '#/components/Button'
import {TimesLarge_Stroke2_Corner0_Rounded as XIcon} from '#/components/icons/Times'
import * as Layout from '#/components/Layout'
import {Link} from '#/components/Link'
import {Text} from '#/components/Typography'
import {useSimpleVerificationState} from '#/components/verification'
import {VerificationCheck} from '#/components/verification/VerificationCheck'
import {useAnalytics} from '#/analytics'
import type * as bsky from '#/types/bsky'
export function SearchHistory({
searchHistory,
selectedProfiles,
onItemClick,
onProfileClick,
onRemoveItemClick,
onRemoveProfileClick,
}: {
searchHistory: string[]
selectedProfiles: bsky.profile.AnyProfileView[]
onItemClick: (item: string) => void
onProfileClick: (profile: bsky.profile.AnyProfileView) => void
onRemoveItemClick: (item: string) => void
onRemoveProfileClick: (profile: bsky.profile.AnyProfileView) => void
}) {
const ax = useAnalytics()
const {t: l} = useLingui()
const moderationOpts = useModerationOpts()
const enableSquareButtons = useEnableSquareButtons()
return (
{(searchHistory.length > 0 || selectedProfiles.length > 0) && (
Recent searches
)}
{selectedProfiles.length > 0 && (
{moderationOpts &&
selectedProfiles.map((profile, index) => (
{
ax.metric('search:recent:press', {
profileDid: profile.did,
position: index,
})
onProfileClick(profile)
}}
onRemove={() => onRemoveProfileClick(profile)}
/>
))}
)}
{searchHistory.length > 0 && (
{searchHistory.slice(0, 5).map((historyItem, index) => (
{
ax.metric('search:query', {
source: 'history',
})
onItemClick(historyItem)
}}
hitSlop={HITSLOP_10}
style={[a.flex_1, a.py_sm]}>
{historyItem}
))}
)}
)
}
function RecentProfileItem({
profile,
moderationOpts,
onPress,
onRemove,
}: {
profile: bsky.profile.AnyProfileView
moderationOpts: ModerationOpts
onPress: () => void
onRemove: () => void
}) {
const {t: l} = useLingui()
const width = 80
const moderation = moderateProfile(profile, moderationOpts)
const name = sanitizeDisplayName(
profile.displayName || sanitizeHandle(profile.handle),
moderation.ui('displayName'),
)
const verification = useSimpleVerificationState({profile})
const enableSquareButtons = useEnableSquareButtons()
return (
{name}
{verification.showBadge && (
)}
)
}