import { createFileRoute, redirect } from '@tanstack/react-router';

export const Route = createFileRoute('/_app/_authenticated/admin')({
  beforeLoad: ({ context, location }) => {
    if (!context.auth.isAuthenticated) {
      throw redirect({
        to: '/login',
        search: { redirect: location.href },
      });
    }

    if (context.auth.user?.role !== 'super_admin') {
      throw redirect({ to: '/' });
    }
  },
});
