import { jsx as _jsx } from "react/jsx-runtime";
import * as React from 'react';
import { MobileContext } from "../../gravity-blocks/context/mobileContext/index.js";
import { useTheme } from "../../gravity-blocks/context/theme/index.js";
import { useAnalytics, useHandleHubspotEvents } from "../../gravity-blocks/hooks/index.js";
import { DefaultEventNames } from "../../models/index.js";
import { block } from "../../utils/index.js";
import HubspotFormContainer from "./HubspotFormContainer.js";
import './HubspotForm.css';
const b = block('hubspot-form');
const HubspotForm = React.forwardRef((props, ref) => {
    const { className, theme: themeProp, isMobile: isMobileProp, formId, formInstanceId, portalId, region, formClassName, 
    // hubspotEvents, // TODO: decide how to handle them
    analyticsEvents, onBeforeSubmit, onSubmit, onBeforeLoad, onLoad, createDOMElement, onSubmitError, defaultValues, } = props;
    const themeValue = useTheme();
    const handleAnalytics = useAnalytics(DefaultEventNames.HubspotFormSubmit);
    const isMobileValue = React.useContext(MobileContext);
    const theme = themeProp ?? themeValue;
    const mobile = isMobileProp ?? isMobileValue;
    const handlers = React.useMemo(() => ({
        onBeforeLoad,
        onBeforeSubmit,
        onLoad,
        onSubmitError,
        onSubmit: (event) => {
            handleAnalytics(analyticsEvents);
            onSubmit?.(event);
        },
    }), [
        onBeforeLoad,
        onBeforeSubmit,
        onLoad,
        handleAnalytics,
        analyticsEvents,
        onSubmit,
        onSubmitError,
    ]);
    useHandleHubspotEvents(handlers, formId);
    return (_jsx(HubspotFormContainer, { createDOMElement: createDOMElement, className: b({ theme, mobile }, className), formClassName: formClassName, formId: formId, portalId: portalId, formInstanceId: formInstanceId, region: region, defaultValues: defaultValues, ref: ref }, [formClassName, formId, formInstanceId, portalId, region].join()));
});
HubspotForm.displayName = 'HubspotForm';
export default HubspotForm;
//# sourceMappingURL=index.js.map
