"use strict";

exports.__esModule = true;
exports.useLinkedMode = void 0;
var _react = require("react");
var useLinkedMode = _ref => {
  var {
    initial = true,
    onChangeCallbacks,
    onInvalidCallbacks,
    onBlurCallbacks
  } = _ref;
  var [isLinkingEnabled, setLinking] = (0, _react.useState)(initial);
  var [isDirty, setIsDirty] = (0, _react.useState)(false);
  var linkedOnChange = function linkedOnChange() {
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    onChangeCallbacks.forEach(onChange => onChange == null ? void 0 : onChange(...args));
    setIsDirty(true);
  };
  var linkedOnInvalid = function linkedOnInvalid() {
    for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
      args[_key2] = arguments[_key2];
    }
    onInvalidCallbacks.forEach(onInvalid => onInvalid == null ? void 0 : onInvalid(...args));
    setIsDirty(true);
  };
  var linkedOnBlur = () => {
    isDirty && onBlurCallbacks.forEach(onBlur => onBlur());
    setIsDirty(false);
  };
  return [{
    linkedOnChange,
    linkedOnInvalid,
    linkedOnBlur,
    isLinkingEnabled
  }, setLinking];
};
exports.useLinkedMode = useLinkedMode;
//# sourceMappingURL=useLinkedMode.js.map