import { jsx as _jsx } from "react/jsx-runtime";
/*
 * Copyright (c) 2023-2025 Datalayer, Inc.
 * Distributed under the terms of the Modified BSD License.
 */
import { useEffect } from 'react';
import { CenteredSpinner } from '../../components/display/index.js';
import { useIAMStore } from '../../state/index.js';
import { useToast, useIAM } from '../../hooks/index.js';
const ExternalTokenSilentLoginRoute = (props) => {
    const { message } = props;
    const { loginAndNavigate } = useIAM();
    const { logout, checkIAMToken, externalToken } = useIAMStore();
    const { enqueueToast } = useToast();
    useEffect(() => {
        if (externalToken) {
            loginAndNavigate(externalToken, logout, checkIAMToken)
                .catch(error => {
                console.debug('Failed to login with the provided token.', error);
                enqueueToast('Failed to login with the provided token.', {
                    variant: 'error',
                });
            })
                .finally(() => {
                enqueueToast('Runtimes are available.', { variant: 'success' });
            });
        }
    }, [externalToken]);
    return _jsx(CenteredSpinner, { size: "small", message: message });
};
export const ExternalTokenSilentLogin = (props) => {
    // No navigation provider needed anymore - auto-detection works without it
    return _jsx(ExternalTokenSilentLoginRoute, { ...props });
};
export default ExternalTokenSilentLogin;
