"use strict";

exports.__esModule = true;
exports.useInputValue = void 0;
var _react = require("react");
var useInputValue = exports.useInputValue = function useInputValue(_ref) {
  var _ref$value = _ref.value,
    value = _ref$value === void 0 ? "" : _ref$value,
    onChange = _ref.onChange,
    maxChars = _ref.maxChars;
  var _useState = (0, _react.useState)(value),
    inputValue = _useState[0],
    setValue = _useState[1];
  var _useState2 = (0, _react.useState)(false),
    isDirty = _useState2[0],
    setIsDirty = _useState2[1];
  var handleChange = (0, _react.useCallback)(function (e) {
    var newValue = e.target.value;
    if (maxChars && newValue.length > maxChars) {
      e.preventDefault();
      e.stopPropagation();
      return;
    }
    setValue(newValue);
    if (!isDirty) {
      setIsDirty(true);
    }
    if (onChange) {
      onChange(e);
    }
  }, [isDirty, maxChars, onChange]);
  var maxCharsIndicator = maxChars ? inputValue.length + "/" + maxChars : "";
  var resetValue = (0, _react.useCallback)(function (v) {
    if (v === void 0) {
      v = "";
    }
    setValue(v);
    setIsDirty(false);
  }, []);
  return [inputValue, handleChange, maxCharsIndicator, isDirty, {
    setIsDirty: setIsDirty,
    setValue: setValue,
    resetValue: resetValue
  }];
};