import { View } from "@tarojs/components";
import EmptyData, {EmptyDataTitle, EmptyDataSubInfo} from "@/components/EmptyData";


import StyleFilter, { TListStyle } from "../StyleFilter";
import { useRef, useState } from "react";

import CorrectionListChat from "./components/CorrectionListChat";
import CorrectionList from "./components/CorrectionList";

import { TEntItem } from "@/types/user";

import CompanyList from "../CompanyList";

const Index = () => {
  const [listStyle, setListStyle] = useState<TListStyle>("chat");
  const [ent, setEnt] = useState<TEntItem | null>(null);
  const [totalCount, setTotalCount] = useState<number>(0);

  const extraEnt: TEntItem[] = [
    {
      entName: "个人知识库",
      entId: undefined,
      expireTime: "0",
      isExpired: false,
      knowledgeCnt: 0,
    },
  ];

  // 渲染数据内容
  const renderScrollContent = () => {
    if (listStyle === "chat") {
      return (
        <CorrectionListChat
          setTotalCount={setTotalCount}
          entId={ent?.entId}
        />
      );
    }
    return (
      <CorrectionList
        setTotalCount={setTotalCount}
        entId={ent?.entId}
      />
    );
  };
  console.log("渲染纠错模块", totalCount);
  // 渲染主体
  const renderEmpty = () => {
    // 空数据
    if (!totalCount) {
      return (
        <EmptyData type={"whiteboard"}>
          <EmptyDataTitle>还没有纠正过的内容</EmptyDataTitle>
          <EmptyDataSubInfo>
            <View>当你发现 AI 理解有误的知识点并进行修改后，</View>
            <View>会汇总在这里，用于优化AI回答。</View>
          </EmptyDataSubInfo>
        </EmptyData>
      );
    }
    return <></>;
  };

  return (
    <View className="h-full flex flex-col">
      <View className="pt-20 pb-20">
        <View className="px-16">
          <CompanyList
            currentEnt={ent}
            setCurrentEnt={setEnt}
            extraEnt={extraEnt}
          ></CompanyList>
        </View>
        <StyleFilter listStyle={listStyle} setListStyle={setListStyle}>
          <View className="flex-1 text-12 leading-20 text-gray-4">
            共纠正 {totalCount ?? 0} 条问答
          </View>
        </StyleFilter>
      </View>
      {renderEmpty()}
      {renderScrollContent()}
    </View>
  );
};

export default Index;
