"use client"; import { useEffect, useRef, useState } from "react"; import { motion } from "framer-motion"; import { Maximize2, Minimize2 } from "lucide-react"; import type { Article } from "@/lib/reading/articles"; import { useFullscreen } from "@/hooks/use-fullscreen"; const GREEN = "#10b981"; interface ReaderProps { article: Article; onFinished: (durationSecs: number) => void; } const MIN_READ_SECONDS = 60; // minimum time before "Done" is active function formatTime(s: number): string { const m = Math.floor(s / 60); const sec = s % 60; return `${m}:${sec.toString().padStart(2, "0")}`; } /** Render basic markdown: ## headers, **bold**, paragraph splits */ function renderMarkdown(text: string): React.ReactNode[] { const blocks = text.split(/\n{2,}/); return blocks.map((block, i) => { const trimmed = block.trim(); if (!trimmed) return null; // Heading const h2 = trimmed.match(/^## (.+)/); if (h2) { return (
{renderInline(trimmed)}
); }); } function renderInline(text: string): React.ReactNode { // Handle **bold** const parts = text.split(/(\*\*[^*]+\*\*)/g); return parts.map((part, i) => { if (part.startsWith("**") && part.endsWith("**")) { return ( {part.slice(2, -2)} ); } return part; }); } export function Reader({ article, onFinished }: ReaderProps) { const [elapsed, setElapsed] = useState(0); const timerRef = useRef{article.domain} · {article.difficulty} · ~{article.estimatedMinutes} min