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 { SCIMConnectionDetailsScreen } from './SCIMConnectionDetailsScreen.mjs';
import { SCIMNewConnectionConfigureScreen } from './SCIMNewConnectionConfigureScreen.mjs';
import { SCIMNewConnectionScreen } from './SCIMNewConnectionScreen.mjs';
import { ScimRouterProvider, ScimRouter } from './SCIMRouter.mjs';
import { SCIMScreen } from './SCIMScreen.mjs';

const routeMap$2 = {
    scimConnection: SCIMScreen,
    newConnection: SCIMNewConnectionScreen,
    newConnectionConfigure: SCIMNewConnectionConfigureScreen,
    scimConnectionDetails: SCIMConnectionDetailsScreen
};
const initialRoute$2 = {
    screen: 'scimConnection'
};
const Content$2 = ()=>{
    const { self, fromCache } = useSelf();
    const { error: adminPortalConfigError, data: adminPortalConfig } = useAdminPortalConfig({
        shouldFetch: !!self
    });
    const isScimEnabled = adminPortalConfig?.scim_config.scim_enabled;
    const { data: canGetScim } = useRbac('stytch.scim', 'get');
    const scimState = getFeatureState({
        self,
        fromCache,
        adminPortalConfigError,
        isFeatureEnabled: isScimEnabled,
        hasPermission: canGetScim
    });
    return /*#__PURE__*/ React__default.createElement(FeatureStateComponent, {
        featureState: scimState,
        notLoggedInValue: 'Please log in to manage SCIM.',
        errorValue: 'SCIM could not be loaded. Please contact your admin if you think this is a mistake.',
        featureNotEnabledValue: 'SCIM Connections are not supported. Please contact your admin if you think this is a mistake.',
        noPermissionValue: 'You do not have permission to view SCIM Connections. Please contact your admin if you think this is a mistake.'
    }, /*#__PURE__*/ React__default.createElement(ScimRouterProvider, {
        initialRoute: initialRoute$2
    }, /*#__PURE__*/ React__default.createElement(ScimRouter, {
        routeMap: routeMap$2
    })));
};
const AdminPortalSCIMContainer = (props)=>{
    const initialClient = useRef(props.client);
    // only send an event on initial mount, even if the client changes
    useEffect(()=>{
        readB2BInternals(initialClient.current).networkClient.logEvent({
            name: 'render_b2b_admin_portal_scim',
            details: {}
        });
    }, []);
    return /*#__PURE__*/ React__default.createElement(AdminPortalWrapper, {
        options: props
    }, /*#__PURE__*/ React__default.createElement(Content$2, null));
};

export { AdminPortalSCIMContainer, Content$2 as Content };
//# sourceMappingURL=AdminPortalSCIMContainer.mjs.map
