import { Stack } from 'expo-router';
import { StatusBar } from 'expo-status-bar';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { SafeAreaProvider } from 'react-native-safe-area-context';

import { ErrorBoundary } from '../components/ErrorBoundary';

// Force-resolve @chat-app/shared at boot so Metro packaging issues
// surface during the very first dev-client load instead of mid-Phase-1.
// Reference the export so tree-shaking can't drop it.
import { sharedSmoke } from '../lib/sharedSmoke';
void sharedSmoke;

// Root layout for every Expo Router screen. Provider stack order:
//   GestureHandlerRootView  — required by gesture-driven libs (BottomSheet,
//                             swipeable rows, drawer nav). Must be the
//                             outermost so gesture state is global.
//   SafeAreaProvider        — feeds notch / status-bar insets to children.
//   ErrorBoundary           — last line of defence for render errors.
//   Stack                   — Expo Router's screen registry.
export default function RootLayout() {
  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <SafeAreaProvider>
        <ErrorBoundary>
          <StatusBar style="auto" />
          <Stack screenOptions={{ headerShown: false }}>
            <Stack.Screen name="index" />
            <Stack.Screen name="(app)" />
          </Stack>
        </ErrorBoundary>
      </SafeAreaProvider>
    </GestureHandlerRootView>
  );
}
