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 { useRbac } from '../utils/useRbac.mjs';
import { useSelf } from '../utils/useSelf.mjs';
import { MemberDetailsScreen } from './MemberDetailsScreen.mjs';
import { MemberListScreen } from './MemberListScreen.mjs';
import { MemberManagementRouterProvider, MemberManagementRouter } from './MemberManagementRouter.mjs';

const routeMap$3 = {
    membersList: MemberListScreen,
    memberDetails: MemberDetailsScreen
};
const initialRoute$3 = {
    screen: 'membersList'
};
const Content$3 = ()=>{
    const { self, fromCache } = useSelf();
    const { data: canSearchMembers } = useRbac('stytch.member', 'search');
    const memberState = getFeatureState({
        self,
        fromCache,
        adminPortalConfigError: undefined,
        isFeatureEnabled: true,
        hasPermission: canSearchMembers
    });
    return /*#__PURE__*/ React__default.createElement(FeatureStateComponent, {
        featureState: memberState,
        notLoggedInValue: 'Please log in to manage Members.',
        errorValue: 'Members could not be loaded. Please contact your admin if you think this is a mistake.',
        featureNotEnabledValue: 'Member Management is not supported. Please contact your admin if you think this is a mistake.',
        noPermissionValue: 'You do not have permission to manage Members. Please contact your admin if you think this is a mistake.'
    }, /*#__PURE__*/ React__default.createElement(MemberManagementRouterProvider, {
        initialRoute: initialRoute$3
    }, /*#__PURE__*/ React__default.createElement(MemberManagementRouter, {
        routeMap: routeMap$3
    })));
};
const AdminPortalMemberManagementContainer = (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_member_management',
            details: {}
        });
    }, []);
    return /*#__PURE__*/ React__default.createElement(AdminPortalWrapper, {
        options: props
    }, /*#__PURE__*/ React__default.createElement(Content$3, null));
};

export { AdminPortalMemberManagementContainer, Content$3 as Content };
//# sourceMappingURL=AdminPortalMemberManagementContainer.mjs.map
