'use strict';

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

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

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

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

var _SearchResultTable2 = _interopRequireDefault(_SearchResultTable);

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

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

var mapStateToProps = function mapStateToProps(state, ownProps) {
  var intl = ownProps.intl,
      config = ownProps.config,
      recordType = ownProps.recordType,
      searchName = ownProps.searchName,
      searchDescriptor = ownProps.searchDescriptor;


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

        return column.formatValue(data, formatterContext);
      }

      return data;
    },
    formatColumnLabel: function formatColumnLabel(column) {
      return intl.formatMessage(column.messages.label);
    },
    isSearchPending: (0, _reducers.isSearchPending)(state, searchName, searchDescriptor),
    searchResult: (0, _reducers.getSearchResult)(state, searchName, searchDescriptor),
    searchError: (0, _reducers.getSearchError)(state, searchName, searchDescriptor)
  };
};

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

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