import { CircleAlert, Loader2, PlusCircle } from 'lucide-react'; import { useState, type ReactNode } from 'react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from '@/components/ui/dialog'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { useTranslation } from '@/i18n/useI18n'; interface AddSkillDialogProps { children: ReactNode; onAdd: (skillPath: string) => Promise; } export function AddSkillDialog({ children, onAdd }: AddSkillDialogProps) { const { t } = useTranslation(); const [open, setOpen] = useState(false); const [skillPath, setSkillPath] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const handleSubmit = async () => { if (!skillPath.trim()) return; setLoading(true); setError(null); try { await onAdd(skillPath.trim()); setSkillPath(''); setOpen(false); } catch (e) { setError((e as Error).message); } finally { setLoading(false); } }; return ( {children} {t('dialog-skill-add.title')} {t('dialog-skill-add.description')}
setSkillPath(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') handleSubmit(); }} /> {error &&

{error}

}
); }