// Custom entry point. The FCM background handler must be registered in the very
// first module that loads — before the router/app mounts — so it reliably fires
// when the app is backgrounded or fully quit. Registering it here (rather than in
// app/_layout.tsx) is what react-native-firebase requires for the killed state.
import messaging from '@react-native-firebase/messaging';
import notifee, { AndroidImportance } from '@notifee/react-native';

messaging().setBackgroundMessageHandler(async (remoteMessage) => {
    const title = remoteMessage.data?.title;
    const body = remoteMessage.data?.body;
    if (!title && !body) return;

    const channelId = await notifee.createChannel({
        id: 'default',
        name: 'General',
        importance: AndroidImportance.HIGH,
    });

    await notifee.displayNotification({
        title,
        body,
        android: { channelId, pressAction: { id: 'default' } },
    });
});

// Hand off to expo-router, which mounts app/_layout.tsx and the routes.
import 'expo-router/entry';
