'use strict';

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

var _keys = require('babel-runtime/core-js/object/keys');

var _keys2 = _interopRequireDefault(_keys);

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _prop_types = require('../../util/prop_types');

var MFPropTypes = _interopRequireWildcard(_prop_types);

var _ImageGrid = require('./ImageGrid');

var _ImageGrid2 = _interopRequireDefault(_ImageGrid);

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

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }

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

var MediaView = function (_React$Component) {
  (0, _inherits3.default)(MediaView, _React$Component);

  function MediaView() {
    (0, _classCallCheck3.default)(this, MediaView);
    return (0, _possibleConstructorReturn3.default)(this, (MediaView.__proto__ || (0, _getPrototypeOf2.default)(MediaView)).apply(this, arguments));
  }

  (0, _createClass3.default)(MediaView, [{
    key: 'shouldComponentUpdate',
    value: function shouldComponentUpdate(nextProps) {
      return nextProps.fieldAnalysis !== this.props.fieldAnalysis || nextProps.filteredFeatures !== this.props.filteredFeatures;
    }
  }, {
    key: 'getImages',
    value: function getImages() {
      var _props = this.props,
          fieldAnalysis = _props.fieldAnalysis,
          filteredFeatures = _props.filteredFeatures;

      var imageFieldNames = (0, _keys2.default)(fieldAnalysis.properties).filter(function (fieldname) {
        return fieldAnalysis.properties[fieldname].type === _constants.FIELD_TYPE_IMAGE;
      });
      return filteredFeatures.reduce(function (p, feature) {
        imageFieldNames.forEach(function (f) {
          if (feature.properties[f] && feature.properties[f] !== _constants.UNDEFINED_KEY) {
            p.push({
              url: feature.properties[f],
              featureId: feature.id
            });
          }
        });
        return p;
      }, []);
    }
  }, {
    key: 'render',
    value: function render() {
      var showFeatureDetail = this.props.showFeatureDetail;

      var images = this.getImages();
      return _react2.default.createElement(_ImageGrid2.default, { images: images, onImageClick: showFeatureDetail });
    }
  }]);
  return MediaView;
}(_react2.default.Component);

MediaView.propTypes = {
  showFeatureDetail: _propTypes2.default.func.isRequired,
  fieldAnalysis: MFPropTypes.fieldAnalysis,
  filteredFeatures: _propTypes2.default.arrayOf(MFPropTypes.mapViewFeature).isRequired
};

MediaView.MfViewId = 'media';

exports.default = MediaView;
//# sourceMappingURL=MediaView.js.map