import React, { useEffect, useContext } from "react";
import { UserManager } from "oidc-client-ts";
import {ConfigContext} from "../../ConfigProvider";
import { Spinner } from "../ui/misc";


const PopupCallback = () => {
    const { config } = useContext(ConfigContext);

    useEffect(() => {
        const userManager = new UserManager(config.OIDC_CONFIG);
        userManager.signinPopupCallback()
            .then(() => {
                window.close();
            })
            .catch((err) => {
                console.error("Popup callback error:", err);
                window.close();
            });
    }, [config]);

    return (
        <div className="flex min-h-screen items-center justify-center">
            <Spinner label="Processing" />
        </div>
    );
};

export default PopupCallback;