'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

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

var _get = require('lodash/get');

var _get2 = _interopRequireDefault(_get);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _RecordSidebarToggleButton = require('../../../styles/cspace-ui/RecordSidebarToggleButton.css');

var _RecordSidebarToggleButton2 = _interopRequireDefault(_RecordSidebarToggleButton);

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

const messages = (0, _reactIntl.defineMessages)({
  hide: {
    'id': 'recordSidebarToggleButton.hide',
    'defaultMessage': 'Hide sidebar'
  },
  show: {
    'id': 'recordSidebarToggleButton.show',
    'defaultMessage': 'Show sidebar'
  }
});

const propTypes = {
  config: _propTypes2.default.object,
  recordType: _propTypes2.default.string,
  isRecordSidebarOpen: _propTypes2.default.bool,
  toggleRecordSidebar: _propTypes2.default.func
};

const defaultProps = {
  isRecordSidebarOpen: true
};

function RecordSidebarToggleButton(props) {
  const config = props.config,
        recordType = props.recordType,
        isRecordSidebarOpen = props.isRecordSidebarOpen,
        toggleRecordSidebar = props.toggleRecordSidebar;


  const serviceType = (0, _get2.default)(config, ['recordTypes', recordType, 'serviceConfig', 'serviceType']);
  const isAuthority = serviceType === 'authority';

  const className = (0, _classnames2.default)(isRecordSidebarOpen ? _RecordSidebarToggleButton2.default.normal : _RecordSidebarToggleButton2.default.closed, isAuthority ? _RecordSidebarToggleButton2.default.purple : _RecordSidebarToggleButton2.default.blue);

  const labelMessage = isRecordSidebarOpen ? messages.hide : messages.show;

  return _react2.default.createElement(
    'button',
    {
      className: className,
      name: 'toggleSidebar',
      type: 'button',
      onClick: toggleRecordSidebar
    },
    _react2.default.createElement(_reactIntl.FormattedMessage, labelMessage)
  );
}

RecordSidebarToggleButton.propTypes = propTypes;
RecordSidebarToggleButton.defaultProps = defaultProps;