import { Badge } from '@/components/ui/badge'
import { Button } from '@/components/ui/button'
import { ScrollArea, ScrollBar } from '@/components/ui/scroll-area'
import { useFetchRelayInfo } from '@/hooks'
import { normalizeHttpUrl } from '@/lib/url'
import { cn } from '@/lib/utils'
import { useNostr } from '@/providers/NostrProvider'
import { Check, Copy, GitBranch, Link, Mail, SquareCode } from 'lucide-react'
import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import { toast } from 'sonner'
import PostEditor from '../PostEditor'
import RelayIcon from '../RelayIcon'
import SaveRelayDropdownMenu from '../SaveRelayDropdownMenu'
import UserAvatar from '../UserAvatar'
import Username from '../Username'
import RelayReviewsPreview from './RelayReviewsPreview'
export default function RelayInfo({ url, className }: { url: string; className?: string }) {
const { t } = useTranslation()
const { checkLogin } = useNostr()
const { relayInfo, isFetching } = useFetchRelayInfo(url)
const [open, setOpen] = useState(false)
if (isFetching || !relayInfo) {
return null
}
return (
{relayInfo.name || relayInfo.shortUrl}
{!!relayInfo.tags?.length && (
{relayInfo.tags.map((tag) => (
{tag}
))}
)}
{relayInfo.description && (
{relayInfo.description}
)}
{relayInfo.pubkey && (
)}
{relayInfo.contact && (
{t('Contact')}
{relayInfo.contact}
)}
{relayInfo.software && (
{t('Software')}
{formatSoftware(relayInfo.software)}
)}
{relayInfo.version && (
{t('Version')}
{relayInfo.version}
)}
)
}
function formatSoftware(software: string) {
const parts = software.split('/')
return parts[parts.length - 1]
}
function RelayControls({ url }: { url: string }) {
const [copiedUrl, setCopiedUrl] = useState(false)
const [copiedShareableUrl, setCopiedShareableUrl] = useState(false)
const handleCopyUrl = () => {
navigator.clipboard.writeText(url)
setCopiedUrl(true)
setTimeout(() => setCopiedUrl(false), 2000)
}
const handleCopyShareableUrl = () => {
navigator.clipboard.writeText(`https://jumble.social/?r=${url}`)
setCopiedShareableUrl(true)
toast.success('Shareable URL copied to clipboard')
setTimeout(() => setCopiedShareableUrl(false), 2000)
}
return (
)
}