import { useLayoutEffect as a, useEffect as d } from "react";
function s(e) {
  if (!/^[0-9a-zA-Z-]+$/.test(e))
    throw new Error(
      `[@mantine/use-form] Form name "${e}" is invalid, it should contain only letters, numbers and dashes`
    );
}
const l = typeof window < "u" ? a : d;
function r(e, i) {
  l(() => {
    if (e)
      return window.addEventListener(e, i), () => window.removeEventListener(e, i);
  }, [e]);
}
function n(e, i) {
  e && s(e), r(
    `mantine-form:${e}:set-field-value`,
    (t) => i.setFieldValue(t.detail.path, t.detail.value)
  ), r(
    `mantine-form:${e}:set-values`,
    (t) => i.setValues(t.detail)
  ), r(
    `mantine-form:${e}:set-initial-values`,
    (t) => i.setInitialValues(t.detail)
  ), r(
    `mantine-form:${e}:set-errors`,
    (t) => i.setErrors(t.detail)
  ), r(
    `mantine-form:${e}:set-field-error`,
    (t) => i.setFieldError(t.detail.path, t.detail.error)
  ), r(
    `mantine-form:${e}:clear-field-error`,
    (t) => i.clearFieldError(t.detail)
  ), r(`mantine-form:${e}:clear-errors`, i.clearErrors), r(`mantine-form:${e}:reset`, i.reset), r(`mantine-form:${e}:validate`, i.validate), r(
    `mantine-form:${e}:validate-field`,
    (t) => i.validateField(t.detail)
  ), r(
    `mantine-form:${e}:reorder-list-item`,
    (t) => i.reorderListItem(t.detail.path, t.detail.payload)
  ), r(
    `mantine-form:${e}:remove-list-item`,
    (t) => i.removeListItem(t.detail.path, t.detail.index)
  ), r(
    `mantine-form:${e}:insert-list-item`,
    (t) => i.insertListItem(t.detail.path, t.detail.item, t.detail.index)
  ), r(
    `mantine-form:${e}:set-dirty`,
    (t) => i.setDirty(t.detail)
  ), r(
    `mantine-form:${e}:set-touched`,
    (t) => i.setTouched(t.detail)
  ), r(
    `mantine-form:${e}:reset-dirty`,
    (t) => i.resetDirty(t.detail)
  ), r(`mantine-form:${e}:reset-touched`, i.resetTouched);
}
export {
  n as useFormActions,
  l as useIsomorphicEffect
};
//# sourceMappingURL=actions.mjs.map
