import { fetchStaff, fetchTeamLeads } from "@/app/api/staff";
import React from "react";
import StaffSearch from "./StaffSearch";
import StaffSearchLoading from "./StaffSearchLoading";
import { Session, getServerSession } from "next-auth";
import { authOptions } from "@/config/authConfig";
import { fetchTeam } from "@/app/api/team";
import { fetchPositions } from "@/app/api/positions";
import { fetchGrades } from "@/app/api/grades";
import { MAINTAIN_USER } from "@/middleware";

interface SubComponents {
  Loading: typeof StaffSearchLoading;
}

interface SessionWithAbilities extends Session {
  abilities?: string[]
}

const StaffSearchWrapper: React.FC & SubComponents = async () => {
  const session = await getServerSession(authOptions) as SessionWithAbilities;
  const abilities = session.abilities!

  const staff = await fetchStaff();
  const teams = await fetchTeam();
  const grades = await fetchGrades();
  const positions = await fetchPositions();

  return <StaffSearch staff={staff} teams={teams} grades={grades} positions={positions} abilities={abilities}/>;
};

StaffSearchWrapper.Loading = StaffSearchLoading;

export default StaffSearchWrapper;
