import { Button } from "@/components/ui/button"; import { Dialog, DialogBody, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog"; import { Input } from "@/components/ui/input"; import { useState } from "react"; import { Label } from "@/components/ui/label"; export function RenameDialog({ isOpen, onOpenChange, onConfirm, currentName, title, }: { isOpen: boolean; onOpenChange: (open: boolean) => void; onConfirm: (newName: string) => void; currentName: string; title: string; }) { const [name, setName] = useState(currentName); const handleOpenChange = (open: boolean) => { if (open) { setName(currentName); } onOpenChange(open); }; const trimmedName = name.trim(); const isConfirmDisabled = trimmedName.length === 0 || trimmedName === currentName; const handleConfirm = () => { if (isConfirmDisabled) { return; } onConfirm(trimmedName); }; return ( {title} setName(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); handleConfirm(); } }} onFocus={(e) => e.target.select()} placeholder="Enter a new name" /> ); }