import { useChat } from '@/providers/ChatProvider' import { TAccessMode } from '@/services/chat.service' import { Globe, Loader2, Lock, LockOpen } from 'lucide-react' import { useState } from 'react' import { Button } from '../ui/button' const accessModes: { mode: TAccessMode; label: string; icon: React.ReactNode; desc: string }[] = [ { mode: 'open', label: 'Open', icon: , desc: 'Anyone authenticated can read and write' }, { mode: 'whitelist', label: 'Whitelist', icon: , desc: 'Only listed members can access' }, { mode: 'blacklist', label: 'Blacklist', icon: , desc: 'Everyone except excluded users can access' } ] export default function CreateChannelDialog({ open, onOpenChange }: { open: boolean onOpenChange: (open: boolean) => void }) { const { createChannel } = useChat() const [name, setName] = useState('') const [about, setAbout] = useState('') const [accessMode, setAccessMode] = useState('open') const [isCreating, setIsCreating] = useState(false) if (!open) return null const handleCreate = async () => { if (!name.trim()) return setIsCreating(true) try { await createChannel(name.trim(), about.trim(), accessMode) setName('') setAbout('') setAccessMode('open') onOpenChange(false) } finally { setIsCreating(false) } } const current = accessModes.find((m) => m.mode === accessMode)! return (
onOpenChange(false)}>
e.stopPropagation()} >

Create Channel

setName(e.target.value)} className="w-full px-3 py-2 text-sm border rounded-md bg-background" autoFocus onKeyDown={(e) => e.key === 'Enter' && handleCreate()} /> setAbout(e.target.value)} className="w-full px-3 py-2 text-sm border rounded-md bg-background" onKeyDown={(e) => e.key === 'Enter' && handleCreate()} />
Access mode
{accessModes.map(({ mode, label, icon }) => ( ))}
{current.desc}
) }