import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/inherits";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectSpread from "@babel/runtime/helpers/objectSpread";

var _dec, _dec2, _dec3, _class, _class2, _temp;

import React, { PureComponent } from 'react';
import { withTheme } from '@material-ui/core/styles';
import PropTypes from 'prop-types';
import { style, classes } from 'typestyle';
import { DropTarget } from 'react-dnd';
import IconButton from '@material-ui/core/IconButton';
import ActionDelete from '@material-ui/icons/Delete';
import NavigationArrowBack from '@material-ui/icons/ArrowBack';
import DragTypes from '../../utils/dragTypes';
import withFiles from '../../store/withFiles';
var cn = {
  icon: style({
    borderWidth: 0,
    borderStyle: 'solid',
    borderColor: 'transparent',
    borderRadius: 2
  })
};

var getCn = function getCn(props) {
  return {
    iconDragOver: style({
      borderTopWidth: props.theme.spacing.unit,
      backgroundColor: props.theme.palette.disabledColor
    })
  };
};

var spec = {
  drop: function drop(props, monitor) {
    var _monitor$getItem = monitor.getItem(),
        files = _monitor$getItem.files;

    var nextFiles = files.map(function (file) {
      return file.set({
        options: _objectSpread({}, file.options, {
          isTrashed: !props.showTrashes // ゴミ箱に入れる/元に戻す

        })
      });
    });
    props.deleteFiles(files);
    props.putFiles(nextFiles);
    return {};
  }
};

var collect = function collect(connect, monitor) {
  return {
    connectDropTarget: connect.dropTarget(),
    isOver: monitor.isOver({
      shallow: true
    })
  };
};

var TrashBox = (_dec = withTheme(), _dec2 = withFiles({
  watch: ''
}), _dec3 = DropTarget(DragTypes.File, spec, collect), _dec(_class = _dec2(_class = _dec3(_class = (_temp = _class2 =
/*#__PURE__*/
function (_PureComponent) {
  _inherits(TrashBox, _PureComponent);

  function TrashBox() {
    _classCallCheck(this, TrashBox);

    return _possibleConstructorReturn(this, _getPrototypeOf(TrashBox).apply(this, arguments));
  }

  _createClass(TrashBox, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          showTrashes = _this$props.showTrashes,
          onClick = _this$props.onClick,
          connectDropTarget = _this$props.connectDropTarget;
      var isOver = this.props.isOver;
      return connectDropTarget(React.createElement("div", null, React.createElement(IconButton, {
        className: classes(cn.icon, isOver && getCn(this.props).iconDragOver),
        onClick: onClick
      }, showTrashes ? React.createElement(NavigationArrowBack, null) : React.createElement(ActionDelete, null))));
    }
  }]);

  return TrashBox;
}(PureComponent), _defineProperty(_class2, "propTypes", {
  theme: PropTypes.object.isRequired,
  showTrashes: PropTypes.bool.isRequired,
  onClick: PropTypes.func.isRequired,
  connectDropTarget: PropTypes.func.isRequired,
  isOver: PropTypes.bool.isRequired,
  // Injected by withFiles (for JSX)
  putFiles: PropTypes.func.isRequired,
  deleteFiles: PropTypes.func.isRequired
}), _temp)) || _class) || _class) || _class);
export { TrashBox as default };