'use strict';

exports.__esModule = true;
exports.useWithFallback = exports.commandline = exports.email = undefined;

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 _multilinedText = require('./multilinedText');

var _multilinedText2 = _interopRequireDefault(_multilinedText);

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

var metaFontSize = 14;

function MetaPair(_ref) {
	var title = _ref.title,
	    content = _ref.content,
	    resolveContent = _ref.resolveContent;

	if (!content) {
		return _react2.default.createElement('noscript', null);
	}

	return _react2.default.createElement(
		_reactSeeds.Seed,
		{ Component: 'dl',
			row: true,
			margin: { bottom: '0.5em' }
		},
		_react2.default.createElement(_reactSeeds.Seed, { Component: 'dt',
			children: title,
			margin: { right: '0.5em' },
			font: { size: metaFontSize, weight: 'bold' }
		}),
		_react2.default.createElement(_reactSeeds.Seed, { Component: 'dd',
			children: resolveContent(content),
			font: { size: metaFontSize }
		})
	);
}

function EmailParagraph(_ref2) {
	var children = _ref2.children;

	return _react2.default.createElement('p', { style: { marginBottom: '1.3em' }, children: children });
}

var email = exports.email = function email(tags, references, text, children, Element, resolveContent) {
	return _react2.default.createElement(
		_reactSeeds.Seed,
		{ width: '90%',
			margin: 'auto',
			padding: { top: '0.5em', base: '1em' },
			text: { align: 'left' },
			boxShadow: '0 2px 8px #bbb'
		},
		_react2.default.createElement(MetaPair, { resolveContent: resolveContent,
			title: 'From',
			content: tags.from || { text: 'hello@yourservice.com' }
		}),
		_react2.default.createElement(MetaPair, { resolveContent: resolveContent,
			title: 'To',
			content: tags.to || { text: 'user@example.com' }
		}),
		_react2.default.createElement(
			_reactSeeds.Seed,
			{ margin: { top: '1em' } },
			(0, _multilinedText2.default)(resolveContent({ text: text, references: references }), EmailParagraph)
		)
	);
};

var commandline = exports.commandline = function commandline(tags, references, text, children, Element, resolveContent) {
	return _react2.default.createElement(
		_reactSeeds.Seed,
		{ width: '90%',
			margin: 'auto',
			padding: '1em',
			text: { align: 'left', color: 'white' },
			font: { family: 'monospace' },
			background: { color: '#1f1f1f' },
			boxShadow: '0 2px 8px #bbb'
		},
		_react2.default.createElement(
			_reactSeeds.Seed,
			{ margin: 'auto' },
			resolveContent({ text: text, references: references })
		)
	);
};

var hasAll = _ramda2.default.pipe(_ramda2.default.map(_ramda2.default.has), _ramda2.default.allPass);

var useWithFallback = exports.useWithFallback = function useWithFallback(fallback) {
	return _ramda2.default.cond([[hasAll(['message', 'email']), _ramda2.default.curry(email)], [_ramda2.default.has('commandline'), _ramda2.default.curry(commandline)], [_ramda2.default.T, fallback]]);
};