// src/components/AdminRoute.tsx
import React from 'react';
import { Navigate, Outlet } from 'react-router-dom';
import type { Profile } from '../types';

export interface AdminRouteProps {
  profile: Profile | null;
}

export const AdminRoute: React.FC<AdminRouteProps> = ({ profile }) => {
  // An admin is identified by the 'admin' role in their profile.
  const isAdmin = profile?.role === 'admin';

  if (!isAdmin) {
    return <Navigate to="/" replace />;
  }

  return <Outlet />;
};
