'use strict';

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

var _reselect = require('reselect');

var _field_analysis = require('./field_analysis');

var _field_analysis2 = _interopRequireDefault(_field_analysis);

var _constants = require('../constants');

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

/**
 * Pick the date field that appears in most records
 */
var getDateFieldName = (0, _reselect.createSelector)(_field_analysis2.default, function (fieldAnalysis) {
  var dateField = void 0;
  for (var fieldname in fieldAnalysis.properties) {
    var field = fieldAnalysis.properties[fieldname];
    if (field.type !== _constants.FIELD_TYPE_DATE) continue;
    if (!dateField || field.count > dateField.count) {
      dateField = field;
    }
  }
  return dateField && dateField.fieldname;
});

exports.default = getDateFieldName;
//# sourceMappingURL=date_field.js.map