"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
var Clipboard = /*#__PURE__*/function (_React$Component) {
  _inheritsLoose(Clipboard, _React$Component);
  function Clipboard() {
    var _this;
    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }
    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (e) {
      if (document.activeElement && ["input", "select", "textarea"].indexOf(document.activeElement.tagName.toLowerCase()) !== -1) {
        return; //stop early if we're inside an input
      }

      var metaKeyIsDown = e.ctrlKey || e.metaKey;
      if (!metaKeyIsDown || !["x", "c", "v"].includes(e.key)) {
        _this.origFocusedElement = null;
        return;
      }
      _this.origFocusedElement = document.activeElement;
      _this.node.select();
    });
    _defineProperty(_assertThisInitialized(_this), "handleKeyUp", function () {
      if (_this.origFocusedElement) {
        _this.origFocusedElement.focus();
      }
    });
    return _this;
  }
  var _proto = Clipboard.prototype;
  _proto.componentDidMount = function componentDidMount() {
    this.node.parentNode.addEventListener("keydown", this.handleKeyDown, false);
    this.node.parentNode.addEventListener("keyup", this.handleKeyUp, false);
  };
  _proto.componentWillUnmount = function componentWillUnmount() {
    this.node.parentNode.removeEventListener("keydown", this.handleKeyDown, false);
    this.node.parentNode.removeEventListener("keyup", this.handleKeyUp, false);
  };
  _proto.render = function render() {
    var _this2 = this;
    var value = this.props.value;
    var style = {
      position: "fixed",
      width: 1,
      height: 1,
      opacity: 0,
      left: 0,
      padding: 0,
      top: 0,
      margin: 0,
      zIndex: 100
    };
    return /*#__PURE__*/_react["default"].createElement("input", {
      ref: function ref(c) {
        if (c) {
          _this2.node = c;
        }
      },
      style: style,
      type: "text",
      value: value,
      onChange: noop,
      readOnly: true,
      className: "clipboard",
      onPaste: this.props.onPaste,
      onCopy: this.props.onCopy,
      onCut: this.props.onCut
    });
  };
  return Clipboard;
}(_react["default"].Component);
_defineProperty(Clipboard, "defaultProps", {
  className: "clipboard"
});
var _default = Clipboard;
exports["default"] = _default;
var noop = function noop() {};
module.exports = exports.default;