'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _immutable = require('immutable');

var _immutable2 = _interopRequireDefault(_immutable);

var _transformimeReact = require('transformime-react');

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

class RichestMime extends _react2.default.Component {

  shouldComponentUpdate(nextProps) {
    // eslint-disable-line class-methods-use-this
    if (nextProps && nextProps.theme && this.props && nextProps.theme !== this.props.theme) {
      return true;
    }
    return false;
  }

  render() {
    const mimetype = (0, _transformimeReact.richestMimetype)(this.props.bundle, this.props.displayOrder, this.props.transforms);

    if (!mimetype) {
      // If no mimetype is supported, don't return a component
      return null;
    }

    const Transform = this.props.transforms.get(mimetype);
    const data = this.props.bundle.get(mimetype);
    const metadata = this.props.metadata.get(mimetype);
    return _react2.default.createElement(Transform, { data: data, metadata: metadata, theme: this.props.theme });
  }
}

exports.default = RichestMime;
RichestMime.propTypes = {
  displayOrder: _react2.default.PropTypes.instanceOf(_immutable2.default.List).isRequired,
  transforms: _react2.default.PropTypes.instanceOf(_immutable2.default.Map).isRequired,
  bundle: _react2.default.PropTypes.instanceOf(_immutable2.default.Map).isRequired,
  metadata: _react2.default.PropTypes.instanceOf(_immutable2.default.Map).isRequired,
  theme: _react2.default.PropTypes.string
};
RichestMime.defaultProps = {
  transforms: _transformimeReact.transforms,
  displayOrder: _transformimeReact.displayOrder,
  theme: 'light',
  metadata: new _immutable2.default.Map(),
  bundle: new _immutable2.default.Map()
};