import { View } from "@tarojs/components";
import { useState } from "react";

import ScrollListChat from "./components/ScrollListChat";
import ScrollList from "./components/ScrollList";


import CompanyList from '../CompanyList'
import { TEntItem } from "@/types/user";
import StyleFilter, {TListStyle} from '../StyleFilter'
import { useUserStore } from "@/store/userStore";
import EmptyData, { EmptyDataSubInfo, EmptyDataTitle } from "@/components/EmptyData";


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


  const renderScrollList = () => {
    if (!ent?.entId) {
      return <></>;
    }
    if(ent?.isExpired){
      return <EmptyData type="triangle">
        <EmptyDataTitle>100 份企业知识已暂停服务</EmptyDataTitle>
        <EmptyDataSubInfo>
          <View>你的企业会员已到期，建议联系企业管理员进行</View>
          <View>续费，以便恢复使用和正常对话支持。</View>
        </EmptyDataSubInfo>
      </EmptyData>
    }

    if (listStyle === "chat") {
      return <ScrollListChat setTotalCount={setTotalCount}  assistantOnly entId={ent.entId} />;
    }
    return <ScrollList setTotalCount={setTotalCount} entId={ent.entId} />;
  };

  return (
    <View className="h-full flex flex-col">
      <View className="pt-20 pb-20">
        <View className="px-16">
          <CompanyList setCurrentEnt={setEnt} currentEnt={ent}></CompanyList>
        </View>
        {(entList.length > 0 && !ent?.isExpired) && <StyleFilter checked={assistantOnly} setChecked={setAssistantOnly} listStyle={listStyle} setListStyle={setListStyle}>
          <View className="flex-1 text-12 leading-20 text-gray-4">
            共 {totalCount ?? 0} 个文件
          </View>
        </StyleFilter>}

      </View>

      {/* 知识库内容 */}
      {renderScrollList()}


    </View>
  );
};

export default Index;
