'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var __chunk_1 = require('./chunk-2b268ae7.js');
var React = require('react');
var React__default = _interopDefault(React);
var nanoCss = require('nano-css');
var cache = require('nano-css/addon/cache');
var stable = require('nano-css/addon/stable');
var nesting = require('nano-css/addon/nesting');
var keyframes = require('nano-css/addon/keyframes');
var unitless = require('nano-css/addon/unitless');
var rule = require('nano-css/addon/rule');
var sheet = require('nano-css/addon/sheet');
var __chunk_3 = require('./chunk-6d243953.js');

var withTheme = function withTheme(styles) {
	if (typeof styles === 'function') {
		return styles(__chunk_1.theme);
	}
	return styles;
};

var nano = nanoCss.create({
	// Add prefix to all generated class names.
	pfx: 'es-'
});

// Add addons you would like to use.
cache.addon(nano);
stable.addon(nano);
nesting.addon(nano);
keyframes.addon(nano);
rule.addon(nano);
sheet.addon(nano);
unitless.addon(nano);
var reduceAttributes = function reduceAttributes(selector, props) {
	Object.keys(selector).reduce(function (memo, key) {
		return memo[key] = typeof selector[key] === 'function' ? selector[key](props) : selector[key];
	}, {});
};

var withNano = function withNano(styles, _displayName) {
	return function (WrappedComponent) {
		var displayName = _displayName || WrappedComponent.displayName || WrappedComponent.name || 'Component';
		var themedStyles = withTheme(styles);

		var _Object$keys$reduce = Object.keys(themedStyles).reduce(function (memo, key) {
			var idx = typeof themedStyles[key] === 'function' ? 1 : 0;
			memo[idx][key] = themedStyles[key];
			return memo;
		}, [{}, {}]),
		    _Object$keys$reduce2 = __chunk_3.slicedToArray(_Object$keys$reduce, 2),
		    baseStyles = _Object$keys$reduce2[0],
		    dynamicStyles = _Object$keys$reduce2[1];
		// const baseClasses = nano.sheet(baseStyles, displayName);


		var Component = function Component(props) {
			var compiledStyles = Object.keys(dynamicStyles).reduce(function (memo, key) {
				memo[key] = dynamicStyles[key](props);
				return memo;
			}, {});
			var rnd = Math.random().toString(36).substr(2);
			// const dynamicClasses = nano.sheet(compiledStyles, `${displayName}-${rnd}`);
			var stylesWithDynamicAtrr = Object.keys(__chunk_3._extends({}, baseStyles, compiledStyles)).reduce(function (memo, key, _, arr) {
				return memo[key] = reduceAttributes(arr[key], props);
			});
			var classes = nano.sheet(stylesWithDynamicAtrr, displayName);
			return React__default.createElement(WrappedComponent, __chunk_3._extends({ classes: __chunk_3._extends({}, baseClasses, dynamicClasses) }, props));
		};
		Component.displayName = 'WithNano(' + displayName + ')';
		return Component;
	};
};

function createCommonjsModule(fn, module) {
	return module = { exports: {} }, fn(module, module.exports), module.exports;
}

var classnames = createCommonjsModule(function (module) {
/*!
  Copyright (c) 2017 Jed Watson.
  Licensed under the MIT License (MIT), see
  http://jedwatson.github.io/classnames
*/
/* global define */

(function () {

	var hasOwn = {}.hasOwnProperty;

	function classNames () {
		var classes = [];

		for (var i = 0; i < arguments.length; i++) {
			var arg = arguments[i];
			if (!arg) continue;

			var argType = typeof arg;

			if (argType === 'string' || argType === 'number') {
				classes.push(arg);
			} else if (Array.isArray(arg) && arg.length) {
				var inner = classNames.apply(null, arg);
				if (inner) {
					classes.push(inner);
				}
			} else if (argType === 'object') {
				for (var key in arg) {
					if (hasOwn.call(arg, key) && arg[key]) {
						classes.push(key);
					}
				}
			}
		}

		return classes.join(' ');
	}

	if (module.exports) {
		classNames.default = classNames;
		module.exports = classNames;
	} else {
		window.classNames = classNames;
	}
}());
});

exports.withNano = withNano;
exports.classNames = classnames;
//# sourceMappingURL=chunk-8c403bc9.js.map
