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";

interface SubComponents {
  Loading: typeof StaffSearchLoading;
}

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

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

  return <StaffSearch staff={staff} abilities={abilities}/>;
};

StaffSearchWrapper.Loading = StaffSearchLoading;

export default StaffSearchWrapper;
