import { authOptions } from "@/config/authConfig";
import { getServerSession, Session } from "next-auth";
import DashboardPage from "./DashboardPage";
import { Typography } from "@mui/material";
import { I18nProvider, getServerI18n } from "@/i18n";
import DashboardLoading from "./DashboardLoading";
import { fetchEscalationLogsByUser } from "@/app/api/escalation";
// import { fetchIqcLogByUser } from "@/app/api/dashboard";

// export type SessionWithAbilities = {
//     abilities: string[]
// } & Session | null

interface SubComponents {
  Loading: typeof DashboardLoading;
}

type Props = {
  searchParams: { [key: string]: string | string[] | undefined };
};

const DashboardWrapper: React.FC<Props> & SubComponents = async ({
  searchParams,
}) => {
  const { t } = await getServerI18n("dashboard");
  //   const session: SessionWithAbilities = await getServerSession(authOptions)
  // const [iqcLog] = await Promise.all([
  //   fetchIqcLogByUser()
  // ])

  const [escalationLogs] = await Promise.all([
    fetchEscalationLogsByUser()
  ])
  
  return (
    <>
      <Typography variant="h4">{t("Dashboard")}</Typography>
      <DashboardPage
        escalationLogs={escalationLogs}
        // iqc={iqcLog}
      // abilities={session ? session?.abilities : []}
      />
    </>
  );
};
DashboardWrapper.Loading = DashboardLoading;

export default DashboardWrapper;
