import { useEffect } from 'react';
import { useDidShow } from '@tarojs/taro';
import { useAgentStore, useAgentStoreActions } from '@/store/agentStore';

/**
 * 聊天智能体数据管理 Hook
 * 负责智能体数据的获取和管理
 */
export const useChatAgent = (agentId: string, isVisitor?: string): {
  agent: any;
  isVisitor: boolean;
} => {
  const { fetchAgent, fetchAgentProfile } = useAgentStoreActions();

  // 获取智能体数据
  const agent = useAgentStore((state) => {
    if (isVisitor === "true") {
      return state.agentProfile;
    }
    return state.agent;
  });

  // 根据是否为访客模式获取不同的智能体数据
  useEffect(() => {
    if (agentId) {
      if (isVisitor === "true") {
        fetchAgentProfile(agentId);
      } else {
        fetchAgent(agentId);
      }
    }
  }, [agentId, isVisitor, fetchAgent, fetchAgentProfile]);

  return {
    agent,
    isVisitor: isVisitor === "true",
    // 可以添加更多智能体相关的状态和方法
  };
};
