"use strict";

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

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

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

var _reactIntl = require("react-intl");

var _reactRouter = require("react-router");

var _immutable = _interopRequireDefault(require("immutable"));

var _BatchPageContainer = _interopRequireDefault(require("../../containers/pages/BatchPageContainer"));

var _ReportPageContainer = _interopRequireDefault(require("../../containers/pages/ReportPageContainer"));

var _VocabularyPageContainer = _interopRequireDefault(require("../../containers/pages/VocabularyPageContainer"));

var _ToolNavBar = _interopRequireDefault(require("../navigation/ToolNavBar"));

var _TitleBar = _interopRequireDefault(require("../sections/TitleBar"));

var _permissionHelpers = require("../../helpers/permissionHelpers");

var _AdminPage = _interopRequireDefault(require("../../../styles/cspace-ui/AdminPage.css"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

const messages = (0, _reactIntl.defineMessages)({
  title: {
    "id": "toolPage.title",
    "defaultMessage": "Tools"
  }
});
const tabs = ['vocabulary', 'report', 'batch'];
const propTypes = {
  match: _propTypes.default.object,
  perms: _propTypes.default.instanceOf(_immutable.default.Map),
  preferredTab: _propTypes.default.string
};

function ToolPage(props) {
  const {
    match,
    perms,
    preferredTab
  } = props;
  const basename = match.url;

  const title = _react.default.createElement(_reactIntl.FormattedMessage, messages.title);

  const permittedTabs = tabs.filter(tab => (0, _permissionHelpers.canList)(tab, perms));

  if (permittedTabs.length === 0) {
    return null;
  }

  const redirectTabName = preferredTab || permittedTabs[0];
  return _react.default.createElement("div", {
    className: _AdminPage.default.common
  }, _react.default.createElement(_TitleBar.default, {
    title: title,
    updateDocumentTitle: true
  }), _react.default.createElement(_ToolNavBar.default, {
    basename: basename,
    tabs: permittedTabs
  }), _react.default.createElement(_reactRouter.Switch, null, _react.default.createElement(_reactRouter.Redirect, {
    exact: true,
    path: basename,
    to: "".concat(basename, "/").concat(redirectTabName)
  }), _react.default.createElement(_reactRouter.Route, {
    path: "".concat(basename, "/vocabulary/:csid?"),
    component: _VocabularyPageContainer.default
  }), _react.default.createElement(_reactRouter.Route, {
    path: "".concat(basename, "/report/:csid?"),
    component: _ReportPageContainer.default
  }), _react.default.createElement(_reactRouter.Route, {
    path: "".concat(basename, "/batch/:csid?"),
    component: _BatchPageContainer.default
  })));
}

ToolPage.propTypes = propTypes;