'use client'; import React, { useEffect, useState } from 'react'; import { BookProject, BookSettings } from '@/lib/types'; import { GENRES, TONES, POV_OPTIONS, TENSE_OPTIONS } from '@/lib/constants'; import { Settings, Book, Feather, Users, Clock, Target, Hash, Save, Check } from 'lucide-react'; import { useLanguage } from '@/providers/LanguageProvider'; import { TranslationKey } from '@/lib/i18n/translations'; interface BookSettingsProps { project: BookProject; onUpdate: (project: BookProject) => void; onDeleteProject: () => void; } const DEFAULT_SETTINGS: BookSettings = { genre: '', subGenre: '', targetAudience: '', tone: '', pov: '', tense: '', synopsis: '', themes: '' }; const BookSettingsComponent: React.FC = ({ project, onUpdate, onDeleteProject }) => { const { t } = useLanguage(); // Local state for all editable fields to prevent excessive API calls const [localTitle, setLocalTitle] = useState(project.title); const [localAuthor, setLocalAuthor] = useState(project.author); const [localStyleGuide, setLocalStyleGuide] = useState(project.styleGuide || ''); const [localSettings, setLocalSettings] = useState(project.settings || DEFAULT_SETTINGS); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); const [isSaving, setIsSaving] = useState(false); const [showSavedFeedback, setShowSavedFeedback] = useState(false); useEffect(() => { setLocalTitle(project.title); setLocalAuthor(project.author); setLocalStyleGuide(project.styleGuide || ''); if (project.settings) { setLocalSettings(project.settings); } }, [project.title, project.author, project.styleGuide, project.settings]); const handleChange = (key: keyof BookSettings, value: string) => { setLocalSettings(prev => ({ ...prev, [key]: value })); }; const handleSave = () => { setIsSaving(true); onUpdate({ ...project, title: localTitle, author: localAuthor, styleGuide: localStyleGuide, settings: localSettings }); // Simulate save delay for UI feedback setTimeout(() => { setIsSaving(false); setShowSavedFeedback(true); setTimeout(() => setShowSavedFeedback(false), 2000); }, 500); }; return (

{t('book_settings.title')}

{t('book_settings.subtitle')}

{t('book_settings.basic_info')}

setLocalTitle(e.target.value)} className="w-full p-2.5 bg-theme-bg text-theme-text border border-theme-border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none font-serif font-bold text-lg transition-colors duration-300" />
setLocalAuthor(e.target.value)} className="w-full p-2.5 bg-theme-bg text-theme-text border border-theme-border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none transition-colors duration-300" />