"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const React = tslib_1.__importStar(require("react"));
const mobileContext_1 = require("../../gravity-blocks/context/mobileContext/index.js");
const theme_1 = require("../../gravity-blocks/context/theme/index.js");
const hooks_1 = require("../../gravity-blocks/hooks/index.js");
const models_1 = require("../../models/index.js");
const utils_1 = require("../../utils/index.js");
const HubspotFormContainer_1 = tslib_1.__importDefault(require("./HubspotFormContainer.js"));
const b = (0, utils_1.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 = (0, theme_1.useTheme)();
    const handleAnalytics = (0, hooks_1.useAnalytics)(models_1.DefaultEventNames.HubspotFormSubmit);
    const isMobileValue = React.useContext(mobileContext_1.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,
    ]);
    (0, hooks_1.useHandleHubspotEvents)(handlers, formId);
    return ((0, jsx_runtime_1.jsx)(HubspotFormContainer_1.default, { 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';
exports.default = HubspotForm;
//# sourceMappingURL=index.js.map
