import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect, useRef } from "react";
/**
 * This component loads and displays a HubSpot form. It handles the form's
 * initialization and provides callbacks when the form is ready or submitted.
 */
export default function HSForms({ region, partialId, formId, className, onFormReady, onFormSubmitted, }) {
    if (window.PRERENDER)
        return null;
    const container = useRef(null);
    useEffect(() => {
        import("jquery").then((jqueryModule) => {
            const funcId = String(Math.round(Math.random() * 999999));
            const idx = `onLoad${funcId}`;
            const idx2 = `onSubmit${funcId}`;
            window[idx] = function (form) {
                if (onFormReady)
                    onFormReady(container.current, form);
            };
            window[idx2] = function () {
                if (onFormSubmitted)
                    onFormSubmitted();
            };
            window.jQuery = jqueryModule.default;
            const script = document.createElement("script");
            script.setAttribute("src", "https://js.hsforms.net/forms/v2.js");
            script.setAttribute("type", "text/javascript");
            script.setAttribute("charset", "utf-8");
            script.onload = () => {
                const createFormScript = document.createElement("script");
                createFormScript.setAttribute("type", "text/javascript");
                createFormScript.innerHTML = `hbspt.forms.create({
          region: "${region}",
          portalId: "${partialId}",
          formId: "${formId}",
          submitButtonClass: '#',
          css: ' ',
          cssClass: '#',
          onFormReady: ${idx},
          onFormSubmit: ${idx2},
          formInstanceId: ${funcId}
        });`;
                container.current.appendChild(createFormScript);
            };
            document.head.appendChild(script);
        });
    }, [region, partialId, formId]);
    return _jsx("div", { ref: container, className: className });
}
//# sourceMappingURL=HSForms.js.map