import React from "react";
import AppNavigator from "./navigation/app-navigator";
import { ClientProvider, useAuthHeader } from "./graphql/client";
import { DEV_USER_ID } from "@env";

const SetAuthHeaderBasedOnEnv = () => {
	const { setAuthHeader } = useAuthHeader();

	React.useEffect(() => {
		if (DEV_USER_ID) {
			setAuthHeader({ key: "user_id", value: DEV_USER_ID });
		}
	}, [setAuthHeader]);

	return null;
};

const App: React.FC = () => {
	return (
		<ClientProvider>
			<SetAuthHeaderBasedOnEnv />
			<AppNavigator />
		</ClientProvider>
	);
};

export default function Root() {
	return (
		<React.StrictMode>
			<App />
		</React.StrictMode>
	);
}
