"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.composeStyles=void 0;var _react=_interopRequireDefault(require("react")),_theme=require("../../config/theme"),_classnames=_interopRequireDefault(require("classnames")),_lodash=_interopRequireDefault(require("lodash")),_reactJss=_interopRequireDefault(require("react-jss"));function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}function _typeof(obj){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(obj){return typeof obj}:function(obj){return obj&&"function"==typeof Symbol&&obj.constructor===Symbol&&obj!==Symbol.prototype?"symbol":typeof obj},_typeof(obj)}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=null==arguments[i]?{}:arguments[i],ownKeys=Object.keys(source);"function"==typeof Object.getOwnPropertySymbols&&(ownKeys=ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym){return Object.getOwnPropertyDescriptor(source,sym).enumerable}))),ownKeys.forEach(function(key){_defineProperty(target,key,source[key])})}return target}function _extends(){return _extends=Object.assign||function(target){for(var source,i=1;i<arguments.length;i++)for(var key in source=arguments[i],source)Object.prototype.hasOwnProperty.call(source,key)&&(target[key]=source[key]);return target},_extends.apply(this,arguments)}function _objectWithoutProperties(source,excluded){if(null==source)return{};var key,i,target=_objectWithoutPropertiesLoose(source,excluded);if(Object.getOwnPropertySymbols){var sourceSymbolKeys=Object.getOwnPropertySymbols(source);for(i=0;i<sourceSymbolKeys.length;i++)key=sourceSymbolKeys[i],!(0<=excluded.indexOf(key))&&Object.prototype.propertyIsEnumerable.call(source,key)&&(target[key]=source[key])}return target}function _objectWithoutPropertiesLoose(source,excluded){if(null==source)return{};var key,i,target={},sourceKeys=Object.keys(source);for(i=0;i<sourceKeys.length;i++)key=sourceKeys[i],0<=excluded.indexOf(key)||(target[key]=source[key]);return target}function _classCallCheck(instance,Constructor){if(!(instance instanceof Constructor))throw new TypeError("Cannot call a class as a function")}function _defineProperties(target,props){for(var descriptor,i=0;i<props.length;i++)descriptor=props[i],descriptor.enumerable=descriptor.enumerable||!1,descriptor.configurable=!0,"value"in descriptor&&(descriptor.writable=!0),Object.defineProperty(target,descriptor.key,descriptor)}function _createClass(Constructor,protoProps,staticProps){return protoProps&&_defineProperties(Constructor.prototype,protoProps),staticProps&&_defineProperties(Constructor,staticProps),Constructor}function _possibleConstructorReturn(self,call){return call&&("object"===_typeof(call)||"function"==typeof call)?call:_assertThisInitialized(self)}function _getPrototypeOf(o){return _getPrototypeOf=Object.setPrototypeOf?Object.getPrototypeOf:function(o){return o.__proto__||Object.getPrototypeOf(o)},_getPrototypeOf(o)}function _inherits(subClass,superClass){if("function"!=typeof superClass&&null!==superClass)throw new TypeError("Super expression must either be null or a function");subClass.prototype=Object.create(superClass&&superClass.prototype,{constructor:{value:subClass,writable:!0,configurable:!0}}),superClass&&_setPrototypeOf(subClass,superClass)}function _setPrototypeOf(o,p){return _setPrototypeOf=Object.setPrototypeOf||function(o,p){return o.__proto__=p,o},_setPrototypeOf(o,p)}function _assertThisInitialized(self){if(void 0===self)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return self}function _defineProperty(obj,key,value){return key in obj?Object.defineProperty(obj,key,{value:value,enumerable:!0,configurable:!0,writable:!0}):obj[key]=value,obj}var withStyles=function(styles){return function(component){var StyledComponent=(0,_reactJss.default)(styles,{theming:_theme.theming})(component),Wrapper=/*#__PURE__*/function(_React$Component){function Wrapper(){var _getPrototypeOf2,_this;_classCallCheck(this,Wrapper);for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++)args[_key]=arguments[_key];return _this=_possibleConstructorReturn(this,(_getPrototypeOf2=_getPrototypeOf(Wrapper)).call.apply(_getPrototypeOf2,[this].concat(args))),_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)),"styledComponent",void 0),_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)),"state",{classes:{}}),_defineProperty(_assertThisInitialized(_assertThisInitialized(_this)),"_mergeClasses",function(props){// Merge classes generated by JSS and user classes
var oldClasses=_this.styledComponent.state.classes,userClasses=props.classes||{};Object.keys(oldClasses).forEach(function(classKey){oldClasses[classKey]=(0,_classnames.default)(oldClasses[classKey],userClasses[classKey])}),_this.setState({classes:oldClasses})}),_this}return _inherits(Wrapper,_React$Component),_createClass(Wrapper,[{key:"componentDidMount",value:function componentDidMount(){this._mergeClasses(this.props)}},{key:"componentDidUpdate",value:function componentDidUpdate(prevProps){_lodash.default.isEqual(this.props.classes,prevProps.classes)||this._mergeClasses(this.props)}},{key:"render",value:function render(){var _this2=this,_this$props=this.props,classes=_this$props.classes,rest=_objectWithoutProperties(_this$props,["classes"]);// eslint-disable-line
return _react.default.createElement(StyledComponent,_extends({ref:function ref(_ref){_this2.styledComponent=_ref}},rest,{classes:this.state.classes}))}}]),Wrapper}(_react.default.Component);return _defineProperty(Wrapper,"displayName",StyledComponent.displayName),Wrapper}},composeStyles=function(){for(var _len3=arguments.length,styles=Array(_len3),_key3=0;_key3<_len3;_key3++)styles[_key3]=arguments[_key3];return function(theme){var mergedStyles={};return styles.forEach(function(v){var style=v(theme);mergedStyles=_objectSpread({},mergedStyles,style)}),mergedStyles}};exports.composeStyles=composeStyles;var _default=withStyles;exports.default=_default;