'use client' import React, { useState } from 'react' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription } from '@/components/ui/dialog' import { UserPlus, Link, Mail, Check, Copy } from 'lucide-react' interface InviteDialogProps { open: boolean onOpenChange: (open: boolean) => void onInviteByEmail: (email: string, role: 'editor' | 'viewer') => Promise onInviteByLink: () => Promise seedIdea: string isLoading: boolean t: (key: string) => string | undefined } export function InviteDialog({ open, onOpenChange, onInviteByEmail, onInviteByLink, seedIdea, isLoading, t, }: InviteDialogProps) { const [tab, setTab] = useState<'email' | 'link'>('email') const [email, setEmail] = useState('') const [role, setRole] = useState<'editor' | 'viewer'>('editor') const [linkCopied, setLinkCopied] = useState(false) const [emailSent, setEmailSent] = useState(false) const [localLoading, setLocalLoading] = useState(false) const handleEmailInvite = async (e: React.FormEvent) => { e.preventDefault() if (!email.trim()) return setLocalLoading(true) try { const res = await onInviteByEmail(email.trim(), role) if (res?.invitedUser) { setEmailSent(true) setTimeout(() => { setEmailSent(false) setEmail('') }, 2000) } } finally { setLocalLoading(false) } } const handleLinkCopy = async () => { setLocalLoading(true) try { const res = await onInviteByLink() if (res?.inviteUrl) { const url = window.location.origin + res.inviteUrl if (navigator.clipboard?.writeText) { await navigator.clipboard.writeText(url) } else { const ta = document.createElement('textarea') ta.value = url ta.style.position = 'fixed' ta.style.opacity = '0' document.body.appendChild(ta) ta.select() document.execCommand('copy') document.body.removeChild(ta) } setLinkCopied(true) setTimeout(() => setLinkCopied(false), 3000) } } finally { setLocalLoading(false) } } const busy = isLoading || localLoading return (
{t('brainstorm.inviteTitle') || 'Invite to brainstorm'}
{seedIdea.length > 60 ? seedIdea.substring(0, 60) + '…' : seedIdea}
{tab === 'email' ? (
setEmail(e.target.value)} placeholder={t('brainstorm.inviteEmailPlaceholder') || 'colleague@email.com'} className="w-full px-4 py-3 text-sm border border-border rounded-xl bg-transparent focus:outline-none focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500/40 transition-all" autoFocus />
) : (

{t('brainstorm.linkDescription') || 'Anyone with this link can join the brainstorm session.'}

)}
) }