import { View } from "@tarojs/components";
import CardList from "@/components/list/card-list";
import CardListItem from "@/components/list/card-list-item";
import WemetaSwitch from "@/components/WemetaSwitch";

import IconArrow from "@/components/icon/icon-arrow";

import IconPageColor from "@/components/icon/icon-page-color";
import Taro from "@tarojs/taro";
import { useAgentStore, useAgentStoreActions } from "@/store/agentStore";

export default function Index() {
  const agentEdit = useAgentStore((state) => state.agentEdit);
  const agentCharacter = useAgentStore((state) => state.agentCharacter);
  const { editAgentCharacter, fetchAgent } = useAgentStoreActions();
  const handleSwitchChange = async (checked: boolean) => {
    if (!agentEdit?.agentId || !agentCharacter) {
      return;
    }

    await editAgentCharacter(agentEdit.agentId, {
      ...agentCharacter,
      enabledPersonalKb: checked,
    });
    fetchAgent(agentEdit.agentId);
  };



  if (!agentEdit || !agentEdit.isEnt) {
    return <></>;
  }

  return (
    <CardList>
      <CardListItem
        className="pl-16 pr-8"
        leftRenderer={IconPageColor}
      >
        <View className="text-14 py-18 font-medium leading-22">知识库</View>
      </CardListItem>
      <View className="">
        <View className="flex flex-col gap-12 px-16 pb-16">
          <View className="flex rounded-8 p-16 gap-16 bg-gray-1">
            <View className="flex-1">
              <View className="text-14 font-medium leading-22 text-black pb-2">
                个人知识
              </View>
              <View className="text-12 leading-20 text-gray-4">
                使用你上传的内容（如文档、链接等）作为智能体回答的知识基础。
              </View>
            </View>

            <View className="flex-center">
              <WemetaSwitch
                checked={agentEdit.enabledPersonalKb ?? true}
                onChange={(checked) => handleSwitchChange(checked)}
              ></WemetaSwitch>
            </View>
          </View>

          {/* <View className="flex rounded-8 p-16 bg-gray-3">
                  <View className="flex-1">
                    <View className="text-14 font-medium leading-22 text-black pb-2">
                      杭州茗视光眼科医院
                    </View>
                    <View className="text-12 leading-20 text-gray-4">
                      引用企业统一配置的知识库内容，如用于支持专业、统一的客户沟通。
                    </View>
                  </View>

                  <View className="flex-center">
                    <WemetaSwitch
                      checked={checked}
                      onChange={(checked) => handleSwitchChange(checked)}
                    ></WemetaSwitch>
                  </View>
                </View> */}
        </View>
      </View>
    </CardList>
  );
}
