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 _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _defineProperty from "@babel/runtime/helpers/defineProperty";

var _dec, _class, _class2, _temp;

import React, { PureComponent } from 'react';
import { withTheme } from '@material-ui/core/styles';
import PropTypes from 'prop-types';
import { style } from 'typestyle';
import IconButton from '@material-ui/core/IconButton';
import HardwareComputer from '@material-ui/icons/Computer';
var cn = {
  input: style({
    display: 'none'
  })
};

var getCn = function getCn(props) {
  return {
    icon: style({
      borderWidth: 0,
      borderStyle: 'solid',
      borderColor: 'transparent',
      borderRadius: 2,
      borderTopWidth: props.theme.spacing.unit,
      backgroundColor: props.theme.palette.disabledColor
    })
  };
};

var _DesktopFile = (_dec = withTheme(), _dec(_class = (_temp = _class2 =
/*#__PURE__*/
function (_PureComponent) {
  _inherits(_DesktopFile, _PureComponent);

  function _DesktopFile() {
    var _getPrototypeOf2;

    var _this;

    _classCallCheck(this, _DesktopFile);

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _possibleConstructorReturn(this, (_getPrototypeOf2 = _getPrototypeOf(_DesktopFile)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _defineProperty(_assertThisInitialized(_assertThisInitialized(_this)), "handleChange", function (event) {
      _this.props.onOpen(Array.from(event.target.files));
    });

    return _this;
  }

  _createClass(_DesktopFile, [{
    key: "render",
    value: function render() {
      var _this2 = this;

      var dcn = getCn(this.props);
      return React.createElement("div", null, React.createElement("input", {
        multiple: true,
        type: "file",
        className: cn.input,
        ref: function ref(_ref) {
          return _ref && (_this2.input = _ref);
        },
        onChange: this.handleChange
      }), React.createElement(IconButton, {
        className: dcn.icon,
        onClick: function onClick() {
          return _this2.input && _this2.input.click();
        }
      }, React.createElement(HardwareComputer, null)));
    }
  }]);

  return _DesktopFile;
}(PureComponent), _defineProperty(_class2, "propTypes", {
  theme: PropTypes.object.isRequired,
  onOpen: PropTypes.func.isRequired
}), _temp)) || _class);

export { _DesktopFile as default };