

import { useEffect, useState } from "react";
import { useScriptService } from "@/app/service/Interaction/ScriptService";
import { useSearchParams } from 'next/navigation';

export const useScriptData = () => {
  const searchParams = useSearchParams();
  const projectId = searchParams.get('episodeId') || '';

  const {
    loading, // 加载状态
    synopsis, //故事梗概
    categories, //故事分类
    protagonist, //主角
    incitingIncident, //激励事件
    problem, //问题与新目标
    conflict, //冲突与障碍
    stakes, //赌注
    characterArc, //人物弧线完成
    planId, //计划ID
    aiOptimizing, //AI优化要求
    scriptBlocksMemo, // 渲染数据
    initializeFromProject,
  } = useScriptService();

  const [scriptData, setScriptData] = useState<any>(null);

  // 初始化剧本
  useEffect(() => {
    initializeFromProject(projectId);
  }, []);

  // 监听剧本加载完毕
  useEffect(() => {
    if (!loading) {
      console.log('scriptBlocksMemo', scriptBlocksMemo);
    }
  }, [loading, scriptBlocksMemo]);

  return {
    scriptData
  }
}