import { useMemo } from 'react'; import { Label } from '@/components/ui/label'; import { Link2, X, GraduationCap } from 'lucide-react'; import { useLabProfiles } from '@/hooks/useLabProfiles'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useTranslation } from '@/contexts/language'; import { cn } from '@/lib/utils'; interface LabLinkFieldProps { /** Selected Lab profile coordinates (`kind:pubkey:d`). */ value: string[]; onChange: (coords: string[]) => void; maxLinks?: number; } /** * Lets a crew owner link their own Lab profiles (studio/coach/builder listings) * so a crew and its service listings cross-reference each other. */ export function LabLinkField({ value, onChange, maxLinks = 8 }: LabLinkFieldProps) { const { user } = useCurrentUser(); const { t } = useTranslation(); const { data: allProfiles } = useLabProfiles(200); const typeLabel = (type: string) => { const known = ['coach', 'filmer', 'editor', 'photographer', 'builder', 'artist', 'graffiti', 'tattoo', 'trainer', 'musician', 'judge', 'barber', 'organizer', 'transport']; return known.includes(type) ? t(`labUi.labLink.${type}`) : t('labUi.labLink.lab'); }; // Only your own Lab profiles — a crew can only vouch a link to listings it controls. const myProfiles = useMemo( () => (allProfiles ?? []).filter((p) => p.pubkey === user?.pubkey), [allProfiles, user?.pubkey] ); const coordFor = (kind: number, pubkey: string, identifier: string) => `${kind}:${pubkey}:${identifier}`; const toggle = (coord: string) => { if (value.includes(coord)) { onChange(value.filter((c) => c !== coord)); } else if (value.length < maxLinks) { onChange([...value, coord]); } }; return (

{t('labUi.labLink.desc')}{' '} {t('common.verified')}{' '} {t('labUi.labLink.descEnd')}

{myProfiles.length === 0 ? (

{t('labUi.labLink.empty')}

) : (
{myProfiles.map((p) => { const coord = coordFor(p.event.kind, p.pubkey, p.identifier); const selected = value.includes(coord); return ( ); })}
)}
); }