import React__default, { useRef, useEffect } from 'react';
import { readB2BInternals } from '../../utils/internal.mjs';
import { AdminPortalWrapper } from '../AdminPortalWrapper.mjs';
import { useAdminPortalOrgUIConfig } from '../StytchClientContext.mjs';
import { FeatureStateComponent } from '../utils/FeatureStateComponent.mjs';
import { getFeatureState } from '../utils/getFeatureState.mjs';
import { useAdminPortalConfig } from '../utils/useAdminPortalConfig.mjs';
import { useSelf } from '../utils/useSelf.mjs';
import { OrgSettingsRouterProvider, OrgSettingsRouter } from './AdminPortalOrgRouter.mjs';
import { OrgSettingsScreen } from './OrgSettingsScreen.mjs';

const validateConfig = (config)=>{
    if (!config) return;
    if (config.allowedAuthMethods?.length === 0) {
        throw new Error('allowedAuthMethods must contain at least one value');
    }
    if (config.allowedMfaAuthMethods?.length === 0) {
        throw new Error('mfaAuthMethods must contain at least one value');
    }
};
const routeMap$1 = {
    orgSettingsScreen: OrgSettingsScreen
};
const initialRoute$1 = {
    screen: 'orgSettingsScreen'
};
const Content$1 = ()=>{
    const { self, fromCache } = useSelf();
    const { error: adminPortalConfigError } = useAdminPortalConfig({
        shouldFetch: !!self
    });
    const orgSettingsState = getFeatureState({
        self,
        fromCache,
        adminPortalConfigError: adminPortalConfigError,
        isFeatureEnabled: true,
        hasPermission: true
    });
    return /*#__PURE__*/ React__default.createElement(FeatureStateComponent, {
        featureState: orgSettingsState,
        notLoggedInValue: 'Please log in to manage Authentication & Access.',
        errorValue: 'Authentication & Access Settings could not be loaded. Please contact your admin if you think this is a mistake.',
        featureNotEnabledValue: 'Authentication & Access is not supported. Please contact your admin if you think this is a mistake.',
        noPermissionValue: 'You do not have permission to view Authentication & Access. Please contact your admin if you think this is a mistake.'
    }, /*#__PURE__*/ React__default.createElement(OrgSettingsRouterProvider, {
        initialRoute: initialRoute$1
    }, /*#__PURE__*/ React__default.createElement(OrgSettingsRouter, {
        routeMap: routeMap$1
    })));
};
const AdminPortalOrgSettingsContainer = (props)=>{
    const uiConfig = useAdminPortalOrgUIConfig();
    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_org_settings',
            details: {}
        });
    }, []);
    useEffect(()=>{
        validateConfig(uiConfig);
    }, [
        uiConfig
    ]);
    return /*#__PURE__*/ React__default.createElement(AdminPortalWrapper, {
        options: props
    }, /*#__PURE__*/ React__default.createElement(Content$1, null));
};

export { AdminPortalOrgSettingsContainer, Content$1 as Content };
//# sourceMappingURL=AdminPortalOrgSettingsContainer.mjs.map
