import { View } from "@tarojs/components";
import { useModalStore } from "@/store/modalStore";
import Taro from "@tarojs/taro";
export const useConfirms = () => {
  const { showModal } = useModalStore((state) => state.actions);
  // 回退确认
  const confirmNavBack = async (): Promise<boolean> => {
    return await new Promise((resolve)=> {
      showModal({
        content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">确定放弃创建智能体？</View>,
        confirmText: "我再想想",
        onConfirm() {
          Taro.showTabBar().catch(()=> {});
          resolve(true)
        },
        onCancel() {
          Taro.showTabBar().catch(()=> {});
          resolve(false)
        },
      })
    })
  }


  const confirmSaveAvatar = async ():Promise<boolean> => {
    return await new Promise((resolve)=> {
      showModal({
        content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">为你的智能体设置一个形象吧</View>,
        confirmText: "继续设置",
        cancelText: "暂时不设置",
        onConfirm() {
          Taro.showTabBar().catch(()=> {});
          resolve(true)
        },
        onCancel() {
          Taro.showTabBar().catch(()=> {});
          resolve(false)
        },
      })
    })
  }
  // 提示先创建智能体
  const confirmCreateAgent = async ():Promise<boolean> => {
    return await new Promise((resolve)=> {
      showModal({
        content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">在进行设置前需要先创建智能体</View>,
        confirmText: "创建",
        cancelText: "不创建",
        onConfirm() {
          Taro.showTabBar().catch(()=> {});
          resolve(true)
        },
        onCancel() {
          Taro.showTabBar().catch(()=> {});
          resolve(false)
        },
      })
    })
  }

  const confirmEditWebsite = async ():Promise<boolean> => {
    return await new Promise((resolve)=> {
      showModal({
        content: <View className="flex items-center flex-col justify-center">
              <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">已创建智能体，继续编辑微官网？</View>
              <View className="text-gray-5 text-14 leading-22" style="max-width: 280px;">让商务伙伴在访问你的智能体时，可以更深入的了解你的企业和业务</View>
          </View>,
        confirmText: "编辑微官网",
        cancelText: "暂时不编辑",
        onConfirm() {
          Taro.showTabBar().catch(()=> {});
          resolve(true)
        },
        onCancel() {
          Taro.showTabBar().catch(()=> {});
          resolve(false)
        },
      })
    })
  }

  const confirmPersonalityAndGreeting = async (personality?: string, greeting?: string):Promise<boolean> => {
    const personalityText =  (!personality || personality?.length <= 0)  ? '人设': ''
    const greetingText =  (!greeting || greeting?.length <= 0)  ? '、开场白': ''
    return await new Promise((resolve)=> {
      showModal({
        content: <View className="text-black font-pingfangSCMedium font-medium text-14 leading-22">还没有设置{`${personalityText} ${greetingText}`}</View>,
        confirmText: "自动生成",
        cancelText: "暂不生成",
        onConfirm() {
          Taro.showTabBar().catch(()=> {});
          resolve(true)
        },
        onCancel() {
          Taro.showTabBar().catch(()=> {});
          resolve(false)
        },
      })
    })
  }


  return {
    confirmEditWebsite,
    confirmNavBack,
    confirmSaveAvatar,
    confirmCreateAgent,
    confirmPersonalityAndGreeting,
  }
}
