'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _styles = require('@material-ui/core/styles');

var _Typography = require('@material-ui/core/Typography');

var _Typography2 = _interopRequireDefault(_Typography);

var _Image = require('../Image');

var _Image2 = _interopRequireDefault(_Image);

var _MarkerIcon = require('./MarkerIcon');

var _MarkerIcon2 = _interopRequireDefault(_MarkerIcon);

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

var MFPropTypes = _interopRequireWildcard(_prop_types);

var _FormattedValue = require('../Shared/FormattedValue');

var _FormattedValue2 = _interopRequireDefault(_FormattedValue);

var _FeatureTable = require('../Shared/FeatureTable');

var _FeatureTable2 = _interopRequireDefault(_FeatureTable);

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 styles = {
  root: {
    backgroundColor: 'white'
  },
  header: {
    display: 'flex',
    padding: 16,
    alignItems: 'center'
  },
  avatar: {
    flex: '0 0 auto',
    marginRight: 16
  },
  headerContent: {
    flex: '1 1 auto'
  },
  media: {
    position: 'relative',
    height: '100%',
    padding: '67% 0 0 0'
  },
  img: {
    width: '100%',
    height: '100%',
    top: 0,
    left: 0,
    position: 'absolute',
    objectFit: 'cover'
  }
};

var ReportFeature = function ReportFeature(_ref) {
  var label = _ref.label,
      classes = _ref.classes,
      colorIndex = _ref.colorIndex,
      feature = _ref.feature,
      fieldAnalysis = _ref.fieldAnalysis,
      fieldMapping = _ref.fieldMapping,
      fieldOrder = _ref.fieldOrder,
      settings = _ref.settings,
      hiddenFields = _ref.hiddenFields;

  var props = feature.properties;
  var media = props[fieldMapping.media];
  var title = props[fieldMapping.title];
  var subtitle = props[fieldMapping.subtitle];
  var color = colorIndex[props[fieldMapping.color]] || props[fieldMapping.color] && colorIndex[props[fieldMapping.color][0]];
  var analysisProps = fieldAnalysis.properties;
  var titleType = analysisProps[fieldMapping.title] && analysisProps[fieldMapping.title].type;
  var subtitleType = analysisProps[fieldMapping.subtitle] && analysisProps[fieldMapping.subtitle].type;

  return _react2.default.createElement(
    'div',
    { className: classes.root },
    _react2.default.createElement(
      'div',
      { className: classes.header },
      _react2.default.createElement(
        'div',
        { className: classes.avatar },
        _react2.default.createElement(_MarkerIcon2.default, { color: color, className: classes.markerIcon, label: label })
      ),
      _react2.default.createElement(
        'div',
        { className: classes.headerContent },
        _react2.default.createElement(
          _Typography2.default,
          { variant: 'title' },
          _react2.default.createElement(_FormattedValue2.default, { value: title, type: titleType })
        ),
        _react2.default.createElement(
          _Typography2.default,
          { variant: 'subheading' },
          _react2.default.createElement(_FormattedValue2.default, { value: subtitle, type: subtitleType })
        )
      )
    ),
    media && _react2.default.createElement(
      'div',
      { className: classes.media },
      _react2.default.createElement(_Image2.default, { className: classes.img, src: media })
    ),
    _react2.default.createElement(_FeatureTable2.default, {
      feature: feature,
      fieldAnalysis: fieldAnalysis,
      fieldOrder: fieldOrder,
      hiddenFields: hiddenFields,
      coordFormat: settings.coordFormat
    })
  );
};

ReportFeature.propTypes = {
  label: _propTypes2.default.string,
  classes: _propTypes2.default.object.isRequired,
  settings: MFPropTypes.settings.isRequired,
  colorIndex: MFPropTypes.colorIndex.isRequired,
  feature: MFPropTypes.feature.isRequired,
  fieldAnalysis: MFPropTypes.fieldAnalysis.isRequired,
  fieldMapping: MFPropTypes.fieldMapping.isRequired,
  fieldOrder: _propTypes2.default.object,
  hiddenFields: _propTypes2.default.object
};

exports.default = (0, _styles.withStyles)(styles)(ReportFeature);
//# sourceMappingURL=ReportFeature.js.map