import OpenIMSDK from "@openim/rn-client-sdk";
import {
  DarkTheme,
  DefaultTheme,
  ThemeProvider,
} from "@react-navigation/native";
import { Stack } from "expo-router";
import { StatusBar } from "expo-status-bar";
import RNFS from "react-native-fs";
import "react-native-reanimated";
import "../global.css";

import { useColorScheme } from "@/hooks/use-color-scheme";

export const unstable_settings = {
  anchor: "(tabs)",
};

export default function RootLayout() {
  const colorScheme = useColorScheme();

  RNFS.mkdir(RNFS.DocumentDirectoryPath + "/tmp");

  OpenIMSDK.initSDK({
    apiAddr: "https://openim-api.riwsan.com/api",
    wsAddr: "wss://openim-api.riwsan.com/msg_gateway",
    dataDir: RNFS.DocumentDirectoryPath + "/tmp",
    logFilePath: RNFS.DocumentDirectoryPath + "/tmp",
    logLevel: 5,
    isLogStandardOutput: true,
  });

  return (
    <ThemeProvider value={colorScheme === "dark" ? DarkTheme : DefaultTheme}>
      <Stack>
        <Stack.Screen name="(tabs)" options={{ headerShown: false }} />
        <Stack.Screen
          name="modal"
          options={{ presentation: "modal", title: "Modal" }}
        />
      </Stack>
      <StatusBar style="auto" />
    </ThemeProvider>
  );
}
