import { fetchAllTasks, fetchTaskTemplates } from "@/app/api/tasks";
import CreateDepartment from "./CreateDepartment";
import { fetchTeamLeads } from "@/app/api/staff";
import { DepartmentResult, fetchDepartmentDetails, fetchDepartments } from "@/app/api/departments";

type CreateDepartmentProps = { isEdit: false };
interface EditDepartmentProps {
  isEdit: true;
  departmentId?: string;
}

type Props = CreateDepartmentProps | EditDepartmentProps;

const CreateDepartmentWrapper: React.FC<Props> = async (props) => {
  
  const departmentInfo = props.isEdit
  ? await fetchDepartmentDetails(props.departmentId!)
  : undefined;

  const [ department ] = await Promise.all([fetchDepartments()])

  return (
    <CreateDepartment depCodes={Boolean(departmentInfo) ? department.map(d => d.code.toLowerCase().trim()).filter(code => code !== departmentInfo?.code.toLowerCase().trim()) : department.map(d => d.code.toLowerCase().trim())} isEdit department={departmentInfo}
    />
  );
};

export default CreateDepartmentWrapper;
