import Link from "next/link"
import { ChevronLeft } from "lucide-react"
import { Button } from "@/components/ui/button"
import { specialSections, FULL_BOOK_PRICE } from "@/lib/book-data"
import { getBookStructure } from "@/lib/book-file-system"
import { ChaptersList } from "@/components/chapters-list"

import { BuyFullBookButton } from "@/components/buy-full-book-button"

export const dynamic = 'force-dynamic';

export default async function ChaptersPage() {
  const parts = getBookStructure()

  // Format special sections for the client component
  const specialSectionsData = {
    preface: { title: specialSections.preface.title },
    epilogue: { title: specialSections.epilogue.title }
  }

  return (
    <div className="min-h-screen bg-[#0a1628] text-white">
      {/* Header */}
      <header className="sticky top-0 z-50 bg-[#0a1628]/90 backdrop-blur-md border-b border-gray-800">
        <div className="max-w-4xl mx-auto px-4 py-4 flex items-center justify-between">
          <Link href="/" className="flex items-center gap-2 text-gray-400 hover:text-white transition-colors">
            <ChevronLeft className="w-5 h-5" />
            <span>返回</span>
          </Link>
          <h1 className="text-lg font-semibold">目录</h1>
          <BuyFullBookButton size="sm" price={9.9} className="bg-[#38bdac] hover:bg-[#2da396] text-white" />
        </div>
      </header>

      {/* Content */}
      <main className="max-w-4xl mx-auto px-4 py-8">
        <ChaptersList parts={parts} specialSections={specialSectionsData} />

        {/* Bottom CTA */}
        <div className="mt-12 bg-gradient-to-r from-[#38bdac]/20 to-[#0f2137] rounded-2xl p-6 border border-[#38bdac]/30">
          <div className="flex flex-col md:flex-row items-center justify-between gap-4">
            <div>
              <h3 className="text-white text-lg font-semibold mb-1">购买整本书,省82%</h3>
              <p className="text-gray-400">全部55节内容,永久阅读,后续更新免费获取</p>
            </div>
            <BuyFullBookButton size="lg" price={9.9} className="bg-[#38bdac] hover:bg-[#2da396] text-white px-8">
              立即购买 ¥9.9
            </BuyFullBookButton>
          </div>
        </div>
      </main>
    </div>
  )
}
