import React__default from 'react';
import '../../../../../_virtual/index2.mjs';
import { useSWRConfig } from '../../../../../node_modules/swr/_internal/dist/index.mjs';
import { Button } from '../components/Button.mjs';
import { FlexBox } from '../shared/components/FlexBox.mjs';
import { Modal } from '../components/Modal.mjs';
import { SettingsContainer } from '../components/SettingsContainer.mjs';
import { Typography } from '../components/Typography.mjs';
import { useMutateWithToast } from '../utils/useMutateWithToast.mjs';
import { useRbac } from '../utils/useRbac.mjs';
import { scimGetConnectionKey } from '../utils/useScimConnection.mjs';
import { useStytchClient } from '../utils/useStytchClient.mjs';
import { useScimRouterController } from './SCIMRouter.mjs';
import { useModalState } from '../shared/components/Modal.mjs';

const DangerZoneSection = ({ connection })=>{
    const client = useStytchClient();
    const { mutate: mutateSWR } = useSWRConfig();
    const { useBlockNavigation } = useScimRouterController();
    const { navigate } = useScimRouterController();
    const { data: canDeleteScim } = useRbac('stytch.scim', 'delete');
    const { mutate: deleteScimConnection } = useMutateWithToast(async (connectionId)=>{
        return await mutateSWR(scimGetConnectionKey(connectionId), async ()=>{
            await client.scim.deleteConnection(connectionId);
        }, {
            populateCache: true,
            revalidate: false
        });
    });
    const deleteConnectionModalProps = useModalState(async ()=>{
        await deleteScimConnection(connection.connection_id);
        navigate({
            screen: 'scimConnection'
        });
    });
    const handleActionClick = ()=>{
        deleteConnectionModalProps.open();
    };
    return canDeleteScim ? /*#__PURE__*/ React__default.createElement(SettingsContainer, {
        title: "Danger zone",
        useBlockNavigation: useBlockNavigation
    }, /*#__PURE__*/ React__default.createElement(FlexBox, {
        flexDirection: "column",
        gap: 2
    }, /*#__PURE__*/ React__default.createElement(Modal, {
        ...deleteConnectionModalProps,
        title: "Delete SCIM connection?",
        confirmButtonText: "Delete connection",
        warning: true
    }, /*#__PURE__*/ React__default.createElement(Typography, {
        variant: "body2"
    }, "Once deleted, the connection cannot be restored. All associated SCIM groups, member registrations, and group role assignments will be deleted.")), /*#__PURE__*/ React__default.createElement(Typography, {
        variant: "body2"
    }, "Once deleted, the connection cannot be restored. All associated SCIM groups, member registrations, and group role assignments will be deleted. To create a new SCIM connection, delete the existing connection first."), /*#__PURE__*/ React__default.createElement(Button, {
        compact: true,
        variant: "ghost",
        warning: true,
        onClick: handleActionClick
    }, "Delete Connection"))) : null;
};

export { DangerZoneSection };
//# sourceMappingURL=SCIMConnectionDangerZoneSection.mjs.map
