"use strict";

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

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

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

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

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 _react = _interopRequireDefault(require("react"));

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

var _styles = require("@material-ui/core/styles");

var _classnames = _interopRequireDefault(require("classnames"));

var _grey = _interopRequireDefault(require("@material-ui/core/colors/grey"));

var _reactDnd = require("react-dnd");

var _uidContext = require("./uid-context");

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 DRAG_TYPE = 'CHOICE';
exports.DRAG_TYPE = DRAG_TYPE;

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

  var _super = _createSuper(Choice);

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

  (0, _createClass2["default"])(Choice, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          classes = _this$props.classes,
          className = _this$props.className,
          children = _this$props.children,
          connectDragSource = _this$props.connectDragSource;
      return connectDragSource( /*#__PURE__*/_react["default"].createElement("div", {
        className: (0, _classnames["default"])(classes.choice, className)
      }, children));
    }
  }]);
  return Choice;
}(_react["default"].Component);

exports.Choice = Choice;
(0, _defineProperty2["default"])(Choice, "propTypes", {
  classes: _propTypes["default"].object.isRequired,
  className: _propTypes["default"].string,
  children: _propTypes["default"].oneOfType([_propTypes["default"].arrayOf(_propTypes["default"].node), _propTypes["default"].node]),
  connectDragSource: _propTypes["default"].func.isRequired
});
(0, _defineProperty2["default"])(Choice, "defaultProps", {});

var styles = function styles(theme) {
  return {
    choice: {
      backgroundColor: theme.palette.background.paper,
      border: "solid 1px ".concat(_grey["default"][400]),
      padding: theme.spacing.unit,
      minHeight: '30px',
      minWidth: theme.spacing.unit * 20,
      maxWidth: theme.spacing.unit * 75
    }
  };
};

var choiceSource = {
  canDrag: function canDrag(props) {
    return !props.disabled;
  },
  beginDrag: function beginDrag(props) {
    var out = {
      choiceId: props.choice.id,
      from: props.category.id,
      alternateResponseIndex: props.alternateResponseIndex,
      choiceIndex: props.choiceIndex
    };
    return out;
  },
  endDrag: function endDrag(props, monitor) {
    if (!monitor.didDrop()) {
      var item = monitor.getItem();

      if (item.from) {
        props.onRemoveChoice(item);
      }
    }
  }
};
var styledChoice = (0, _styles.withStyles)(styles)(Choice);
var DraggableChoice = (0, _reactDnd.DragSource)(function (_ref) {
  var uid = _ref.uid;
  return uid;
}, choiceSource, function (connect, monitor) {
  return {
    connectDragSource: connect.dragSource(),
    connectDragPreview: connect.dragPreview(),
    isDragging: monitor.isDragging()
  };
})(styledChoice);

var _default = (0, _uidContext.withUid)(DraggableChoice);

exports["default"] = _default;
//# sourceMappingURL=choice.js.map