import l, { PureComponent as p, Component as h } from "react";
import f from "../../../../../../../../_virtual/index8.js";
var d = /* @__PURE__ */ function() {
  function r(t, a) {
    for (var e = 0; e < a.length; e++) {
      var n = a[e];
      n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(t, n.key, n);
    }
  }
  return function(t, a, e) {
    return a && r(t.prototype, a), e && r(t, e), t;
  };
}();
function v(r, t, a) {
  return t in r ? Object.defineProperty(r, t, { value: a, enumerable: !0, configurable: !0, writable: !0 }) : r[t] = a, r;
}
function c(r, t) {
  if (!(r instanceof t))
    throw new TypeError("Cannot call a class as a function");
}
function b(r, t) {
  if (!r)
    throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
  return t && (typeof t == "object" || typeof t == "function") ? t : r;
}
function y(r, t) {
  if (typeof t != "function" && t !== null)
    throw new TypeError("Super expression must either be null or a function, not " + typeof t);
  r.prototype = Object.create(t && t.prototype, { constructor: { value: r, enumerable: !1, writable: !0, configurable: !0 } }), t && (Object.setPrototypeOf ? Object.setPrototypeOf(r, t) : r.__proto__ = t);
}
var g = 1, u = 38, m = 40, w = [u, m], _ = function(t) {
  return w.indexOf(t) > -1;
}, E = function(t) {
  return Number(String(t).replace(/%/g, ""));
}, O = 1, C = function(r) {
  y(t, r);
  function t(a) {
    c(this, t);
    var e = b(this, (t.__proto__ || Object.getPrototypeOf(t)).call(this));
    return e.handleBlur = function() {
      e.state.blurValue && e.setState({ value: e.state.blurValue, blurValue: null });
    }, e.handleChange = function(n) {
      e.setUpdatedValue(n.target.value, n);
    }, e.handleKeyDown = function(n) {
      var i = E(n.target.value);
      if (!isNaN(i) && _(n.keyCode)) {
        var o = e.getArrowOffset(), s = n.keyCode === u ? i + o : i - o;
        e.setUpdatedValue(s, n);
      }
    }, e.handleDrag = function(n) {
      if (e.props.dragLabel) {
        var i = Math.round(e.props.value + n.movementX);
        i >= 0 && i <= e.props.dragMax && e.props.onChange && e.props.onChange(e.getValueObjectWithLabel(i), n);
      }
    }, e.handleMouseDown = function(n) {
      e.props.dragLabel && (n.preventDefault(), e.handleDrag(n), window.addEventListener("mousemove", e.handleDrag), window.addEventListener("mouseup", e.handleMouseUp));
    }, e.handleMouseUp = function() {
      e.unbindEventListeners();
    }, e.unbindEventListeners = function() {
      window.removeEventListener("mousemove", e.handleDrag), window.removeEventListener("mouseup", e.handleMouseUp);
    }, e.state = {
      value: String(a.value).toUpperCase(),
      blurValue: String(a.value).toUpperCase()
    }, e.inputId = "rc-editable-input-" + O++, e;
  }
  return d(t, [{
    key: "componentDidUpdate",
    value: function(e, n) {
      this.props.value !== this.state.value && (e.value !== this.props.value || n.value !== this.state.value) && (this.input === document.activeElement ? this.setState({ blurValue: String(this.props.value).toUpperCase() }) : this.setState({ value: String(this.props.value).toUpperCase(), blurValue: !this.state.blurValue && String(this.props.value).toUpperCase() }));
    }
  }, {
    key: "componentWillUnmount",
    value: function() {
      this.unbindEventListeners();
    }
  }, {
    key: "getValueObjectWithLabel",
    value: function(e) {
      return v({}, this.props.label, e);
    }
  }, {
    key: "getArrowOffset",
    value: function() {
      return this.props.arrowOffset || g;
    }
  }, {
    key: "setUpdatedValue",
    value: function(e, n) {
      var i = this.props.label ? this.getValueObjectWithLabel(e) : e;
      this.props.onChange && this.props.onChange(i, n), this.setState({ value: e });
    }
  }, {
    key: "render",
    value: function() {
      var e = this, n = f({
        default: {
          wrap: {
            position: "relative"
          }
        },
        "user-override": {
          wrap: this.props.style && this.props.style.wrap ? this.props.style.wrap : {},
          input: this.props.style && this.props.style.input ? this.props.style.input : {},
          label: this.props.style && this.props.style.label ? this.props.style.label : {}
        },
        "dragLabel-true": {
          label: {
            cursor: "ew-resize"
          }
        }
      }, {
        "user-override": !0
      }, this.props);
      return l.createElement(
        "div",
        { style: n.wrap },
        l.createElement("input", {
          id: this.inputId,
          style: n.input,
          ref: function(o) {
            return e.input = o;
          },
          value: this.state.value,
          onKeyDown: this.handleKeyDown,
          onChange: this.handleChange,
          onBlur: this.handleBlur,
          placeholder: this.props.placeholder,
          spellCheck: "false"
        }),
        this.props.label && !this.props.hideLabel ? l.createElement(
          "label",
          {
            htmlFor: this.inputId,
            style: n.label,
            onMouseDown: this.handleMouseDown
          },
          this.props.label
        ) : null
      );
    }
  }]), t;
}(p || h);
export {
  C as EditableInput,
  C as default
};
//# sourceMappingURL=EditableInput.js.map
