import { FC, useEffect } from 'react'
import { updateProfile } from '../pages/profile/service/ProfileService'

declare global {
    interface Window {
        NAJVA: {
            getUserToken: () => Promise<string>
            najvaUserSubscribed: (najvaUserToken: string) => void
        }
    }
}
const NajvaToken: FC = () => {

    const handleNajvaToken = async () => {
        const userToken = await window.NAJVA?.getUserToken()
        if (userToken) {
            updateProfile({
                pushToken: userToken,
            })
        } else {
            console.log('userToken is null')
        }
    }

    useEffect(() => {
        handleNajvaToken()
        // window.NAJVA.najvaUserSubscribed = function (najvaUserToken) {
        //     console.log('najvaUserToken', najvaUserToken)
        // }
    }, [])

    return null
}

export default NajvaToken