/**
 * 全选的逻辑
 *
 * 点击全选的话
 * 如果页面是选择部门的话，取上一级部门的id，调根据部门获取人员接口获取人员即可
 * 如果页面是选择人员的话，获取当前页面所有人员
 * 然后添加到selectedList中
 *
 * 判断选中状态
 * 获取上级部门的count和部门id集合
 * 比较selectedList的人员存在部门id集合的总数和count
 * 如果等于话就是选中，小于就是半选，总数为0就是未选
 */
import {
  // TEmployeeData,
  // TListRenderType,
  TRenderData,
  TRenderDataNoLetter,
} from "../../type";
const useChooseAll = () => {
  //判断ids里是否包含了data里所有的员工id
  // const judgeEmployeeInSelectedList = (data: TEmployeeData[], ids: string[]): boolean => {
  //   let order = 0;
  //   let bool = true;
  //   while (data?.length > order) {
  //     if (!ids.includes(data[order].id)) return false;
  //     order++;
  //   }
  //   return bool;
  // };

  //判断是否显示全选
  const showCheckAll = (stack: TRenderData[][]): boolean => {
    const isFirstPage = stack.length === 1;
    const currentPageHasData = stack[stack?.length - 1]?.length > 0;
    return !isFirstPage && currentPageHasData;
  };

  const isAllChecked = (data: TRenderData[]) => {
    // if (renderType === "employee") {
    //   return judgeEmployeeInSelectedList(data as TEmployeeData[], selectedEmployeeIds);
    // } else if (renderType === "department") {
    //   return (data as TEmployeeDataAddStatus[]).every(
    //     (res: TEmployeeDataAddStatus) => res.checkedStatus === "checked"
    //   );
    // }
    return (data as TRenderDataNoLetter[]).every(
      (res: TRenderDataNoLetter) => res.checkedStatus === "checked",
    );
  };

  return {
    isAllChecked,
    showCheckAll,
  };
};

export default useChooseAll;
