import { Navigate } from 'react-router-dom';
import { useAccount } from '@/lib/AccountContext';
import LoadingPanel from '@/components/workshop/LoadingPanel';

// Root redirect — sends each role to its home after auth resolves.
export default function RoleRouter() {
  const { account, loading, homePath } = useAccount();
  if (loading || !account) return <LoadingPanel label="Preparing your workspace" />;
  if (['Suspended', 'Archived', 'Access Revoked'].includes(account.account_status)) return <Navigate to="/login" replace />;
  return <Navigate to={homePath} replace />;
}