import React__default, { useRef, useEffect } from 'react';
import { readB2BInternals } from '../../utils/internal.mjs';
import { AdminPortalWrapper } from '../AdminPortalWrapper.mjs';
import { FeatureStateComponent } from '../utils/FeatureStateComponent.mjs';
import { getFeatureState } from '../utils/getFeatureState.mjs';
import { useAdminPortalConfig } from '../utils/useAdminPortalConfig.mjs';
import { useRbac } from '../utils/useRbac.mjs';
import { useSelf } from '../utils/useSelf.mjs';
import { SSOConnectionDetailsScreen } from './SSOConnectionDetailsScreen.mjs';
import { SSOConnectionsScreen } from './SSOConnectionsScreen.mjs';
import { SSONewConnectionConfigureScreen } from './SSONewConnectionConfigureScreen.mjs';
import { SSONewConnectionScreen } from './SSONewConnectionScreen.mjs';
import { SsoRouterProvider, SsoRouter } from './SSORouter.mjs';

const routeMap = {
    connectionDetails: SSOConnectionDetailsScreen,
    connectionsList: SSOConnectionsScreen,
    newConnection: SSONewConnectionScreen,
    newConnectionConfigure: SSONewConnectionConfigureScreen
};
const initialRoute = {
    screen: 'connectionsList'
};
const Content = ()=>{
    const { data: canGetSso } = useRbac('stytch.sso', 'get');
    const { self, fromCache } = useSelf();
    const { data: adminPortalConfig, error: adminPortalConfigError } = useAdminPortalConfig({
        shouldFetch: !!self
    });
    const isSsoEnabled = adminPortalConfig?.sso_config.sso_enabled;
    const ssoState = getFeatureState({
        self,
        fromCache,
        adminPortalConfigError: adminPortalConfigError,
        isFeatureEnabled: isSsoEnabled,
        hasPermission: canGetSso
    });
    return /*#__PURE__*/ React__default.createElement(FeatureStateComponent, {
        featureState: ssoState,
        notLoggedInValue: 'Please log in to manage SSO.',
        errorValue: 'SSO Connections could not be loaded. Please contact your admin if you think this is a mistake.',
        featureNotEnabledValue: 'SSO Connections are not supported. Please contact your admin if you think this is a mistake.',
        noPermissionValue: 'You do not have permission to view SSO Connections. Please contact your admin if you think this is a mistake.'
    }, /*#__PURE__*/ React__default.createElement(SsoRouterProvider, {
        initialRoute: initialRoute
    }, /*#__PURE__*/ React__default.createElement(SsoRouter, {
        routeMap: routeMap
    })));
};
const AdminPortalSSOContainer = (props)=>{
    // only send an event on initial mount, even if the client changes
    const initialClient = useRef(props.client);
    useEffect(()=>{
        readB2BInternals(initialClient.current).networkClient.logEvent({
            name: 'render_b2b_admin_portal_sso',
            details: {}
        });
    }, []);
    return /*#__PURE__*/ React__default.createElement(AdminPortalWrapper, {
        options: props
    }, /*#__PURE__*/ React__default.createElement(Content, null));
};

export { AdminPortalSSOContainer, Content };
//# sourceMappingURL=AdminPortalSSOContainer.mjs.map
