import Head from "next/head";
import {
	AdminDashboard,
	UserDashboard,
} from "~/components/area-riservata/dashboard";
import { AreaRiservataLayout } from "~/components/Layout";
import type { NextPageWithLayout } from "~/pages/_app";
import { useTranslation } from "~/providers/I18nProvider";
import { useEnforcedSession } from "~/providers/SessionProvider";

/**
 * Pagina principale dell'area riservata: /area-riservata/dashboard
 * Mostra la dashboard amministrativa o utente a seconda del ruolo.
 */
const Dashboard: NextPageWithLayout = () => {
	const { t } = useTranslation();
	const session = useEnforcedSession();

	return (
		<>
			<Head>
				<title>{t.heads.area_riservata_titolo}</title>
				<meta content={t.heads.area_riservata_description} name="description" />
			</Head>

			{session.user.isAdmin ? (
				<AdminDashboard />
			) : (
				<UserDashboard userId={session.user.id} />
			)}
		</>
	);
};

export default Dashboard;

export async function getServerSideProps() {
	return {
		props: {},
	};
}

Dashboard.getLayout = function getLayout(page) {
	return <AreaRiservataLayout>{page}</AreaRiservataLayout>;
};
