"use strict";

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

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = exports.DRAG_TYPE = exports.BlankContent = 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 _drag = require("../../drag");

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

var _Chip = _interopRequireDefault(require("@material-ui/core/Chip"));

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

var _reactDom = _interopRequireDefault(require("react-dom"));

var _mathRendering = require("@pie-lib/math-rendering");

var _renderUi = require("../../render-ui");

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

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

  var _super = _createSuper(BlankContentComp);

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

  (0, _createClass2["default"])(BlankContentComp, [{
    key: "componentDidUpdate",
    value: function componentDidUpdate() {
      (0, _mathRendering.renderMath)(this.rootRef);
    }
  }, {
    key: "render",
    value: function render() {
      var _this = this;

      var _this$props = this.props,
          connectDragSource = _this$props.connectDragSource,
          choice = _this$props.choice,
          classes = _this$props.classes,
          disabled = _this$props.disabled; // TODO the Chip element is causing drag problems on touch devices. Avoid using Chip and consider refactoring the code. Keep in mind that Chip is a span with a button role, which interferes with seamless touch device dragging.

      return connectDragSource( /*#__PURE__*/_react["default"].createElement("span", {
        className: (0, _classnames["default"])(classes.choice, disabled && classes.disabled)
      }, /*#__PURE__*/_react["default"].createElement(_Chip["default"], {
        clickable: false,
        disabled: true,
        ref: function ref(_ref2) {
          //eslint-disable-next-line
          _this.rootRef = _reactDom["default"].findDOMNode(_ref2);
        },
        className: classes.chip,
        label: /*#__PURE__*/_react["default"].createElement("span", {
          className: classes.chipLabel,
          ref: function ref(_ref) {
            if (_ref) {
              _ref.innerHTML = choice.value || ' ';
            }
          }
        }, ' '),
        variant: disabled ? 'outlined' : undefined
      })), {});
    }
  }]);
  return BlankContentComp;
}(_react["default"].Component);

(0, _defineProperty2["default"])(BlankContentComp, "propTypes", {
  disabled: _propTypes["default"].bool,
  choice: _propTypes["default"].object,
  classes: _propTypes["default"].object,
  connectDragSource: _propTypes["default"].func
});
var BlankContent = (0, _styles.withStyles)(function (theme) {
  return {
    choice: {
      border: "solid 0px ".concat(theme.palette.primary.main),
      borderRadius: theme.spacing.unit * 2,
      margin: theme.spacing.unit / 2,
      transform: 'translate(0, 0)'
    },
    chip: {
      backgroundColor: _renderUi.color.background(),
      border: "1px solid ".concat(_renderUi.color.text()),
      color: _renderUi.color.text(),
      alignItems: 'center',
      display: 'inline-flex',
      height: 'initial',
      minHeight: '32px',
      fontSize: 'inherit',
      whiteSpace: 'pre-wrap',
      maxWidth: '374px',
      // Added for touch devices, for image content.
      // This will prevent the context menu from appearing and not allowing other interactions with the image.
      // If interactions with the image in the token will be requested we should handle only the context Menu.
      pointerEvents: 'none'
    },
    chipLabel: {
      whiteSpace: 'pre-wrap',
      '& img': {
        display: 'block',
        padding: '2px 0'
      }
    },
    disabled: {}
  };
})(BlankContentComp);
exports.BlankContent = BlankContent;
var tileSource = {
  canDrag: function canDrag(props) {
    return !props.disabled;
  },
  beginDrag: function beginDrag(props) {
    return {
      choice: props.choice,
      instanceId: props.instanceId
    };
  }
};
var DragDropTile = (0, _drag.DragSource)(DRAG_TYPE, tileSource, function (connect, monitor) {
  return {
    connectDragSource: connect.dragSource(),
    isDragging: monitor.isDragging()
  };
})(BlankContent);
var _default = DragDropTile;
exports["default"] = _default;
//# sourceMappingURL=choice.js.map