import { useFetchWebMetadata } from '@/hooks/useFetchWebMetadata'
import { cn } from '@/lib/utils'
import { useContentPolicy } from '@/providers/ContentPolicyProvider'
import { useScreenSize } from '@/providers/ScreenSizeProvider'
import { useMemo } from 'react'
import Image from '../Image'
import ExternalLink from '../ExternalLink'
export default function WebPreview({
url,
className,
mustLoad
}: {
url: string
className?: string
mustLoad?: boolean
}) {
const { autoLoadMedia } = useContentPolicy()
const { isSmallScreen } = useScreenSize()
const { title, description, image } = useFetchWebMetadata(url)
const hostname = useMemo(() => {
try {
return new URL(url).hostname
} catch {
return ''
}
}, [url])
if (!autoLoadMedia && !mustLoad) {
return null
}
if (!title) {
if (mustLoad) {
return