import React from 'react' import { useNavigate } from 'react-router-dom' import { Eye, BookOpen, Lock } from 'lucide-react' import { Chapter } from '../../types' interface ChapterListProps { chapters: Chapter[] storyId: number showEditLinks?: boolean onEdit?: (chapterId: number) => void } function formatDate(str: string) { return new Date(str).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric' }) } export const ChapterList: React.FC = ({ chapters, storyId, showEditLinks, onEdit }) => { const navigate = useNavigate() const sorted = [...chapters].sort((a, b) => a.chapter_number - b.chapter_number) if (sorted.length === 0) { return (

No chapters yet.

) } return (
{sorted.map(chapter => (
{ if (chapter.is_published) navigate(`/story/${storyId}/chapter/${chapter.chapter_id}`) }} > {/* Number */}
{chapter.chapter_number}
{/* Info */}

{chapter.title}

{!chapter.is_published && ( Draft )}
{chapter.word_count.toLocaleString()} words {formatDate(chapter.created_at)}
{/* Views */}
{chapter.view_count.toLocaleString()}
{/* Edit button */} {showEditLinks && onEdit && ( )}
))}
) }