"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 _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

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

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

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

var _FileTree = _interopRequireDefault(require("../../common/components/FileTree"));

var _formatMessage = _interopRequireDefault(require("../../format-message"));

var _UploadForm = _interopRequireDefault(require("./UploadForm"));

/*
 * 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 FilesPanel =
/*#__PURE__*/
function (_Component) {
  (0, _inherits2.default)(FilesPanel, _Component);

  function FilesPanel() {
    var _getPrototypeOf2;

    var _this;

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

    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, _getPrototypeOf2.default)(FilesPanel)).call.apply(_getPrototypeOf2, [this].concat(args)));

    _this.handleSelect = function (id) {
      var file = _this.props.files[id];

      _this.props.onLinkClick({
        title: file.name,
        href: file.url,
        embed: file.embed
      });
    };

    return _this;
  }

  (0, _createClass2.default)(FilesPanel, [{
    key: "renderUploadForm",
    value: function renderUploadForm() {
      if (this.props.withUploadForm) {
        return _react.default.createElement(_UploadForm.default, {
          fetchFolders: this.props.fetchFolders,
          upload: this.props.upload,
          toggleUploadForm: this.props.toggleUploadForm,
          startUpload: this.props.startUpload,
          usageRightsRequired: this.props.usageRightsRequired,
          messages: {
            expand: "Tukuake he k\u014Dnae hou",
            expandScreenreader: "K\u014Dnae Tukuake Pukapuka",
            collapse: "Whakakore k\u014Dnae tukuake",
            collapseScreenreader: "K\u014Dnae Tukuake Pukapuka"
          },
          showAltTextForm: false
        });
      }

      return null;
    }
  }, {
    key: "render",
    value: function render() {
      return _react.default.createElement("div", null, _react.default.createElement("p", null, "P\u0101whiri t\u0113tahi k\u014Dnae ki te k\u014Dkuhu i t\u0113tahi hononga tikiake mo taua k\u014Dnae."), this.props.rootFolderId != null && _react.default.createElement(_FileTree.default, {
        onSelect: this.handleSelect,
        onToggle: this.props.toggleFolder,
        files: this.props.files,
        folders: this.props.folders,
        folder: this.props.folders[this.props.rootFolderId],
        maxHeight: "37em"
      }), this.renderUploadForm());
    }
  }]);
  FilesPanel.displayName = "FilesPanel";
  return FilesPanel;
}(_react.Component);

exports.default = FilesPanel;
FilesPanel.propTypes = {
  withUploadForm: _propTypes.default.bool,
  files: _propTypes.default.objectOf(_propTypes.default.shape({
    id: _propTypes.default.number,
    name: _propTypes.default.string,
    type: _propTypes.default.string,
    url: _propTypes.default.string
  })),
  folders: _propTypes.default.objectOf(_propTypes.default.shape({
    id: _propTypes.default.number,
    name: _propTypes.default.string,
    filesUrl: _propTypes.default.string,
    foldersUrl: _propTypes.default.string
  })),
  rootFolderId: _propTypes.default.number,
  toggleFolder: _propTypes.default.func.isRequired,
  fetchFolders: _UploadForm.default.propTypes.fetchFolders,
  startUpload: _UploadForm.default.propTypes.startUpload,
  upload: _UploadForm.default.propTypes.upload,
  toggleUploadForm: _UploadForm.default.propTypes.toggleUploadForm,
  onLinkClick: _propTypes.default.func.isRequired,
  canUploadFiles: _propTypes.default.bool,
  usageRightsRequired: _propTypes.default.bool
};