import { redirect } from 'next/navigation';
import { auth } from '@/auth';
import { isHRD, isSuperAdmin } from '@/lib/auth/roles';
import { OrganizerListing } from '@/features/organizers/components/organizer-listing';

export const metadata = {
  title: 'Dashboard: IT Organizers'
};

export default async function Page() {
  const session = await auth();

  if (
    !session?.user ||
    !isHRD({
      businessRole: session.user.businessRole,
      systemRole: session.user.systemRole,
      membershipRole: session.user.membershipRole,
      role: session.user.role
    })
  ) {
    redirect('/dashboard/overview');
  }

  return <OrganizerListing canManage={isSuperAdmin(session.user.systemRole)} />;
}
