'use strict';

exports.__esModule = true;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.default = PreviewSection;

var _ramda = require('ramda');

var _ramda2 = _interopRequireDefault(_ramda);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactSeeds = require('react-seeds');

var _reactSeeds2 = _interopRequireDefault(_reactSeeds);

var _reactFrameComponent = require('react-frame-component');

var _reactFrameComponent2 = _interopRequireDefault(_reactFrameComponent);

var _Button = require('../../ui/Button');

var _Button2 = _interopRequireDefault(_Button);

var _Choice = require('../../ui/Choice');

var _Choice2 = _interopRequireDefault(_Choice);

var _stylers = require('../../stylers');

var stylers = _interopRequireWildcard(_stylers);

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 catchRenderErrors = false;

var iframeStyler = (0, _reactSeeds2.default)({
	//grow: 1,
	height: 600,
	border: 'none'
});

function DestinationChoice(_ref) {
	var destinationID = _ref.destinationID,
	    destinationDevice = _ref.destinationDevice,
	    destinations = _ref.destinations,
	    onChange = _ref.onChange,
	    onPhoneDestination = _ref.onPhoneDestination,
	    onFullDestination = _ref.onFullDestination;

	var items = _ramda2.default.pipe(_ramda2.default.toPairs, _ramda2.default.map(_ramda2.default.converge(_ramda2.default.merge, [_ramda2.default.pipe(_ramda2.default.prop(0), _ramda2.default.objOf('value')), _ramda2.default.pipe(_ramda2.default.prop(1), _ramda2.default.pick(['title']))])))(destinations);

	return _react2.default.createElement(
		_reactSeeds.Seed,
		{ row: true, width: '100%' },
		_react2.default.createElement(_Choice2.default, {
			value: destinationID,
			items: items,
			width: '100%',
			minHeight: 32,
			grow: 1,
			border: 'none'
			//maxWidth='20em'
			, onChange: onChange,
			styler: stylers.masterButton
		}),
		_react2.default.createElement(_Button2.default, {
			onClick: onPhoneDestination,
			children: 'Phone',
			selected: destinationDevice == 'phone',
			styler: stylers.masterButton
		}),
		_react2.default.createElement(_Button2.default, {
			onClick: onFullDestination,
			children: 'Full',
			selected: destinationDevice == 'full',
			styler: stylers.masterButton
		})
	);
}

function PreviewSection(_ref2) {
	var contentTree = _ref2.contentTree,
	    ingredients = _ref2.ingredients,
	    destinationID = _ref2.destinationID,
	    destinationDevice = _ref2.destinationDevice,
	    destinations = _ref2.destinations,
	    onChangeDestination = _ref2.onChangeDestination,
	    onPhoneDestination = _ref2.onPhoneDestination,
	    onFullDestination = _ref2.onFullDestination;
	var _destinations$destina = destinations[destinationID],
	    renderHead = _destinations$destina.head,
	    Preview = _destinations$destina.Preview;


	return _react2.default.createElement(
		_reactSeeds.Seed,
		_extends({ column: true, alignItems: 'center'
		}, stylers.previewColumn({ destinationDevice: destinationDevice })),
		_react2.default.createElement(
			_reactSeeds.Seed,
			{ key: destinationID,
				column: true,
				grow: 1, width: '100%'
			},
			!!contentTree ? false ? _ramda2.default.tryCatch(function (contentTree) {
				return _react2.default.createElement(Preview, {
					ingredients: ingredients,
					contentTree: contentTree
				});
			}, function (error, contentTree) {
				return console.error('Invalid tree', error, contentTree);
			})(contentTree) : _react2.default.createElement(
				_reactFrameComponent2.default,
				_extends({
					head: renderHead()
				}, iframeStyler),
				_react2.default.createElement(Preview, {
					ingredients: ingredients,
					contentTree: contentTree
				})
			) : null
		),
		_react2.default.createElement(DestinationChoice, {
			destinationID: destinationID,
			destinationDevice: destinationDevice,
			destinations: destinations,
			onChange: onChangeDestination,
			onPhoneDestination: onPhoneDestination,
			onFullDestination: onFullDestination
		})
	);
}
module.exports = exports['default'];