import { DashboardPage } from "@/components/layout/dashboard-page";
import { getDashboardRole } from "@/lib/auth/dashboard-role";
import { LocationDirectory } from "@/features/locations/location-directory";
import {
  getLocationDirectoryPageData,
  getLocationMapConfig,
} from "@/features/locations/location-server";

export default async function DashboardRoute(props: {
  searchParams: Promise<Record<string, string | string[] | undefined>>;
}) {
  const query = await props.searchParams;
  const role = await getDashboardRole(
    Array.isArray(query.role) ? query.role[0] : query.role,
  );
  const data = await getLocationDirectoryPageData(role);
  const mapConfig = role === "admin" ? getLocationMapConfig() : null;
  return (
    <DashboardPage role={role}>
      <LocationDirectory data={data} mapConfig={mapConfig} />
    </DashboardPage>
  );
}
