import React, { useEffect, useState } from 'react' import { X, Save } from 'lucide-react' import { KnowledgeGroup, UpdateGroupData } from '../types' import { useLanguage } from '../contexts/LanguageContext' import { useToast } from '../contexts/ToastContext' interface EditNotebookDialogProps { isOpen: boolean onClose: () => void notebook: KnowledgeGroup onUpdate: (id: string, data: UpdateGroupData) => Promise } export const EditNotebookDialog: React.FC = ({ isOpen, onClose, notebook, onUpdate, }) => { const [name, setName] = useState(notebook.name) const [description, setDescription] = useState(notebook.description || '') const [isSubmitting, setIsSubmitting] = useState(false) const { t } = useLanguage() const { showError } = useToast() // Reset form when notebook changes or dialog opens useEffect(() => { if (isOpen) { setName(notebook.name) setDescription(notebook.description || '') } }, [isOpen, notebook]) if (!isOpen) return null const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!name.trim()) return try { setIsSubmitting(true) await onUpdate(notebook.id, { name: name.trim(), description: description.trim(), }) onClose() } catch (error) { console.error('Failed to update notebook:', error) showError(t('updateFailedRetry')) } finally { setIsSubmitting(false) } } return (

{t('editNotebookTitle')}

setName(e.target.value)} className="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder={t('namePlaceholder')} required />
setDescription(e.target.value)} className="w-full px-3 py-2 border rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500" placeholder={t('descPlaceholder')} />
) }