"use strict";

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

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

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

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

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 _classnames = _interopRequireDefault(require("classnames"));

var _plot = require("../../../plot");

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

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

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

var _styles = require("../../common/styles");

var _excluded = ["x", "y", "graphProps", "classes", "className", "interactive", "CustomDraggableComponent", "correctness"];

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 RawDragHandle = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(RawDragHandle, _React$Component);

  var _super = _createSuper(RawDragHandle);

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

  (0, _createClass2["default"])(RawDragHandle, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          x = _this$props.x,
          y = _this$props.y,
          graphProps = _this$props.graphProps,
          classes = _this$props.classes,
          className = _this$props.className,
          interactive = _this$props.interactive,
          CustomDraggableComponent = _this$props.CustomDraggableComponent,
          correctness = _this$props.correctness,
          rest = (0, _objectWithoutProperties2["default"])(_this$props, _excluded);
      var scale = graphProps.scale;
      return /*#__PURE__*/_react["default"].createElement(CustomDraggableComponent, (0, _extends2["default"])({
        scale: scale,
        x: x,
        y: y,
        classes: classes,
        className: (0, _classnames["default"])(className, !interactive && 'non-interactive'),
        correctness: correctness,
        interactive: interactive
      }, rest));
    }
  }]);
  return RawDragHandle;
}(_react["default"].Component);

(0, _defineProperty2["default"])(RawDragHandle, "propTypes", {
  x: _propTypes["default"].number.isRequired,
  y: _propTypes["default"].number.isRequired,
  width: _propTypes["default"].number,
  graphProps: _plot.types.GraphPropsType.isRequired,
  classes: _propTypes["default"].object.isRequired,
  className: _propTypes["default"].string,
  interactive: _propTypes["default"].bool,
  CustomDraggableComponent: _propTypes["default"].func,
  correctness: _propTypes["default"].shape({
    value: _propTypes["default"].string,
    label: _propTypes["default"].string
  })
});
var DragHandle = (0, _index.withStyles)(function () {
  return {
    handle: {
      transition: 'fill 200ms linear, height 200ms linear',
      '&.correct': (0, _styles.correct)('fill'),
      '&.incorrect': (0, _styles.incorrect)('fill'),
      '&.non-interactive': (0, _styles.disabled)('fill')
    },
    transparentHandle: {
      height: '20px',
      fill: 'transparent',
      stroke: 'transparent'
    },
    line: {
      stroke: _renderUi.color.defaults.TEXT,
      transition: 'fill 200ms linear, height 200ms linear',
      '&.non-interactive': (0, _styles.disabled)('stroke'),
      '&.correct': (0, _styles.correct)('stroke'),
      '&.incorrect': (0, _styles.incorrect)('stroke')
    }
  };
})(RawDragHandle);
exports.DragHandle = DragHandle;
var DraggableHandle = (0, _plot.gridDraggable)({
  axis: 'y',
  fromDelta: function fromDelta(props, delta) {
    //TODO: should be in grid-draggable, if axis is y delta.x should always be 0.
    delta.x = 0;

    var newPoint = _plot.utils.point(props).add(_plot.utils.point(delta));

    return newPoint.y;
  },
  bounds: function bounds(props, _ref) {
    var domain = _ref.domain,
        range = _ref.range;
    var area = {
      left: 0,
      top: props.y,
      bottom: props.y,
      right: 0
    };
    return _plot.utils.bounds(area, domain, range);
  },
  anchorPoint: function anchorPoint(props) {
    return {
      x: props.x,
      y: props.y
    };
  }
})(DragHandle);
var _default = DraggableHandle;
exports["default"] = _default;
//# sourceMappingURL=drag-handle.js.map