import { Button } from '@/components/ui/button';
import {
  Dialog,
  DialogContent,
  DialogDescription,
  DialogFooter,
  DialogHeader,
  DialogTitle,
} from '@/components/ui/dialog';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Switch } from '@/components/ui/switch';
import { Loader2, MessageCircle, Plus } from 'lucide-react';

interface CreateRoomDialogProps {
  open: boolean;
  onOpenChange: (open: boolean) => void;
  roomName: string;
  roomPublic: boolean;
  onRoomNameChange: (v: string) => void;
  onRoomPublicChange: (v: boolean) => void;
  onSubmit: () => void;
  isPending: boolean;
}

export function CreateRoomDialog({
  open,
  onOpenChange,
  roomName,
  roomPublic,
  onRoomNameChange,
  onRoomPublicChange,
  onSubmit,
  isPending,
}: CreateRoomDialogProps) {
  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent className="sm:max-w-[425px]">
        <DialogHeader>
          <DialogTitle className="flex items-center gap-2">
            <MessageCircle className="h-5 w-5" />
            New Room
          </DialogTitle>
          <DialogDescription>Create a new chat room. Choose a name and visibility.</DialogDescription>
        </DialogHeader>
        <div className="grid gap-4 py-4">
          <div className="grid gap-2">
            <Label htmlFor="room-name">Room name</Label>
            <Input
              id="room-name"
              value={roomName}
              onChange={(e) => onRoomNameChange(e.target.value)}
              placeholder="e.g. general"
            />
          </div>
          <div className="flex items-center justify-between">
            <Label htmlFor="room-public">Public (visible to all project members)</Label>
            <Switch id="room-public" checked={roomPublic} onCheckedChange={onRoomPublicChange} />
          </div>
        </div>
        <DialogFooter>
          <Button variant="outline" onClick={() => onOpenChange(false)} disabled={isPending}>
            Cancel
          </Button>
          <Button onClick={onSubmit} disabled={!roomName.trim() || isPending}>
            {isPending ? (
              <>
                <Loader2 className="mr-2 h-4 w-4 animate-spin" /> Creating...
              </>
            ) : (
              <>
                <Plus className="mr-2 h-4 w-4" /> Create
              </>
            )}
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
}
