import { useEffect } from 'react';
import { Redirect } from 'expo-router';

import { AppRouteStack } from '../../src/app-navigation/AppRouteStack';
import { messageManager, useAuthStore } from '../../src/stores';

export default function AppLayout() {
  const isAuthenticated = useAuthStore((s) => s.isAuthenticated);

  useEffect(() => {
    messageManager.initialize();
  }, []);

  if (!isAuthenticated) {
    return <Redirect href="/login" />;
  }

  return <AppRouteStack />;
}
