"use strict";

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

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

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

var _get = _interopRequireDefault(require("lodash/get"));

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

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

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

const mapStateToProps = (state, ownProps) => {
  const {
    intl,
    config,
    recordType,
    searchName,
    searchDescriptor
  } = ownProps;
  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, _get.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 = (0, _reactRedux.connect)(mapStateToProps)(_SearchResultTable.default);
exports.ConnectedSearchResultTable = ConnectedSearchResultTable;

var _default = (0, _reactIntl.injectIntl)(ConnectedSearchResultTable);

exports.default = _default;