'use strict';

exports.__esModule = true;
exports.useWithFallback = exports.howmany = exports.whatsize = 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);

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

var Error = function Error(message) {
	return _react2.default.createElement(
		_reactSeeds.Seed,
		{ text: { color: 'red' } },
		message
	);
};

var whatsize = exports.whatsize = function whatsize(tags, references, text, children, Element, resolveContent) {
	if (_ramda2.default.isNil(tags.within)) {
		return Error('Add tag #within');
	} else if (_ramda2.default.isNil(tags.count)) {
		return Error('Add tag #count');
	}

	var within = parseFloat(resolveContent(tags.within));
	var count = parseFloat(resolveContent(tags.count));

	return _react2.default.createElement(
		_reactSeeds.Seed,
		null,
		'Within ',
		within,
		' \xB7 Count ',
		count,
		' \xB7 Individual size = ',
		within / count
	);
};

var howmany = exports.howmany = function howmany(tags, references, text, children, Element, resolveContent) {
	if (_ramda2.default.isNil(tags.within)) {
		return Error('Add tag #within');
	} else if (_ramda2.default.isNil(tags.size)) {
		return Error('Add tag #size');
	}

	var within = parseFloat(resolveContent(tags.within));
	var size = parseFloat(resolveContent(tags.size));
	var count = within / size;
	var remainder = within % size;

	return _react2.default.createElement(
		_reactSeeds.Seed,
		null,
		_react2.default.createElement(
			_reactSeeds.Seed,
			{ row: true },
			_react2.default.createElement(_reactSeeds.Seed, { basis: Math.floor(count) * size, background: { color: '#e41' }, height: '1rem' }),
			_react2.default.createElement(_reactSeeds.Seed, { basis: remainder, background: { color: '#ed1' } })
		),
		'Within ',
		within,
		' \xB7 Size ',
		size,
		' \xB7 Count = ',
		count,
		' \xB7 Remainder = ',
		remainder
	);
};

var useWithFallback = exports.useWithFallback = function useWithFallback(fallback) {
	return _ramda2.default.cond([[_ramda2.default.has('whatsize'), _ramda2.default.curry(whatsize)], [_ramda2.default.has('howmany'), _ramda2.default.curry(howmany)], [_ramda2.default.T, fallback]]);
};