import { useCallback } from 'react';
import '../../../../../_virtual/index2.mjs';
import { useSWRConfig } from '../../../../../node_modules/swr/_internal/dist/index.mjs';
import { useMutateWithToast } from './useMutateWithToast.mjs';
import { useRevalidateConnectionList } from './useRevalidateConnectionList.mjs';
import { useStytchClient } from './useStytchClient.mjs';

const mutateSamlConnection = (client)=>(options)=>client.sso.saml.updateConnection(options);
const mutateOidcConnection = (client)=>(options)=>client.sso.oidc.updateConnection(options);
const mutateExternalConnection = (client)=>(options)=>client.sso.external.updateConnection(options);
const updateConnectionByURL = (client)=>(options)=>client.sso.saml.updateConnectionByURL(options);
const deleteConnection = (client)=>({ connection_id })=>client.sso.deleteConnection(connection_id);
const deleteVerificationCertificate = (client)=>(options)=>client.sso.saml.deleteVerificationCertificate(options);
const useMutateFnSsoConnection = (mutateFn)=>{
    const { mutate: mutateSWR } = useSWRConfig();
    const client = useStytchClient();
    const revalidateConnectionList = useRevalidateConnectionList();
    return useMutateWithToast(useCallback(async (options)=>{
        await mutateSWR([
            'sso.connection',
            options.connection_id
        ], ()=>mutateFn(client)(options));
        return revalidateConnectionList();
    }, [
        client,
        mutateFn,
        mutateSWR,
        revalidateConnectionList
    ]));
};
const useMutateSsoConnectionByUrl = ()=>{
    return useMutateFnSsoConnection(updateConnectionByURL);
};
const useDeleteSsoConnection = ()=>{
    return useMutateFnSsoConnection(deleteConnection);
};
const useDeleteSsoConnectionCert = ()=>{
    return useMutateFnSsoConnection(deleteVerificationCertificate);
};
const useMutateSsoConnection = (connectionType)=>{
    return useMutateFnSsoConnection(connectionType === 'saml' ? mutateSamlConnection : connectionType === 'oidc' ? mutateOidcConnection : mutateExternalConnection);
};

export { useDeleteSsoConnection, useDeleteSsoConnectionCert, useMutateSsoConnection, useMutateSsoConnectionByUrl };
//# sourceMappingURL=useMutateSsoConnection.mjs.map
