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'


const Index = () => {
  const [listStyle, setListStyle] = useState<TListStyle>("chat");
  const [ent, setEnt] = useState<TEntItem|null>(null)
  const [assistantOnly, setAssistantOnly] = useState(false);

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

  return (
    <View className="px-16 h-full">
      <CompanyList setCurrentEnt={setEnt} currentEnt={ent}></CompanyList>

      <StyleFilter checked={assistantOnly} setChecked={setAssistantOnly} listStyle={listStyle} setListStyle={setListStyle}>
        <View className="flex-1 text-12 leading-20 text-gray-45">
            共 {ent?.knowledgeCnt ?? 0} 个文件
          </View>
      </StyleFilter>
      
      {/* 知识库内容 */}
      {renderScrollList()}
        
      
    </View>
  );
};

export default Index;
