import '../../../../../node_modules/preact/compat/dist/compat.module.mjs';
import { useToast } from '../shared/components/Toast.mjs';
import { useAdminPortalMemberManagementUIConfig } from '../StytchClientContext.mjs';
import { useStytchClient } from '../utils/useStytchClient.mjs';
import { useCallback as T } from '../../../../../node_modules/preact/hooks/dist/hooks.module.mjs';

function useSendInviteEmail({ onSuccess }) {
    const client = useStytchClient();
    const uiConfig = useAdminPortalMemberManagementUIConfig();
    const { openToast } = useToast();
    return T(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
