'use strict';

exports.__esModule = true;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var CollectedImage = _react2.default.createClass({
	displayName: 'CollectedImage',
	getInitialState: function getInitialState() {
		return {
			html: null
		};
	},
	componentWillMount: function componentWillMount() {
		window.promiseCollectedImageURL(this.props).then(this.onLoad, this.onError);
	},
	onLoad: function onLoad(result) {
		this.setState(result);
	},
	onError: function onError(error) {
		this.setState({ error: error });
	},
	render: function render() {
		var text = this.props.text;
		var _state = this.state,
		    html = _state.html,
		    error = _state.error;


		if (html) {
			return _react2.default.createElement('div', { dangerouslySetInnerHTML: { __html: html } });
		} else if (error) {
			return _react2.default.createElement('div', { children: 'Error: ' + error.message });
		}

		return text;
	}
});

exports.default = CollectedImage;
module.exports = exports['default'];