'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 _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 }; }

var propTypes = {
  config: _propTypes2.default.object,
  csid: _propTypes2.default.string,
  recordType: _propTypes2.default.string,
  vocabulary: _propTypes2.default.string,
  history: _propTypes2.default.object,
  workflowState: _propTypes2.default.string
};

function RecordSideBar(props) {
  var config = props.config,
      csid = props.csid,
      recordType = props.recordType,
      vocabulary = props.vocabulary,
      history = props.history,
      workflowState = props.workflowState;

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

  var recordTypeConfig = config.recordTypes[recordType];

  if (!recordTypeConfig) {
    return null;
  }

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

  var mediaSnapshot = null;
  var relatedObjects = null;
  var relatedProcedures = null;
  var usedBy = null;

  var showAddButton = workflowState !== 'locked';

  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: showAddButton
    });

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

  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
  );
}

RecordSideBar.propTypes = propTypes;