"use client";
import { useNavigation } from "@core/app/hooks/goto";
import { checkUserPhone } from "@core/Services/Session.Login";
import { useConfirmStore } from "@core/Store/Confirm.Store";
import { useSessionStore } from "@core/Store/Sesion.Store";
import { useEffect } from "react";

export default function CheckUserPhone() {
    const confirm = useConfirmStore();
    const SessionInfo = useSessionStore();
    const { goTo } = useNavigation();

    const checkIfPhoneIsSaved = () => {
        if (!SessionInfo.userId) return;

        checkUserPhone({
            sessionUser: SessionInfo.userId,
        }).then((response) => {
            if (!response) {
                confirm.show(
                    "Por favor, completa tu número de teléfono para que podamos informarte sobre cualquier novedad relacionada con tus reservas.",
                    () => {
                        goTo("/user/profile/edit");
                    },
                    () => {}
                );
            }
        });
    };

    useEffect(() => {
        checkIfPhoneIsSaved();
    }, [SessionInfo.userId]);

    return <></>;
}
