/* eslint-disable react-refresh/only-export-components -- TrustFilter component + its level constants/helpers are intentionally colocated (dev-only HMR rule). */ import { Shield, CheckCircle2, Users } from 'lucide-react'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuCheckboxItem, DropdownMenuTrigger, DropdownMenuLabel, DropdownMenuSeparator, } from '@/components/ui/dropdown-menu'; import { cn } from '@/lib/utils'; export type TrustFilterLevel = 'all' | 'verified' | 'trusted' | 'following'; interface TrustFilterProps { value: TrustFilterLevel; onChange: (value: TrustFilterLevel) => void; className?: string; compact?: boolean; } const TRUST_LEVELS = [ { value: 'all' as const, label: 'All Users', description: 'Show content from everyone', icon: Users, color: 'text-gray-400', }, { value: 'verified' as const, label: 'Verified', description: 'You follow them or they are verified (trust ≥90)', icon: CheckCircle2, color: 'text-green-500', }, { value: 'trusted' as const, label: 'Trusted', description: 'Friends-of-friends or NIP-05 verified (trust ≥60)', icon: Shield, color: 'text-yellow-500', }, { value: 'following' as const, label: 'Following Only', description: 'Only show content from people you follow', icon: CheckCircle2, color: 'text-green-500', }, ]; export function TrustFilter({ value, onChange, className, compact = false }: TrustFilterProps) { const currentLevel = TRUST_LEVELS.find((l) => l.value === value) || TRUST_LEVELS[0]; const Icon = currentLevel.icon; if (compact) { return ( Filter by Trust Level {TRUST_LEVELS.map((level) => ( onChange(level.value)} className="flex flex-col items-start py-3" >
{level.label}

{level.description}

))}
); } return (
{TRUST_LEVELS.map((level) => { const Icon = level.icon; const isActive = value === level.value; return ( ); })}
); } /** * Helper function to filter items by trust score */ export function filterByTrustLevel( items: T[], level: TrustFilterLevel, getTrustScore: (pubkey: string) => number | undefined ): T[] { if (level === 'all') return items; return items.filter((item) => { const score = getTrustScore(item.pubkey); if (score === undefined) return false; switch (level) { case 'verified': return score >= 90; case 'trusted': return score >= 60; case 'following': return score === 90 || score === 100; default: return true; } }); }