import { useWindowSize } from '@vueuse/core';

export default function (url: string, popupWidth: number, popupHeight: number, callback: () => void) {
    // Open window in center
    const { width, height } = useWindowSize();
    const top = (height.value - popupHeight) / 2;
    const left = (width.value - popupWidth) / 2;

    const popupWindow = window.open(
        url,
        'Auth0',
        `status=no,height=${popupHeight},width=${popupWidth},top=${top},left=${left},resizable=no,toolbar=no,menubar=no,scrollbars=no,location=no,directories=no`
    );

    // Check if popup is closed
    const interval = setInterval(() => {
        if (popupWindow.closed) {
            clearInterval(interval);

            // Callback when popup is closed
            callback();
        }
    }, 500);
}
