'use strict';

exports.__esModule = true;
exports.title = exports.Preview = undefined;
exports.head = head;

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

var Vanilla = _interopRequireWildcard(_Vanilla);

var _render = require('./render');

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 backgroundColor = '#191919';

var Code = function Code(_ref) {
	var children = _ref.children,
	    _ref$indent = _ref.indent,
	    indent = _ref$indent === undefined ? 0 : _ref$indent;
	return _react2.default.createElement(
		_reactSeeds.Seed,
		{ Component: 'pre',
			grow: 1, width: '100%',
			text: { align: 'left', whitespace: 'pre-wrap', color: 'white' },
			background: { color: backgroundColor }
		},
		_ramda2.default.repeat('  ', indent),
		children
	);
};

var field = function field(tags, references, text) {
	return _react2.default.createElement(
		Code,
		null,
		'    <label\n      <span>' + text + '</span>\n      <input type=\'' + (Vanilla.isPassword(tags, text) ? 'password' : 'text') + '\' />\n    </label>\n'
	);
};

var button = function button(tag, mentions, text) {
	return _react2.default.createElement(Code, { children: '<button>' + text + '</button>', indent: 2 });
};

var image = function image(tag, mentions, text) {
	return _react2.default.createElement(
		Code,
		null,
		'    <figure>\n      <img src="...">\n      <figcaption>' + text + '</figcaption>\n    </figure>\n'
	);
};

var text = function text(tag, mentions, _text, children) {
	return _react2.default.createElement(
		Code,
		{ children: '<span>' + (mentions[0] || _text) + '</span>', indent: 2 },
		'<span>',
		_ramda2.default.ifElse(_ramda2.default.isNil, _ramda2.default.always(_text), function (mentionName) {
			return '{ ' + mentionName + ' }';
		})(mentions[0]),
		'</span>'
	);
};

var elementRendererForTags = _ramda2.default.cond([[_ramda2.default.has('field'), _ramda2.default.curry(field)], [_ramda2.default.has('button'), _ramda2.default.curry(button)], [_ramda2.default.has('cta'), _ramda2.default.curry(button)], [_ramda2.default.has('image'), _ramda2.default.curry(image)],
// [ R.has('video'), R.curry(Web.video) ],
[_ramda2.default.has('text'), _ramda2.default.curry(text)],
// [ R.has('swatch'), R.curry(Web.swatch) ],
// [ R.has('nav'), R.curry(Web.nav) ],
// [ R.has('columns'), R.curry(Web.columns) ],
// [ R.has('list'), R.curry(Web.list) ],
[_ramda2.default.T, _ramda2.default.curry(text)]]);

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

	return _react2.default.createElement(_reactSeeds.Seed, { children: children });
}

function Master(_ref3) {
	var children = _ref3.children,
	    ingredients = _ref3.ingredients;

	var ingredientIDs = _ramda2.default.pipe(_ramda2.default.keys, _ramda2.default.join(', '))(ingredients);

	return _react2.default.createElement(
		_reactSeeds.Seed,
		{
			background: { color: backgroundColor }
		},
		_react2.default.createElement(Code, { children: 'function Component({ ' + ingredientIDs + ' }) {' }),
		_react2.default.createElement(Code, { children: 'return (', indent: 1 }),
		children,
		_react2.default.createElement(Code, { children: ')', indent: 1 }),
		_react2.default.createElement(Code, { children: '}' })
	);
}

var Preview = exports.Preview = _ramda2.default.pipe((0, _render.renderTreeUsing)({
	elementRendererForTags: elementRendererForTags,
	Section: Section,
	Master: Master
}));

var title = exports.title = 'React Code';

function head() {
	return [];
}