import { readFileSync } from "fs";
import path from "path";
import { parseEbookMarkdown, estimateReadingMinutes } from "@/lib/content/ebook";
import { EbookViewer } from "@/app/components/content/EbookViewer";
import { CLOUDPHONE_EBOOK_CONFIG } from "@/config/content.config";

export const metadata = {
  title: "云手机 | 低成本工作室搭建指南",
  description: "云手机：低成本自建云手机，TikTok/YouTube 无人直播，Redroid、AOSP、ffmpeg、SRS 从零搭建。",
};

export default function CloudphoneEbookPage() {
  const mdPath = path.join(process.cwd(), "app/data/cloudphone.md");
  const source = readFileSync(mdPath, "utf-8");
  const data = parseEbookMarkdown(source);
  const textLen = data.chunks.reduce((s, c) => s + c.html.replace(/<[^>]+>/g, "").length, 0);
  const config = {
    ...CLOUDPHONE_EBOOK_CONFIG,
    estimatedMinutes: estimateReadingMinutes(textLen),
  };

  return <EbookViewer data={data} config={config} />;
}
