"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

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

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

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

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

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

var _react = _interopRequireWildcard(require("react"));

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

var _aphrodite = require("aphrodite");

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

var _IconDocument = _interopRequireDefault(require("@instructure/ui-icons/lib/Line/IconDocument"));

/*
 * Copyright (C) 2018 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */
var File =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(File, _Component);

  function File() {
    var _getPrototypeOf2;

    var _this;

    (0, _classCallCheck2.default)(this, File);

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

    _this = (0, _possibleConstructorReturn2.default)(this, (_getPrototypeOf2 = (0, _getPrototypeOf3.default)(File)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.handleSelect = function () {
      var _this$props = _this.props,
          onSelect = _this$props.onSelect,
          file = _this$props.file;

      if (onSelect) {
        onSelect(file.id);
      }
    };

    return _this;
  }

  (0, _createClass2.default)(File, [{
    key: "icon",
    value: function icon() {
      switch (this.props.file.type) {
        default:
          return _react.default.createElement(_IconDocument.default, null);
      }
    }
  }, {
    key: "render",
    value: function render() {
      var name = this.props.file.name;
      return _react.default.createElement("button", {
        className: (0, _aphrodite.css)(_styles.default.button, _styles.default.file),
        onClick: this.handleSelect
      }, this.icon(), " ", name);
    }
  }]);
  File.displayName = "File";
  return File;
}(_react.Component);

exports.default = File;
File.propTypes = {
  file: (0, _propTypes.shape)({
    id: _propTypes.number,
    name: _propTypes.string,
    type: _propTypes.string
  }).isRequired,
  onSelect: _propTypes.func
};