'use strict';

exports.__esModule = true;

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; };

var _react = require('react');

var React = _interopRequireWildcard(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _wrapDisplayName = require('recompose/wrapDisplayName');

var _wrapDisplayName2 = _interopRequireDefault(_wrapDisplayName);

var _recompose = require('recompose');

var _prefix = require('./prefix');

var _prefix2 = _interopRequireDefault(_prefix);

var _constants = require('./constants');

var _reactFlowTypes = require('react-flow-types');

var _TypeDefinition = require('./TypeDefinition');

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

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 _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); if (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; }

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); }

var withStyleProps = function withStyleProps() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return function (Component) {
    var hasSize = options.hasSize,
        hasStatus = options.hasStatus,
        hasColor = options.hasColor;

    var WithStyleProps = function (_React$Component) {
      _inherits(WithStyleProps, _React$Component);

      function WithStyleProps() {
        _classCallCheck(this, WithStyleProps);

        return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
      }

      WithStyleProps.prototype.render = function render() {
        var _props = this.props,
            classPrefix = _props.classPrefix,
            size = _props.size,
            color = _props.color,
            status = _props.status,
            innerRef = _props.innerRef,
            className = _props.className,
            props = _objectWithoutProperties(_props, ['classPrefix', 'size', 'color', 'status', 'innerRef', 'className']);

        var addPrefix = (0, _prefix2.default)(classPrefix);
        var classes = (0, _classnames2.default)(hasSize ? addPrefix(size) : null, hasColor ? addPrefix(color) : null, hasStatus ? addPrefix(status) : null, className);

        return React.createElement(Component, _extends({}, props, { classPrefix: classPrefix, className: classes, ref: innerRef }));
      };

      return WithStyleProps;
    }(React.Component);

    WithStyleProps.displayName = (0, _wrapDisplayName2.default)(Component, 'withStyleProps');
    WithStyleProps.defaultProps = Component.defaultProps;
    WithStyleProps.handledProps = [];
    WithStyleProps.propTypes = {
      className: _propTypes2.default.string,
      classPrefix: _propTypes2.default.string,
      innerRef: _propTypes2.default.func,
      size: function size() {
        return (typeof _TypeDefinition.bpfrpt_proptype_Size === 'function' ? _TypeDefinition.bpfrpt_proptype_Size : _propTypes2.default.shape(_TypeDefinition.bpfrpt_proptype_Size)).apply(this, arguments);
      },
      color: function color() {
        return (typeof _TypeDefinition.bpfrpt_proptype_Size === 'function' ? _TypeDefinition.bpfrpt_proptype_Size : _propTypes2.default.shape(_TypeDefinition.bpfrpt_proptype_Size)).apply(this, arguments);
      },
      status: function status() {
        return (typeof _TypeDefinition.bpfrpt_proptype_Size === 'function' ? _TypeDefinition.bpfrpt_proptype_Size : _propTypes2.default.shape(_TypeDefinition.bpfrpt_proptype_Size)).apply(this, arguments);
      }
    };


    var propTypes = {
      innerRef: _propTypes2.default.func
    };

    if (hasSize) {
      propTypes.size = _propTypes2.default.oneOf(_constants.SIZE);
    }

    if (hasColor) {
      propTypes.color = _propTypes2.default.oneOf(_constants.COLOR);
    }

    if (hasStatus) {
      propTypes.status = _propTypes2.default.oneOf(_constants.STATUS);
    }

    (0, _recompose.setPropTypes)(propTypes)(WithStyleProps);

    return WithStyleProps;
  };
};

withStyleProps.handledProps = [];
exports.default = withStyleProps;