"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 _propTypes = _interopRequireDefault(require("prop-types"));

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

var _ToggleDetails = _interopRequireDefault(require("@instructure/ui-toggle-details/lib/components/ToggleDetails"));

var _View = _interopRequireDefault(require("@instructure/ui-layout/lib/components/View"));

var _LinkSet = _interopRequireDefault(require("./LinkSet"));

var _NavigationPanel = _interopRequireDefault(require("./NavigationPanel"));

var _LinkToNewPage = _interopRequireDefault(require("./LinkToNewPage"));

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

/*
 * 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/>.
 */
function AccordionSection(_ref) {
  var collection = _ref.collection,
      children = _ref.children,
      onChange = _ref.onChange,
      selectedIndex = _ref.selectedIndex,
      summary = _ref.summary;
  return _react.default.createElement(_View.default, {
    as: "div",
    margin: "xx-small none"
  }, _react.default.createElement(_ToggleDetails.default, {
    variant: "filled",
    summary: summary,
    expanded: selectedIndex === collection,
    onToggle: function onToggle(e, expanded) {
      return onChange(expanded ? collection : "");
    }
  }, _react.default.createElement("div", {
    style: {
      maxHeight: '20em',
      overflow: 'auto'
    }
  }, children)));
}

AccordionSection.propTypes = {
  collection: _propTypes.default.string.isRequired,
  children: _propTypes.default.node.isRequired,
  selectedIndex: _propTypes.default.string,
  summary: _ToggleDetails.default.propTypes.summary
};

function CollectionPanel(props) {
  return _react.default.createElement(AccordionSection, props, _react.default.createElement(_LinkSet.default, {
    fetchInitialPage: props.fetchInitialPage && function () {
      return props.fetchInitialPage(props.collection);
    },
    fetchNextPage: props.fetchNextPage && function () {
      return props.fetchNextPage(props.collection);
    },
    collection: props.collections[props.collection],
    onLinkClick: props.onLinkClick,
    suppressRenderEmpty: props.suppressRenderEmpty
  }), props.renderNewPageLink && _react.default.createElement(_LinkToNewPage.default, {
    onLinkClick: props.onLinkClick,
    toggleNewPageForm: props.toggleNewPageForm,
    newPageLinkExpanded: props.newPageLinkExpanded,
    contextId: props.contextId,
    contextType: props.contextType
  }));
}

CollectionPanel.propTypes = {
  collection: _propTypes.default.string.isRequired,
  renderNewPageLink: _propTypes.default.bool,
  suppressRenderEmpty: _propTypes.default.bool
};
CollectionPanel.defaultProps = {
  renderNewPageLink: false,
  suppressRenderEmpty: false
};

function LinksPanel(props) {
  var isCourse = props.contextType === "course";
  var isGroup = props.contextType === "group";
  var navigationSummary = isCourse ? "Course Navigation" : isGroup ? "Group Navigation" : "";
  return _react.default.createElement("div", null, _react.default.createElement("p", null, props.contextType === "course" ? "Link to other content in the course." : props.contextType === "group" ? "Link to other content in the group." : "", "Click any page to insert a link to that page."), _react.default.createElement("div", null, (isCourse || isGroup) && _react.default.createElement(CollectionPanel, Object.assign({}, props, {
    collection: "wikiPages",
    summary: "Pagini",
    renderNewPageLink: props.canCreatePages !== false,
    suppressRenderEmpty: props.canCreatePages !== false
  })), isCourse && _react.default.createElement(CollectionPanel, Object.assign({}, props, {
    collection: "assignments",
    summary: "Teme"
  })), isCourse && _react.default.createElement(CollectionPanel, Object.assign({}, props, {
    collection: "quizzes",
    summary: "Test"
  })), (isCourse || isGroup) && _react.default.createElement(CollectionPanel, Object.assign({}, props, {
    collection: "announcements",
    summary: "Anun\u021Buri"
  })), (isCourse || isGroup) && _react.default.createElement(CollectionPanel, Object.assign({}, props, {
    collection: "discussions",
    summary: "Discu\u021Bii"
  })), isCourse && _react.default.createElement(CollectionPanel, Object.assign({}, props, {
    collection: "modules",
    summary: "Modules"
  })), _react.default.createElement(AccordionSection, Object.assign({}, props, {
    collection: "navigation",
    summary: navigationSummary
  }), _react.default.createElement(_NavigationPanel.default, {
    contextType: props.contextType,
    contextId: props.contextId,
    onLinkClick: props.onLinkClick
  }))));
}

LinksPanel.propTypes = {
  selectedIndex: _propTypes.default.string,
  onChange: _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,
  toggleNewPageForm: _LinkToNewPage.default.propTypes.toggleNewPageForm,
  newPageLinkExpanded: _propTypes.default.bool,
  canCreatePages: _propTypes.default.bool
};
LinksPanel.defaultProps = {
  selectedIndex: ""
};
var _default = LinksPanel;
exports.default = _default;