import { useCallback } from 'react';
import { useToast } from '../shared/components/Toast.mjs';
import { useAdminPortalMemberManagementUIConfig } from '../StytchClientContext.mjs';
import { useStytchClient } from '../utils/useStytchClient.mjs';

function useSendInviteEmail({ onSuccess }) {
    const client = useStytchClient();
    const uiConfig = useAdminPortalMemberManagementUIConfig();
    const { openToast } = useToast();
    return useCallback(async (email_address, additionalOptions = {})=>{
        const trimmedEmail = email_address.trim();
        await client.magicLinks.email.invite({
            ...additionalOptions,
            email_address: trimmedEmail,
            invite_template_id: uiConfig?.inviteTemplateId,
            invite_redirect_url: uiConfig?.inviteRedirectURL
        });
        openToast({
            text: `Invite sent to ${trimmedEmail}`,
            type: 'success'
        });
        await onSuccess?.();
    }, [
        client,
        uiConfig?.inviteTemplateId,
        uiConfig?.inviteRedirectURL,
        openToast,
        onSuccess
    ]);
}

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