"use client" import { useState, useEffect } from "react" import Link from "next/link" import { ChevronLeft, Lock, Share2, BookOpen, Clock, MessageCircle, ChevronRight, Sparkles } from "lucide-react" import { type Section, getFullBookPrice, isSectionUnlocked } from "@/lib/book-data" import { useStore } from "@/lib/store" import { AuthModal } from "./modules/auth/auth-modal" import { PaymentModal } from "./modules/payment/payment-modal" import { UserMenu } from "./user-menu" import { QRCodeModal } from "./modules/marketing/qr-code-modal" import { ReferralShare } from "./modules/referral/referral-share" interface ChapterContentProps { section: Section & { filePath: string } partTitle: string chapterTitle: string } export function ChapterContent({ section, partTitle, chapterTitle }: ChapterContentProps) { const [content, setContent] = useState("") const [isLoading, setIsLoading] = useState(true) const [isAuthOpen, setIsAuthOpen] = useState(false) const [isPaymentOpen, setIsPaymentOpen] = useState(false) const [isQRModalOpen, setIsQRModalOpen] = useState(false) const [paymentType, setPaymentType] = useState<"section" | "fullbook">("section") const [fullBookPrice, setFullBookPrice] = useState(9.9) const [readingProgress, setReadingProgress] = useState(0) const { user, isLoggedIn, hasPurchased, settings } = useStore() const distributorShare = settings?.distributorShare || 90 const isUnlocked = isSectionUnlocked(section) const canAccess = section.isFree || isUnlocked || (isLoggedIn && hasPurchased(section.id)) useEffect(() => { setFullBookPrice(getFullBookPrice()) }, []) // 阅读进度追踪 useEffect(() => { const handleScroll = () => { const scrollTop = window.scrollY const docHeight = document.documentElement.scrollHeight - window.innerHeight const progress = Math.min((scrollTop / docHeight) * 100, 100) setReadingProgress(progress) } window.addEventListener('scroll', handleScroll) return () => window.removeEventListener('scroll', handleScroll) }, []) useEffect(() => { async function loadContent() { try { if (section.content) { setContent(section.content) setIsLoading(false) return } if (typeof window !== "undefined" && section.filePath.startsWith("custom/")) { const customSections = JSON.parse(localStorage.getItem("custom_sections") || "[]") as Section[] const customSection = customSections.find((s) => s.id === section.id) if (customSection?.content) { setContent(customSection.content) setIsLoading(false) return } } const response = await fetch(`/api/content?path=${encodeURIComponent(section.filePath)}`) if (response.ok) { const data = await response.json() if (!data.isCustom) { setContent(data.content) } } } catch (error) { console.error("Failed to load content:", error) } finally { setIsLoading(false) } } loadContent() }, [section.filePath, section.id, section.content]) const handlePurchaseClick = (type: "section" | "fullbook") => { if (!isLoggedIn) { setIsAuthOpen(true) return } setPaymentType(type) setIsPaymentOpen(true) } const handleShare = async () => { const url = user?.referralCode ? `${window.location.href}?ref=${user.referralCode}` : window.location.href const shareData = { title: section.title, text: `来自Soul派对房的真实商业故事: ${section.title}`, url: url, } try { if (navigator.share && navigator.canShare && navigator.canShare(shareData)) { await navigator.share(shareData) } else { navigator.clipboard.writeText(url) alert( `链接已复制!分享后他人购买,你可获得${distributorShare}%返利 (¥${((fullBookPrice * distributorShare) / 100).toFixed(1)})`, ) } } catch (error) { if ((error as Error).name !== "AbortError") { navigator.clipboard.writeText(url) alert(`链接已复制!分享后他人购买,你可获得${distributorShare}%返利`) } } } const previewContent = content.slice(0, 500) return (
{/* 阅读进度条 */}
{/* Header - iOS风格毛玻璃 */}

{partTitle}

{chapterTitle && (

{chapterTitle}

)}
{/* 阅读内容 */}
{/* 标题区域 */}
{section.id} {section.unlockAfterDays && !section.isFree && ( {isUnlocked ? "已免费解锁" : `${section.unlockAfterDays}天后免费`} )}

{section.title}

{isLoading ? ( // 骨架屏加载
{[...Array(8)].map((_, i) => (
))}
) : canAccess ? ( <> {/* 正文内容 - 书籍阅读风格 */}
{content.split("\n").map((paragraph, index) => ( paragraph.trim() && (

{paragraph}

) ))}
{/* 进群引导 CTA */}

想听更多商业故事?

每天早上6-9点,卡若在Soul派对房分享真实案例

) : (
{/* 预览内容 */}
{previewContent.split("\n").map((paragraph, index) => ( paragraph.trim() && (

{paragraph}

) ))}
{/* 购买提示 - 毛玻璃风格 */}

解锁完整内容

{isLoggedIn ? "购买本节或整本书以阅读完整内容" : "登录后购买即可阅读完整内容"}

{section.unlockAfterDays && (
本节将在{section.unlockAfterDays}天后免费解锁
)}

分享本书,他人购买你可获得 {distributorShare}%返利

{/* 进群引导 */}

不想花钱?来派对群免费听!

每天早上6-9点,卡若在Soul派对房免费分享

)} {/* 底部导航 */}
返回目录
{/* 弹窗 */} setIsAuthOpen(false)} /> setIsPaymentOpen(false)} type={paymentType} sectionId={section.id} sectionTitle={section.title} amount={paymentType === "section" ? section.price : fullBookPrice} onSuccess={() => window.location.reload()} /> setIsQRModalOpen(false)} />
) }