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

const SetupStepperPage = lazyRouteComponent(
  () => import('@/features/onboard/setup-stepper-page'),
  'SetupStepperPage'
);

export const Route = createFileRoute('/onboard/setup')({
  beforeLoad: ({ context }) => {
    const hasSession = context.auth.isAuthenticated;
    const hasPendingSignup = Boolean(sessionStorage.getItem('pending-signup-email'));

    if (!hasSession && !hasPendingSignup) {
      throw redirect({ to: '/login' });
    }
  },
  component: SetupStepperPage,
});
