import R from 'ramda';
import React from 'react';
import seeds, { Seed } from 'react-seeds';

import multilinedText from './multilinedText';

var metaFontSize = 14;

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

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

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

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

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

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

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

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

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