'use client';

import { useEffect } from 'react';
import { useRouter } from 'next/navigation';
import { useAuthStore } from '@/stores/auth-store';
import { defaultDespachoPathForRole } from '@/components/despachos/despacho-subnav';

export default function DespachosIndex() {
  const router = useRouter();
  const role = useAuthStore(s => s.user?.role);
  const platformRoles = useAuthStore(s => s.user?.platformRoles);
  useEffect(() => {
    if (!role) return;
    router.replace(defaultDespachoPathForRole(role, platformRoles));
  }, [role, platformRoles, router]);
  return null;
}
