import Add from '../../../../../node_modules/@mui/icons-material/esm/Add.mjs';
import wn from '../../../../../node_modules/preact/compat/dist/compat.module.mjs';
import { Alert } from '../components/Alert.mjs';
import { Button } from '../components/Button.mjs';
import { FlexBox } from '../shared/components/FlexBox.mjs';
import { PageLoadingIndicator } from '../components/PageLoadingIndicator.mjs';
import { Typography } from '../components/Typography.mjs';
import { useRbac } from '../utils/useRbac.mjs';
import { useScimConnection } from '../utils/useScimConnection.mjs';
import { SCIMConnectionDetailsScreen } from './SCIMConnectionDetailsScreen.mjs';
import { useScimRouterController } from './SCIMRouter.mjs';

const NewSCIMConnection = ()=>{
    const { navigate } = useScimRouterController();
    const { data: canCreateScim } = useRbac('stytch.scim', 'create');
    if (canCreateScim === undefined) {
        return /*#__PURE__*/ wn.createElement(PageLoadingIndicator, null);
    }
    return /*#__PURE__*/ wn.createElement(FlexBox, {
        gap: 3,
        flexDirection: "column"
    }, /*#__PURE__*/ wn.createElement(Typography, {
        variant: "h1"
    }, "SCIM"), /*#__PURE__*/ wn.createElement(FlexBox, {
        flexDirection: "column",
        gap: 2
    }, /*#__PURE__*/ wn.createElement(Typography, {
        variant: "body2"
    }, "Set up a SCIM connection to sync from an IdP."), canCreateScim ? /*#__PURE__*/ wn.createElement(Button, {
        type: "submit",
        variant: "ghost",
        startIcon: /*#__PURE__*/ wn.createElement(Add, null),
        onClick: ()=>navigate({
                screen: 'newConnection'
            })
    }, "Create") : /*#__PURE__*/ wn.createElement(Alert, null, "You do not have permission to create SCIM Connections. Please contact your admin if you think this is a mistake.")));
};
const SCIMScreen = ()=>{
    const { data: connection, isLoading, error } = useScimConnection({
        shouldFetch: true
    });
    if (error) {
        return /*#__PURE__*/ wn.createElement(Alert, null, "There was an error loading the SCIM connection.");
    }
    if (isLoading) {
        return /*#__PURE__*/ wn.createElement(PageLoadingIndicator, null);
    }
    return connection ? /*#__PURE__*/ wn.createElement(SCIMConnectionDetailsScreen, {
        connection: connection
    }) : /*#__PURE__*/ wn.createElement(NewSCIMConnection, null);
};

export { SCIMScreen };
//# sourceMappingURL=SCIMScreen.mjs.map
