import { useMutation } from '@tanstack/react-query';
import { useClientSession } from '../../../lib/seam/client-sessions/use-client-session.js';
import { NullSeamClientError, useSeamClient } from '../../../lib/seam/use-seam-client.js';
export function useCreateConnectWebview({ willNavigateToWebview = false, } = {}) {
    const { client } = useSeamClient();
    const { clientSession } = useClientSession();
    return useMutation({
        mutationFn: async (variables) => {
            if (client === null)
                throw new NullSeamClientError();
            return await client.connectWebviews.create({
                custom_metadata: {
                    client_session_id: clientSession?.client_session_id ?? null,
                    user_identifier_key: clientSession?.user_identifier_key ?? null,
                    ...variables.custom_metadata,
                },
                ...variables,
            });
        },
        onSuccess: ({ url }) => {
            if (willNavigateToWebview && url != null) {
                globalThis.location.href = url;
            }
        },
    });
}
//# sourceMappingURL=use-create-connect-webview.js.map