import { useState } from 'react'; import { Card, CardContent } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; import { useCurrentUser } from '@/hooks/useCurrentUser'; import { useToast } from '@/hooks/useToast'; import { useTranslation } from '@/contexts/language'; import { useSendCollectiveJoinRequest, useMyCollectiveJoinRequest, } from '@/hooks/useCollectiveJoinRequests'; import type { LabProfile } from '@/hooks/useLabProfiles'; import { Users, Hand, Loader2, Check, X } from 'lucide-react'; /** * "Request to join this collective" — shown on a Lab collective's profile to * logged-in skaters who aren't the owner and aren't already listed. Mirrors the * crew join-request: it notifies the owner (who adds the member through their * own editor). Owners never see it on their own profile. */ export function RequestToJoinCollective({ profile, accentText = 'text-teal-400', accentBorder = 'border-teal-500', }: { profile: LabProfile; accentText?: string; accentBorder?: string; }) { const { t } = useTranslation(); const { user } = useCurrentUser(); const { toast } = useToast(); const [open, setOpen] = useState(false); const [note, setNote] = useState(''); const coord = `${profile.event.kind}:${profile.pubkey}:${profile.identifier}`; const { mutateAsync: send, isPending: sending } = useSendCollectiveJoinRequest(); const { data: alreadyRequested, isLoading: checking } = useMyCollectiveJoinRequest(coord); // Gate: must be logged in, not the owner, not already a listed member. if (!user) return null; const meLc = user.pubkey.toLowerCase(); if (meLc === profile.pubkey.toLowerCase()) return null; if (profile.members.some((m) => m.toLowerCase() === meLc)) return null; const handleSend = async () => { try { await send({ profile, note }); setOpen(false); setNote(''); toast({ title: t('socialUi.requestCollective.sentTitle'), description: t('socialUi.requestCollective.sentDesc', { name: profile.title }), }); } catch (err) { toast({ title: t('socialUi.requestCollective.couldNotSend'), description: err instanceof Error ? err.message : t('common.tryAgain'), variant: 'destructive', }); } }; return (

{t('socialUi.requestCollective.title')}

{alreadyRequested ? (
{t('socialUi.requestCollective.waiting', { name: profile.title })}
) : !open ? ( <>

{t('socialUi.requestCollective.askA')}{' '} {profile.title}{' '} {t('socialUi.requestCollective.askB')}

) : (