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 } from 'lucide-react';

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

export function EditRoomDialog({
  open,
  onOpenChange,
  roomName,
  roomPublic,
  onRoomNameChange,
  onRoomPublicChange,
  onSubmit,
  isPending,
}: EditRoomDialogProps) {
  return (
    <Dialog open={open} onOpenChange={onOpenChange}>
      <DialogContent className="sm:max-w-[425px]">
        <DialogHeader>
          <DialogTitle>Edit room</DialogTitle>
          <DialogDescription>Change room name and visibility.</DialogDescription>
        </DialogHeader>
        <div className="grid gap-4 py-4">
          <div className="grid gap-2">
            <Label htmlFor="edit-room-name">Room name</Label>
            <Input
              id="edit-room-name"
              value={roomName}
              onChange={(e) => onRoomNameChange(e.target.value)}
              placeholder="Room name"
            />
          </div>
          <div className="flex items-center justify-between">
            <Label htmlFor="edit-room-public">Public</Label>
            <Switch id="edit-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" /> Saving...
              </>
            ) : (
              'Save'
            )}
          </Button>
        </DialogFooter>
      </DialogContent>
    </Dialog>
  );
}
