import { Stack, useRouter } from "expo-router";
import * as Notifications from "expo-notifications";
import { useEffect } from "react";

export default function Layout() {
  const router = useRouter();

  useEffect(() => {
    const sub = Notifications.addNotificationResponseReceivedListener((resp) => {
      const data: any = resp.notification.request.content.data;
      if (data?.type === "OFFER") router.push("/(provider)/offers");
      if (data?.type === "DEPOSIT_REQUIRED" && data?.bookingId) router.push(`/(client)/booking/${data.bookingId}/deposit`);
      if (data?.type === "BOOKING_CONFIRMED" && data?.bookingId) router.push(`/(client)/booking/${data.bookingId}/deposit`);
    });
    return () => sub.remove();
  }, []);

  return <Stack screenOptions={{ headerTitle: "Bùhlé" }} />;
}
