"use strict";var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=exports.composeStyles=void 0;var _extends2=_interopRequireDefault(require("@babel/runtime/helpers/extends")),_objectWithoutProperties2=_interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")),_classCallCheck2=_interopRequireDefault(require("@babel/runtime/helpers/classCallCheck")),_createClass2=_interopRequireDefault(require("@babel/runtime/helpers/createClass")),_assertThisInitialized2=_interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized")),_inherits2=_interopRequireDefault(require("@babel/runtime/helpers/inherits")),_possibleConstructorReturn2=_interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn")),_getPrototypeOf2=_interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf")),_defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty")),_react=_interopRequireDefault(require("react")),_theme=require("../../config/theme"),_classnames=_interopRequireDefault(require("classnames")),_lodash=_interopRequireDefault(require("lodash")),_reactJss=_interopRequireDefault(require("react-jss"));function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable})),keys.push.apply(keys,symbols)}return keys}function _objectSpread(target){for(var source,i=1;i<arguments.length;i++)source=null==arguments[i]?{}:arguments[i],i%2?ownKeys(Object(source),!0).forEach(function(key){(0,_defineProperty2["default"])(target,key,source[key])}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key))});return target}function _createSuper(Derived){var hasNativeReflectConstruct=_isNativeReflectConstruct();return function(){var result,Super=(0,_getPrototypeOf2["default"])(Derived);if(hasNativeReflectConstruct){var NewTarget=(0,_getPrototypeOf2["default"])(this).constructor;result=Reflect.construct(Super,arguments,NewTarget)}else result=Super.apply(this,arguments);return(0,_possibleConstructorReturn2["default"])(this,result)}}function _isNativeReflectConstruct(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],function(){})),!0}catch(e){return!1}}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 _this;(0,_classCallCheck2["default"])(this,Wrapper);for(var _len=arguments.length,args=Array(_len),_key=0;_key<_len;_key++)args[_key]=arguments[_key];return _this=_super.call.apply(_super,[this].concat(args)),(0,_defineProperty2["default"])((0,_assertThisInitialized2["default"])(_this),"styledComponent",void 0),(0,_defineProperty2["default"])((0,_assertThisInitialized2["default"])(_this),"state",{classes:{}}),(0,_defineProperty2["default"])((0,_assertThisInitialized2["default"])(_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}(0,_inherits2["default"])(Wrapper,_React$Component);var _super=_createSuper(Wrapper);return(0,_createClass2["default"])(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=(0,_objectWithoutProperties2["default"])(_this$props,["classes"]);// eslint-disable-line
return/*#__PURE__*/_react["default"].createElement(StyledComponent,(0,_extends2["default"])({ref:function ref(_ref){_this2.styledComponent=_ref}},rest,{classes:this.state.classes}))}}]),Wrapper}(_react["default"].Component);return(0,_defineProperty2["default"])(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(_objectSpread({},mergedStyles),style)}),mergedStyles}};exports.composeStyles=composeStyles;var _default=withStyles;exports["default"]=_default;