import { useParams } from 'react-router-dom'; import { useGetDocument, useGetProgress } from '../generated/anthoLumeAPIV1'; interface Document { id: string; title: string; author: string; description?: string; isbn10?: string; isbn13?: string; words?: number; filepath?: string; created_at: string; updated_at: string; deleted: boolean; percentage?: number; total_time_seconds?: number; wpm?: number; seconds_per_percent?: number; last_read?: string; } interface Progress { document_id?: string; percentage?: number; created_at?: string; user_id?: string; device_name?: string; title?: string; author?: string; } // Helper function to format seconds nicely (mirroring legacy niceSeconds) function niceSeconds(seconds: number): string { if (seconds === 0) return 'N/A'; const days = Math.floor(seconds / 60 / 60 / 24); const remainingSeconds = seconds % (60 * 60 * 24); const hours = Math.floor(remainingSeconds / 60 / 60); const remainingAfterHours = remainingSeconds % (60 * 60); const minutes = Math.floor(remainingAfterHours / 60); const remainingSeconds2 = remainingAfterHours % 60; let result = ''; if (days > 0) result += `${days}d `; if (hours > 0) result += `${hours}h `; if (minutes > 0) result += `${minutes}m `; if (remainingSeconds2 > 0) result += `${remainingSeconds2}s`; return result || 'N/A'; } export default function DocumentPage() { const { id } = useParams<{ id: string }>(); const { data: docData, isLoading: docLoading } = useGetDocument(id || ''); const { data: progressData, isLoading: progressLoading } = useGetProgress(id || ''); if (docLoading || progressLoading) { return
Loading...
; } const document = docData?.data?.document as Document; const progressDataArray = progressData?.data?.progress; const progress = Array.isArray(progressDataArray) ? progressDataArray[0] as Progress : undefined; if (!document) { return
Document not found
; } // Calculate total time left (mirroring legacy template logic) const percentage = progress?.percentage || document.percentage || 0; const secondsPerPercent = document.seconds_per_percent || 0; const totalTimeLeftSeconds = Math.round((100 - percentage) * secondsPerPercent); return (
{/* Document Info - Left Column */}
{/* Cover Image */} {document.filepath && (
{`${document.title}
)} {/* Read Button - Only if file exists */} {document.filepath && ( Read )} {/* Action Buttons */}

ISBN-10:

{document.isbn10 || 'N/A'}

ISBN-13:

{document.isbn13 || 'N/A'}

{/* Download Button - Only if file exists */} {document.filepath && ( )}
{/* Document Details Grid */}
{/* Title - Editable */}

Title

{document.title}

{/* Author - Editable */}

Author

{document.author}

{/* Time Read */}

Time Read

{document.total_time_seconds ? niceSeconds(document.total_time_seconds) : 'N/A'}

{/* Progress */}

Progress

{percentage ? `${Math.round(percentage)}%` : '0%'}

{/* Description - Editable */}

Description

{document.description || 'N/A'}

{/* Reading Statistics */}

Words

{document.words || 'N/A'}

Created

{new Date(document.created_at).toLocaleDateString()}

Updated

{new Date(document.updated_at).toLocaleDateString()}

{/* Additional Reading Stats - Matching Legacy Template */} {progress && (

Words / Minute:

{document.wpm || 'N/A'}

Est. Time Left:

{niceSeconds(totalTimeLeftSeconds)}

)}
); }