const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

async function testSubsectionNavigation() {
  console.log('\n📊 测试小节导航：\n');
  
  const bookId = 5;
  
  // 获取一个小节
  const subsection = await prisma.bookChapter.findFirst({
    where: {
      bookId,
      level: 3
    },
    select: {
      id: true,
      title: true,
      level: true,
      number: true,
      content: true,
      status: true,
      contentStatus: true,
    }
  });
  
  if (!subsection) {
    console.log('❌ 找不到小节\n');
    await prisma.$disconnect();
    return;
  }
  
  console.log('示例小节：');
  console.log(`  ID: ${subsection.id}`);
  console.log(`  标题: ${subsection.title}`);
  console.log(`  Level: ${subsection.level}`);
  console.log(`  Number: ${subsection.number}`);
  console.log(`  Status: ${subsection.status}`);
  console.log(`  ContentStatus: ${subsection.contentStatus}`);
  console.log(`  内容: ${subsection.content ? subsection.content.substring(0, 50) + '...' : '无'}\n`);
  
  console.log('✅ 前端应该这样跳转：');
  console.log(`   /pages/book-generator/chapter-detail?bookId=5&chapter=${subsection.id}\n`);
  
  console.log('✅ 详情页应该显示：');
  console.log(`   - 标题: ${subsection.title}`);
  console.log(`   - Level: 3 (小节)`);
  console.log(`   - 内容: ${subsection.content ? '有内容' : '无内容'}`);
  console.log(`   - 状态: ${subsection.status}\n`);
  
  await prisma.$disconnect();
}

testSubsectionNavigation().catch(console.error);
