'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _MediaSnapshotPanelContainer = require('../../containers/record/MediaSnapshotPanelContainer');

var _MediaSnapshotPanelContainer2 = _interopRequireDefault(_MediaSnapshotPanelContainer);

var _RelatedRecordPanelContainer = require('../../containers/record/RelatedRecordPanelContainer');

var _RelatedRecordPanelContainer2 = _interopRequireDefault(_RelatedRecordPanelContainer);

var _RecordBatchPanelContainer = require('../../containers/record/RecordBatchPanelContainer');

var _RecordBatchPanelContainer2 = _interopRequireDefault(_RecordBatchPanelContainer);

var _RecordReportPanelContainer = require('../../containers/record/RecordReportPanelContainer');

var _RecordReportPanelContainer2 = _interopRequireDefault(_RecordReportPanelContainer);

var _TermsUsedPanelContainer = require('../../containers/record/TermsUsedPanelContainer');

var _TermsUsedPanelContainer2 = _interopRequireDefault(_TermsUsedPanelContainer);

var _UsedByPanelContainer = require('../../containers/record/UsedByPanelContainer');

var _UsedByPanelContainer2 = _interopRequireDefault(_UsedByPanelContainer);

var _RecordSideBar = require('../../../styles/cspace-ui/RecordSideBar.css');

var _RecordSideBar2 = _interopRequireDefault(_RecordSideBar);

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

const propTypes = {
  config: _propTypes2.default.object,
  csid: _propTypes2.default.string,
  recordType: _propTypes2.default.string,
  vocabulary: _propTypes2.default.string,
  history: _propTypes2.default.object,
  isRelatable: _propTypes2.default.bool
};

function RecordSideBar(props) {
  const config = props.config,
        csid = props.csid,
        recordType = props.recordType,
        vocabulary = props.vocabulary,
        history = props.history,
        isRelatable = props.isRelatable;

  // TODO: Make sidebar components configurable based on service type/record type.

  const recordTypeConfig = config.recordTypes[recordType];

  if (!recordTypeConfig) {
    return null;
  }

  const serviceType = recordTypeConfig.serviceConfig.serviceType;
  const isAuthority = serviceType === 'authority';
  const isUtility = serviceType === 'utility';
  const panelColor = isAuthority ? 'purple' : 'blue';

  let mediaSnapshot = null;
  let relatedObjects = null;
  let relatedProcedures = null;
  let usedBy = null;
  let reports = null;
  let batchJobs = null;

  if (!isAuthority && !isUtility) {
    mediaSnapshot = _react2.default.createElement(_MediaSnapshotPanelContainer2.default, {
      color: panelColor,
      csid: csid,
      config: config,
      recordType: recordType
    });

    relatedObjects = _react2.default.createElement(_RelatedRecordPanelContainer2.default, {
      color: panelColor,
      columnSetName: 'narrow',
      csid: csid,
      config: config,
      history: history,
      name: 'relatedObjectPanel',
      recordType: recordType,
      relatedRecordType: 'collectionobject',
      showAddButton: isRelatable
    });

    relatedProcedures = _react2.default.createElement(_RelatedRecordPanelContainer2.default, {
      color: panelColor,
      csid: csid,
      columnSetName: 'narrow',
      config: config,
      history: history,
      name: 'relatedProcedurePanel',
      recordType: recordType,
      relatedRecordType: 'procedure',
      showAddButton: isRelatable
    });
  }

  if (!isUtility) {
    reports = _react2.default.createElement(_RecordReportPanelContainer2.default, {
      color: panelColor,
      csid: csid,
      config: config,
      recordType: recordType
    });

    batchJobs = _react2.default.createElement(_RecordBatchPanelContainer2.default, {
      color: panelColor,
      csid: csid,
      config: config,
      history: history,
      recordType: recordType
    });
  }

  if (isAuthority) {
    usedBy = _react2.default.createElement(_UsedByPanelContainer2.default, {
      color: panelColor,
      csid: csid,
      config: config,
      history: history,
      recordType: recordType,
      vocabulary: vocabulary
    });
  }

  return _react2.default.createElement(
    'div',
    { className: _RecordSideBar2.default[serviceType] },
    mediaSnapshot,
    _react2.default.createElement(_TermsUsedPanelContainer2.default, {
      color: panelColor,
      csid: csid,
      config: config,
      history: history,
      recordType: recordType,
      vocabulary: vocabulary
    }),
    relatedObjects,
    relatedProcedures,
    usedBy,
    reports,
    batchJobs
  );
}

RecordSideBar.propTypes = propTypes;