import { DarkTheme, DefaultTheme, ThemeProvider } from '@react-navigation/native';
import { useFonts } from 'expo-font';
import { Stack } from 'expo-router';
import { StatusBar } from 'expo-status-bar';
import 'react-native-reanimated';

import { useColorScheme } from '@/hooks/useColorScheme';
import { KindeAuthProvider } from '@kinde/expo';

export default function RootLayout() {
  const colorScheme = useColorScheme();
  const [loaded] = useFonts({
    SpaceMono: require('../assets/fonts/SpaceMono-Regular.ttf'),
  });

  if (!loaded) {
    // Async font loading only occurs in development.
    return null;
  }

  return (
    <KindeAuthProvider
      config={{
        domain: "https://tinycloset.kinde.com",  // e.g https://mybusiness.kinde.com
        clientId: "bdcd58c0687a44e6b5e09802c2f99172",
      }}
      // All callbacks are optional
      callbacks={{
        onSuccess: async (token, state, context) => {
          console.log("onSuccess", token, state, context);
        },
        onError: (error) => {
          console.log("onError", error);
        },
        onEvent: async (event, state, context) => {
          console.log("onEvent", event, state, context);
        },
      }}
    >
      < ThemeProvider value={colorScheme === 'dark' ? DarkTheme : DefaultTheme
      }>
        <Stack>
          <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
          <Stack.Screen name="+not-found" />
        </Stack>
        <StatusBar style="auto" />
      </ThemeProvider >
    </KindeAuthProvider>
  );
}
