"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.IconMenu = void 0;

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _Menu = _interopRequireDefault(require("@material-ui/core/Menu"));

var _MenuItem = _interopRequireDefault(require("@material-ui/core/MenuItem"));

var _MoreVert = _interopRequireDefault(require("@material-ui/icons/MoreVert"));

var _MoreHoriz = _interopRequireDefault(require("@material-ui/icons/MoreHoriz"));

var _IconButton = _interopRequireDefault(require("@material-ui/core/IconButton"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _react = _interopRequireDefault(require("react"));

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

var IconMenu = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(IconMenu, _React$Component);

  var _super = _createSuper(IconMenu);

  function IconMenu(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, IconMenu);
    _this = _super.call(this, props);
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleClick", function (event) {
      return _this.setState({
        open: true,
        anchorEl: event.currentTarget
      });
    });
    (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "handleRequestClose", function () {
      return _this.setState({
        open: false
      });
    });
    _this.state = {
      anchorEl: undefined,
      open: false
    };
    return _this;
  }

  (0, _createClass2["default"])(IconMenu, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var _this$props = this.props,
          opts = _this$props.opts,
          onClick = _this$props.onClick,
          classes = _this$props.classes;
      var _this$state = this.state,
          open = _this$state.open,
          anchorEl = _this$state.anchorEl;
      var keys = Object.keys(opts) || [];

      var handleMenuClick = function handleMenuClick(key) {
        return function () {
          onClick(key);

          _this2.handleRequestClose();
        };
      };

      var iconColor = open ? 'inherit' : 'disabled';
      return /*#__PURE__*/_react["default"].createElement("div", null, /*#__PURE__*/_react["default"].createElement("div", {
        onClick: this.handleClick
      }, /*#__PURE__*/_react["default"].createElement(_IconButton["default"], {
        className: classes.icon
      }, open ? /*#__PURE__*/_react["default"].createElement(_MoreVert["default"], {
        color: iconColor
      }) : /*#__PURE__*/_react["default"].createElement(_MoreHoriz["default"], {
        color: iconColor
      }))), /*#__PURE__*/_react["default"].createElement(_Menu["default"], {
        id: "point-menu",
        anchorEl: anchorEl,
        open: open,
        onClose: this.handleRequestClose,
        style: {
          transform: 'translate(-15px, -15px)'
        },
        transformOrigin: {
          vertical: 'center',
          horizontal: 'right'
        }
      }, keys.map(function (k, index) {
        return /*#__PURE__*/_react["default"].createElement(_MenuItem["default"], {
          key: index,
          onClick: handleMenuClick(k)
        }, opts[k]);
      })));
    }
  }]);
  return IconMenu;
}(_react["default"].Component);

exports.IconMenu = IconMenu;
(0, _defineProperty2["default"])(IconMenu, "propTypes", {
  opts: _propTypes["default"].object,
  onClick: _propTypes["default"].func.isRequired,
  classes: _propTypes["default"].object.isRequired
});

var PointMenu = /*#__PURE__*/function (_React$Component2) {
  (0, _inherits2["default"])(PointMenu, _React$Component2);

  var _super2 = _createSuper(PointMenu);

  function PointMenu() {
    (0, _classCallCheck2["default"])(this, PointMenu);
    return _super2.apply(this, arguments);
  }

  (0, _createClass2["default"])(PointMenu, [{
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          onChange = _this$props2.onChange,
          classes = _this$props2.classes,
          showSampleAnswer = _this$props2.showSampleAnswer;
      var sampleText = showSampleAnswer ? 'Provide Sample Response' : 'Remove Sample Response';
      return /*#__PURE__*/_react["default"].createElement(IconMenu, {
        onClick: function onClick(key) {
          return onChange(key);
        },
        opts: {
          sample: sampleText
        },
        classes: classes
      });
    }
  }]);
  return PointMenu;
}(_react["default"].Component);

exports["default"] = PointMenu;
(0, _defineProperty2["default"])(PointMenu, "propTypes", {
  onChange: _propTypes["default"].func.isRequired,
  classes: _propTypes["default"].object.isRequired,
  showSampleAnswer: _propTypes["default"].bool.isRequired
});
(0, _defineProperty2["default"])(PointMenu, "defaultProps", {
  classes: {}
});
//# sourceMappingURL=point-menu.js.map