'use strict';

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

var _reactRedux = require('react-redux');

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

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

var _get2 = _interopRequireDefault(_get);

var _SearchResultTable = require('../../components/search/SearchResultTable');

var _SearchResultTable2 = _interopRequireDefault(_SearchResultTable);

var _reducers = require('../../reducers');

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

const mapStateToProps = (state, ownProps) => {
  const intl = ownProps.intl,
        config = ownProps.config,
        recordType = ownProps.recordType,
        searchName = ownProps.searchName,
        searchDescriptor = ownProps.searchDescriptor;


  return {
    formatCellData: (column, data, rowData) => {
      if (column.formatValue) {
        const formatterContext = {
          intl,
          config,
          recordType,
          rowData
        };

        return column.formatValue(data, formatterContext);
      }

      return data;
    },
    formatColumnLabel: column => {
      const message = (0, _get2.default)(column, ['messages', 'label']);

      return message ? intl.formatMessage(message) : '';
    },
    perms: (0, _reducers.getUserPerms)(state),
    isSearchPending: (0, _reducers.isSearchPending)(state, searchName, searchDescriptor),
    searchResult: (0, _reducers.getSearchResult)(state, searchName, searchDescriptor),
    searchError: (0, _reducers.getSearchError)(state, searchName, searchDescriptor)
  };
};

const ConnectedSearchResultTable = exports.ConnectedSearchResultTable = (0, _reactRedux.connect)(mapStateToProps)(_SearchResultTable2.default);

exports.default = (0, _reactIntl.injectIntl)(ConnectedSearchResultTable);