"use server";

import getMe from "@/lib/getMe";
import { redirect } from "next/navigation";
import PhotoGallery from "./_media";
import hasPermissions from "@/lib/hasPermissions";

export default async function Page() {
	const me = await getMe();
	if (
		!me ||
		me.status === "Error" ||
		!me.data ||
		!hasPermissions(me.data.roles, { media: ["get"] } as const).all
	) {
		redirect("/dashboard");
	}

	return <PhotoGallery user={me.data} />;
}
