"use client" import { useState, useEffect } from "react" import { X, Lock, Sparkles } from "lucide-react" import { useStore } from "@/lib/store" import { getFullBookPrice } from "@/lib/book-data" interface ReadingModalProps { section: { id: string; title: string; filePath: string } onClose: () => void onPurchase: (sectionId: string, title: string, price: number) => void } export function ReadingModal({ section, onClose, onPurchase }: ReadingModalProps) { const [content, setContent] = useState("") const [isLoading, setIsLoading] = useState(true) const { isLoggedIn, hasPurchased } = useStore() const isFree = section.id === "preface" || section.id === "epilogue" const canAccess = isFree || (isLoggedIn && hasPurchased(section.id)) const fullBookPrice = getFullBookPrice() useEffect(() => { async function loadContent() { try { const response = await fetch(`/api/content?path=${encodeURIComponent(section.filePath)}`) if (response.ok) { const data = await response.json() setContent(data.content || "") } } catch (error) { console.error("Failed to load content:", error) } finally { setIsLoading(false) } } loadContent() }, [section.filePath]) // 计算显示内容 const displayContent = canAccess ? content : content.slice(0, Math.floor(content.length * 0.3)) const showPaywall = !canAccess && content.length > 0 return (
{/* Header */}

{section.title}

{/* Content */}
{isLoading ? (
{[...Array(10)].map((_, i) => (
))}
) : ( <>
{displayContent.split("\n").map( (paragraph, index) => paragraph.trim() && (

{paragraph}

), )}
{/* 付费墙渐变 */} {showPaywall && (
)}
{/* 付费提示 - 在阅读中途触发 */} {showPaywall && (

解锁完整内容

您已阅读30%,解锁后可阅读完整内容

分享给好友,他人购买你可获得 90% 返利

)} )}
) }