import React__default, { useState, useCallback } from 'react';
import { Modal } from './Modal.mjs';
import { Typography } from './Typography.mjs';
import { useDeleteSsoConnection } from '../utils/useMutateSsoConnection.mjs';
import { useModalState } from '../shared/components/Modal.mjs';

const DeleteConfirmModal = ({ connectionName, connectionType, ...modalProps })=>{
    return /*#__PURE__*/ React__default.createElement(Modal, {
        ...modalProps,
        title: `Delete ${connectionName || 'connection'}?`,
        confirmButtonText: "Delete",
        warning: true
    }, /*#__PURE__*/ React__default.createElement(Typography, null, connectionType === 'external' ? 'Once deleted, the SSO connection will be removed. Any members assigned automatic roles via this connection, as well as members allowed to JIT provision via this SSO connection, will lose access immediately.' : 'Once deleted, the SSO connection cannot be restored. Any members assigned automatic roles via this connection, as well as members allowed to JIT provision via this SSO connection, will lose access immediately.'));
};
const useMutateDeleteConnection = ()=>{
    const { mutate } = useDeleteSsoConnection();
    const deleteConnection = ({ connectionId })=>mutate({
            connection_id: connectionId
        });
    return {
        deleteConnection
    };
};
const useDeleteConnection = ({ onConfirm } = {})=>{
    const [connection, setConnection] = useState();
    const { deleteConnection } = useMutateDeleteConnection();
    const handleConfirm = async ()=>{
        if (connection) {
            try {
                await deleteConnection({
                    connectionId: connection.id
                });
            } catch  {
                // Throw a new error to provide specific user-facing verbiage
                throw new Error(`Failed to delete ${connection.displayName}`);
            }
            onConfirm?.();
        }
    };
    const { close, confirm, isOpen, open } = useModalState(handleConfirm);
    const handleRequestDelete = useCallback((connection)=>{
        setConnection(connection);
        open();
    }, [
        open
    ]);
    return {
        handleRequestDelete,
        modalProps: {
            connectionName: connection?.displayName,
            connectionType: connection?.connectionType,
            isOpen,
            close,
            confirm
        }
    };
};

export { DeleteConfirmModal, useDeleteConnection };
//# sourceMappingURL=DeleteConnection.mjs.map
