/*
 * 루트 레이아웃 — AuthProvider + 네이티브 스택 내비.
 * 모바일은 MDI 미적용(단일 화면 포커스, design.md §2-2).
 */
import { Stack } from 'expo-router';
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { AuthProvider } from '../context/AuthContext';
import { LanguageProvider } from '../context/LanguageContext';
import { SecureScreenProvider } from '../context/SecureScreenContext';
import '../lib/i18n'; // i18next 동기 초기화(최초 렌더 전)
import { colors } from '../theme';

function RootStack() {
  const { t } = useTranslation();
  return (
    <Stack
      screenOptions={{
        headerStyle: { backgroundColor: colors.white },
        headerTintColor: colors.neutral900,
        headerTitleStyle: { fontWeight: '600' },
        contentStyle: { backgroundColor: colors.neutral050 },
      }}
    >
      <Stack.Screen name="index" options={{ headerShown: false }} />
      <Stack.Screen name="login" options={{ headerShown: false }} />
      <Stack.Screen name="register" options={{ title: t('nav.register') }} />
      <Stack.Screen name="forgot-password" options={{ title: t('nav.forgotPassword') }} />
      <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
      <Stack.Screen name="(visitor)" options={{ headerShown: false }} />
      <Stack.Screen name="profile" options={{ title: t('nav.profile') }} />
      <Stack.Screen name="checklist" options={{ title: t('nav.checklist') }} />
      <Stack.Screen name="inspection" options={{ title: t('nav.inspection') }} />
      <Stack.Screen name="tickets/index" options={{ title: t('nav.ticketsIndex') }} />
      <Stack.Screen name="tickets/select" options={{ title: t('nav.ticketsSelect') }} />
    </Stack>
  );
}

export default function RootLayout() {
  return (
    <GestureHandlerRootView style={{ flex: 1 }}>
      <SafeAreaProvider>
        <LanguageProvider>
          <AuthProvider>
            <SecureScreenProvider>
              <StatusBar style="dark" />
              <RootStack />
            </SecureScreenProvider>
          </AuthProvider>
        </LanguageProvider>
      </SafeAreaProvider>
    </GestureHandlerRootView>
  );
}
