'use strict';

exports.__esModule = true;
exports.title = exports.Preview = exports.panel = exports.cta = exports.button = undefined;

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.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 _rgba = require('react-sow/rgba');

var _rgba2 = _interopRequireDefault(_rgba);

var _assets = require('./assets');

var assets = _interopRequireWildcard(_assets);

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 buttonTagsToClass = _ramda2.default.uncurryN(3, function (resolveContent, contentIsTrue) {
	return _ramda2.default.converge(_ramda2.default.unapply(_ramda2.default.join(' ')), [_ramda2.default.always('btn'), _ramda2.default.cond([[contentIsTrue('primary'), _ramda2.default.always('btn-primary')],
	//[ contentIsTrue('link'), R.always('btn-link') ],
	[_ramda2.default.T, _ramda2.default.always('btn-default')]]), _ramda2.default.cond([[contentIsTrue('large'), _ramda2.default.always('btn-lg')], [contentIsTrue('small'), _ramda2.default.always('btn-sm')], [contentIsTrue('extrasmall'), _ramda2.default.always('btn-xs')], [_ramda2.default.T, _ramda2.default.always('')]])]);
});

var button = exports.button = function button(tags, mentions, texts, children, Element, resolveContent) {
	var contentIsTrue = _ramda2.default.propSatisfies(function (value) {
		return resolveContent(value, { single: true }) == true;
	});

	var Component = 'button';
	var url = void 0;
	if (_ramda2.default.has('link', tags)) {
		Component = 'a';
		url = resolveContent(tags.link);
	}

	var onClick = void 0;
	if (_ramda2.default.has('toggle', tags)) {
		onClick = function onClick() {
			resolveContent(tags.toggle, { alter: _ramda2.default.not });
		};
	}

	return _react2.default.createElement(Component, _extends({
		href: url
	}, (0, _reactSeeds2.default)({
		alignSelf: 'center',
		margin: { bottom: '0.5rem' },
		maxWidth: '20em'
	}), {
		className: buttonTagsToClass(resolveContent, contentIsTrue, tags),
		children: texts,
		onClick: onClick
	}));
};
var cta = exports.cta = button;

var panelTagsToClass = _ramda2.default.uncurryN(3, function (resolveContent, contentIsTrue) {
	return _ramda2.default.converge(_ramda2.default.unapply(_ramda2.default.join(' ')), [_ramda2.default.always('panel'), _ramda2.default.cond([[contentIsTrue('primary'), _ramda2.default.always('panel-primary')], [contentIsTrue('success'), _ramda2.default.always('panel-success')], [contentIsTrue('info'), _ramda2.default.always('panel-info')], [contentIsTrue('warning'), _ramda2.default.always('panel-warning')], [contentIsTrue('danger'), _ramda2.default.always('panel-danger')], [_ramda2.default.T, _ramda2.default.always('panel-default')]])]);
});

var panel = exports.panel = function panel(tags, mentions, texts, children, Element, resolveContent) {
	var contentIsTrue = _ramda2.default.propSatisfies(function (value) {
		return resolveContent(value, true) == true;
	});

	return _react2.default.createElement(
		_reactSeeds.Seed,
		{ Component: 'div',
			className: panelTagsToClass(resolveContent, contentIsTrue, tags),
			alignSelf: 'center',
			margin: { bottom: '0.5rem' },
			maxWidth: '20em'
		},
		_react2.default.createElement(
			'div',
			{ className: 'panel-heading' },
			_react2.default.createElement('h2', { className: 'panel-title', children: texts })
		),
		_react2.default.createElement(
			'div',
			{ className: 'panel-body' },
			children.map(function (element, index) {
				return _react2.default.createElement(Element, _extends({}, element, { key: index }));
			})
		)
	);
};

var elementRendererForTags = Vanilla.extendTagConds([[_ramda2.default.has('field'), _ramda2.default.curry(Vanilla.makeField({ wrapInDiv: true, wrapperClassName: 'form-group', inputClassName: 'form-control' }))], [_ramda2.default.has('card'), _ramda2.default.curry(panel)], [_ramda2.default.has('panel'), _ramda2.default.curry(panel)], [_ramda2.default.has('button'), _ramda2.default.curry(button)], [_ramda2.default.has('cta'), _ramda2.default.curry(cta)]]);

var Preview = exports.Preview = (0, _render.renderTreeUsing)({ elementRendererForTags: elementRendererForTags });

var title = exports.title = 'Bootstrap 3';

function head() {
	return [_react2.default.createElement('link', { key: 'css',
		rel: 'stylesheet', type: 'text/css',
		href: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'
	}), _react2.default.createElement('script', { key: 'js',
		src: 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'
	})];
}