import { x as o, bE as s, r as d } from "./index-6wLGsgHc.js";
class a {
  /**
   * Register the listener that will be called when the widget's form is cleared.
   * This should be called in the `render` function of every class-based widget
   * element - it mimics the behavior of a `useEffect` hook, and ensures that
   * subscription and unsubscription happen correctly.
   *
   * Hooks-based widgets can just use `useEffect` and call
   * `widgetMgr.addFormClearedListener` directly. Or just use the convenient
   * hook `useFormClearHelper`, below.
   */
  manageFormClearListener(t, e, i) {
    o(this.formClearListener) && this.lastWidgetMgr === t && this.lastFormId === e || (this.disconnect(), s(e) && (this.formClearListener = t.addFormClearedListener(e, i), this.lastWidgetMgr = t, this.lastFormId = e));
  }
  /**
   * Disconnect from the form-clear signal, if we're connected.
   * This should be called from the `componentWillUnmount` function of every
   * element that uses it.
   */
  disconnect() {
    this.formClearListener?.disconnect(), this.formClearListener = void 0, this.lastWidgetMgr = void 0, this.lastFormId = void 0;
  }
}
function l({
  element: r,
  widgetMgr: t,
  onFormCleared: e
}) {
  d.useEffect(() => {
    if (!t || !s(r.formId)) return;
    const i = t.addFormClearedListener(r.formId, e);
    return () => {
      i.disconnect();
    };
  }, [r, t, e]);
}
export {
  a as d,
  l as m
};
//# sourceMappingURL=FormClearHelper-Dgu5Halt-DyRdP6JG.js.map
