'use strict';

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactDom = require('react-dom');

var _App = require('./App');

var _App2 = _interopRequireDefault(_App);

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

function initGateauAppElements(appElements) {
	for (var i = 0; i < appElements.length; i++) {
		var appElement = appElements[i];
		var destinationID = appElement.getAttribute('data-destination');
		var contentElement = appElement.querySelector('.gateau_content');
		var ingredientsElement = appElement.querySelector('.gateau_ingredients');
		var scenariosElement = appElement.querySelector('.gateau_scenarios');
		var content = contentElement.textContent.trim();
		var ingredients = ingredientsElement ? JSON.parse(ingredientsElement.textContent) : [];
		var scenarios = scenariosElement ? JSON.parse(scenariosElement.textContent) : [];
		(0, _reactDom.render)(_react2.default.createElement(_App2.default, {
			initialContent: content,
			initialDestinationID: destinationID,
			initialIngredients: ingredients,
			initialScenarios: scenarios
		}), appElement);
	}
}

// Render app elements on the page
initGateauAppElements(document.querySelectorAll('.gateau'));

// Allow dynamic app elements in the future
window.initGateauAppElements = initGateauAppElements;

if (!window.promiseCollectedText) {
	window.promiseCollectedText = function (options) {
		return Promise.resolve(null);
	};
}

if (!window.promiseCollectedImageURL) {
	window.promiseCollectedImageURL = function (options) {
		return Promise.reject({ message: 'No collected service' });
	};
}