import Add from '../../../../../node_modules/@mui/icons-material/esm/Add.mjs';
import React__default from 'react';
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__*/ React__default.createElement(PageLoadingIndicator, null);
    }
    return /*#__PURE__*/ React__default.createElement(FlexBox, {
        gap: 3,
        flexDirection: "column"
    }, /*#__PURE__*/ React__default.createElement(Typography, {
        variant: "h1"
    }, "SCIM"), /*#__PURE__*/ React__default.createElement(FlexBox, {
        flexDirection: "column",
        gap: 2
    }, /*#__PURE__*/ React__default.createElement(Typography, {
        variant: "body2"
    }, "Set up a SCIM connection to sync from an IdP."), canCreateScim ? /*#__PURE__*/ React__default.createElement(Button, {
        type: "submit",
        variant: "ghost",
        startIcon: /*#__PURE__*/ React__default.createElement(Add, null),
        onClick: ()=>navigate({
                screen: 'newConnection'
            })
    }, "Create") : /*#__PURE__*/ React__default.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__*/ React__default.createElement(Alert, null, "There was an error loading the SCIM connection.");
    }
    if (isLoading) {
        return /*#__PURE__*/ React__default.createElement(PageLoadingIndicator, null);
    }
    return connection ? /*#__PURE__*/ React__default.createElement(SCIMConnectionDetailsScreen, {
        connection: connection
    }) : /*#__PURE__*/ React__default.createElement(NewSCIMConnection, null);
};

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