import React from "react";
import EditUser from "./EditUser";
import EditUserLoading from "./EditUserLoading";
// import { fetchTeam, fetchTeamLeads } from "@/app/api/Team";
import { useSearchParams } from "next/navigation";
import { fetchTeam, fetchTeamDetail } from "@/app/api/team";
import { fetchStaff } from "@/app/api/staff";
import { fetchPwRules, fetchUser, fetchUserDetail } from "@/app/api/user";
import { searchParamsProps } from "@/app/utils/fetchUtil";
import { fetchUserDetails } from "@/app/api/user/actions";
import { fetchAuth } from "@/app/api/group/actions";

interface SubComponents {
  Loading: typeof EditUserLoading;
}

const EditUserWrapper: React.FC<searchParamsProps> & SubComponents = async ({
  searchParams,
}) => {
  const id = parseInt(searchParams.id as string);
  const [pwRule, user, auths] = await Promise.all([
    fetchPwRules(),
    fetchUserDetails(id),
    fetchAuth("user", id),
  ]);

  return <EditUser user={user.data} rules={pwRule} auths={auths.records} />;
};

EditUserWrapper.Loading = EditUserLoading;

export default EditUserWrapper;
