'use strict';

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

var _reselect = require('reselect');

var _objectAssign = require('object-assign');

var _objectAssign2 = _interopRequireDefault(_objectAssign);

var _featureFilterGeojson = require('feature-filter-geojson');

var _featureFilterGeojson2 = _interopRequireDefault(_featureFilterGeojson);

var _config = require('../../config.json');

var _config2 = _interopRequireDefault(_config);

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

// **THIS IS NOT A REGULAR SELECTOR**
// It is used within the Map component to construct
// GeoJSON with extra fields for the map. We use a
// selector to save re-constructing the GeoJSON
var getMapGeoJson = (0, _reselect.createSelector)(function (state) {
  return state.features;
}, function (state) {
  return state.fieldMapping;
}, function (state) {
  return state.colorIndex;
}, function (state) {
  return state.filter;
}, function (features, fieldMapping, colorIndex, filter) {
  var i = 0;
  var ff = (0, _featureFilterGeojson2.default)(filter);
  return {
    type: 'FeatureCollection',
    features: features.filter(function (f) {
      return f.geometry;
    }).map(function (f) {
      var newFeature = {
        type: 'feature',
        geometry: f.geometry,
        properties: (0, _objectAssign2.default)({}, f.properties, {
          __mf_id: f.id,
          __mf_color: colorIndex[f.properties[fieldMapping.color]]
        })
      };
      if (ff(f)) newFeature.properties.__mf_label = _config2.default.labelChars.charAt(i++);
      return newFeature;
    })
  };
});

exports.default = getMapGeoJson;
//# sourceMappingURL=map_geojson.js.map