import React, { useState, useEffect } from 'react' import { useParams, useNavigate } from 'react-router-dom' import { ArrowLeft, Save, Globe, BookOpen } from 'lucide-react' import { useStoryStore } from '../../store/storyStore' import { useUIStore } from '../../store/uiStore' import { Button } from '../../components/ui/Button' import { AISuggestionPanel } from '../../components/writer/AISuggestionPanel' export const EditChapterPage: React.FC = () => { const { chapterId } = useParams<{ chapterId: string }>() const navigate = useNavigate() const { stories, chapters, updateChapter } = useStoryStore() const { addToast } = useUIStore() const [saving, setSaving] = useState(false) const chapter = chapters.find(c => c.chapter_id === Number(chapterId)) const story = chapter ? stories.find(s => s.story_id === chapter.story_id) : null const [form, setForm] = useState({ title: '', content: '' }) useEffect(() => { if (chapter) { setForm({ title: chapter.title, content: chapter.content }) } }, [chapter?.chapter_id]) if (!chapter || !story) { return (
{story.title} · Chapter {chapter.chapter_number}