import { useState } from 'react'; import { Loader2, Flag, Check } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog'; import { LoginArea } from '@/components/auth/LoginArea'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useToast } from '@/hooks/useToast'; import { usePublishSpotStatus, useSpotStatus } from '@/hooks/useSpotStatus'; import { SpotStatusBadge } from '@/components/SpotStatusBadge'; import { SPOT_STATUS_META, SPOT_STATUS_ORDER, statusTimeAgo } from '@/lib/spotStatus'; import { useAuthor } from '@/hooks/useAuthor'; import { genUserName } from '@/lib/genUserName'; import { useTranslation } from '@/contexts/language'; import type { SpotStatusValue, SpotStatusReport } from '@/lib/types'; import { cn } from '@/lib/utils'; interface ReportSpotStatusDialogProps { spotPubkey: string; spotIdentifier: string; spotTitle: string; trigger?: React.ReactNode; } function ReportRow({ report }: { report: SpotStatusReport }) { const { t } = useTranslation(); const author = useAuthor(report.pubkey); const name = author.data?.metadata?.name ?? genUserName(report.pubkey); const meta = SPOT_STATUS_META[report.status]; return (
{t(meta.labelKey)} {t('spotUi.byAuthor', { name })} {statusTimeAgo(report.createdAt)}
{report.note && (

{report.note}

)}
); } export function ReportSpotStatusDialog({ spotPubkey, spotIdentifier, spotTitle, trigger, }: ReportSpotStatusDialogProps) { const { t } = useTranslation(); const { user } = useCurrentUser(); const { toast } = useToast(); const [open, setOpen] = useState(false); const [selected, setSelected] = useState(null); const [note, setNote] = useState(''); const { aggregated, reports } = useSpotStatus(spotPubkey, spotIdentifier); const { mutateAsync: publishStatus, isPending } = usePublishSpotStatus(); const handleSubmit = async () => { if (!selected) return; try { await publishStatus({ spotPubkey, spotIdentifier, spotTitle, status: selected, note: note.trim() || undefined, }); toast({ title: t('spotUi.statusReported'), description: t('spotUi.statusReportedDesc'), }); setSelected(null); setNote(''); setOpen(false); } catch (error) { toast({ title: t('spotUi.couldNotSubmit'), description: error instanceof Error ? error.message : t('spotUi.somethingWentWrong'), variant: 'destructive', }); } }; return ( {trigger ?? ( )} {t('spotUi.spotStatus')} {t('spotUi.spotStatusDesc', { title: spotTitle })} {/* Current consensus */}
{t('spotUi.current')} {aggregated.status ? ( ) : ( {t('spotUi.noReportsYet')} )}
{user ? (
{/* Status picker */}
{SPOT_STATUS_ORDER.map((value) => { const meta = SPOT_STATUS_META[value]; const isSel = selected === value; return ( ); })}
{/* Optional note */}