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

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 _TabList = _interopRequireDefault(require("@instructure/ui-tabs/lib/components/TabList"));

var _TabPanel = _interopRequireDefault(require("@instructure/ui-tabs/lib/components/TabList/TabPanel"));

var _Tab = _interopRequireDefault(require("@instructure/ui-core/lib/components/TabList/Tab"));

var _ApplyTheme = _interopRequireDefault(require("@instructure/ui-themeable/lib/components/ApplyTheme"));

var _LinksPanel = _interopRequireDefault(require("./LinksPanel"));

var _FilesPanel = _interopRequireDefault(require("./FilesPanel"));

var _ImagesPanel = _interopRequireDefault(require("./ImagesPanel"));

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

  function Sidebar() {
    (0, _classCallCheck2.default)(this, Sidebar);
    return (0, _possibleConstructorReturn2.default)(this, (0, _getPrototypeOf2.default)(Sidebar).apply(this, arguments));
  }

  (0, _createClass2.default)(Sidebar, [{
    key: "disableFilesPanel",
    value: function disableFilesPanel() {
      return Object.keys(this.props.folders).length === 0 && Object.keys(this.props.files).length === 0;
    }
  }, {
    key: "render",
    value: function render() {
      if (this.props.hidden) {
        return _react.default.createElement("div", {
          style: {
            display: "none"
          }
        });
      }

      var panels = [_react.default.createElement(_TabPanel.default, {
        title: "\u05E7\u05D9\u05E9\u05D5\u05E8\u05D9\u05DD",
        key: "linksPanel"
      }, _react.default.createElement(_LinksPanel.default, {
        selectedIndex: this.props.selectedAccordionIndex,
        onChange: this.props.onChangeAccordion,
        fetchInitialPage: this.props.fetchInitialPage,
        fetchNextPage: this.props.fetchNextPage,
        contextType: this.props.contextType,
        contextId: this.props.contextId,
        collections: this.props.collections,
        onLinkClick: this.props.onLinkClick,
        toggleNewPageForm: this.props.toggleNewPageForm,
        newPageLinkExpanded: this.props.newPageLinkExpanded,
        canCreatePages: this.props.session.canCreatePages
      })), !this.props.filesTabDisabled && _react.default.createElement(_TabPanel.default, {
        title: "\u05E7\u05D1\u05E6\u05D9\u05DD ",
        key: "filesPanel",
        disabled: this.disableFilesPanel()
      }, _react.default.createElement(_FilesPanel.default, {
        withUploadForm: this.props.canUploadFiles,
        files: this.props.files,
        folders: this.props.folders,
        fetchFolders: this.props.fetchFolders,
        rootFolderId: this.props.rootFolderId,
        startUpload: this.props.startUpload.bind(null, "files"),
        onLinkClick: this.props.onLinkClick,
        toggleFolder: this.props.toggleFolder,
        upload: this.props.upload,
        toggleUploadForm: this.props.toggleUploadForm,
        canUploadFiles: this.props.session.canUploadFiles,
        usageRightsRequired: this.props.session.usageRightsRequired
      })), _react.default.createElement(_TabPanel.default, {
        id: "ImagesSidebarPanel",
        key: "imagesPanel",
        title: "\u05EA\u05DE\u05D5\u05E0\u05D5\u05EA"
      }, _react.default.createElement(_ImagesPanel.default, {
        withUploadForm: this.props.canUploadFiles,
        upload: this.props.upload,
        images: this.props.images,
        startUpload: this.props.startUpload.bind(null, "images"),
        fetchFolders: this.props.fetchFolders,
        fetchImages: this.props.fetchImages,
        flickr: this.props.flickr,
        flickrSearch: this.props.flickrSearch,
        toggleUploadForm: this.props.toggleUploadForm,
        toggleFlickrForm: this.props.toggleFlickrForm,
        onImageEmbed: this.props.onImageEmbed,
        usageRightsRequired: this.props.session.usageRightsRequired
      }))].filter(Boolean);
      return _react.default.createElement(_ApplyTheme.default, {
        theme: (0, _defineProperty2.default)({}, _Tab.default.theme, {
          fontSize: "0.8125rem"
        })
      }, _react.default.createElement(_TabList.default, {
        selectedIndex: this.props.selectedTabIndex,
        onChange: this.props.onChangeTab,
        focus: true
      }, panels));
    }
  }]);
  Sidebar.displayName = "Sidebar";
  return Sidebar;
}(_react.Component);

Sidebar.propTypes = {
  hidden: _propTypes.default.bool,
  selectedTabIndex: _propTypes.default.number,
  onChangeTab: _propTypes.default.func,
  selectedAccordionIndex: _propTypes.default.string,
  onChangeAccordion: _propTypes.default.func,
  contextType: _propTypes.default.string.isRequired,
  contextId: _propTypes.default.string.isRequired,
  collections: _propTypes.default.object.isRequired,
  fetchInitialPage: _propTypes.default.func,
  fetchNextPage: _propTypes.default.func,
  onLinkClick: _propTypes.default.func,
  onImageEmbed: _propTypes.default.func,
  toggleFolder: _FilesPanel.default.propTypes.toggleFolder,
  files: _FilesPanel.default.propTypes.files,
  folders: _FilesPanel.default.propTypes.folders,
  rootFolderId: _FilesPanel.default.propTypes.rootFolderId,
  images: _ImagesPanel.default.propTypes.images,
  flickr: _ImagesPanel.default.propTypes.flickr,
  fetchImages: _ImagesPanel.default.propTypes.fetchImages,
  fetchFolders: _ImagesPanel.default.propTypes.fetchFolders,
  flickrSearch: _ImagesPanel.default.propTypes.flickrSearch,
  canUploadFiles: _ImagesPanel.default.propTypes.withUploadForm,
  filesTabDisabled: _propTypes.default.bool,
  toggleFlickrForm: _ImagesPanel.default.propTypes.toggleFlickrForm,
  upload: _UploadForm.default.propTypes.upload,
  startUpload: _UploadForm.default.propTypes.startUpload,
  toggleUploadForm: _UploadForm.default.propTypes.toggleUploadForm,
  session: _propTypes.default.shape({
    canUploadFiles: _propTypes.default.bool,
    usageRightsRequired: _propTypes.default.bool,
    useHighContrast: _propTypes.default.bool,
    canCreatePages: _propTypes.default.bool
  }),
  toggleNewPageForm: _LinksPanel.default.propTypes.toggleNewPageForm,
  newPageLinkExpanded: _propTypes.default.bool
};
Sidebar.defaultProps = {
  hidden: false,
  selectedTabIndex: 0,
  selectedAccordionIndex: "",
  filesTabDisabled: false,
  canUploadFiles: false,
  files: {},
  folders: {}
};
var _default = Sidebar;
exports.default = _default;