'use strict';

exports.__esModule = true;
exports.Component = undefined;

var _class, _temp;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classname = require('@bem-react/classname');

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

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) : subClass.__proto__ = superClass; }

// http://bem.github.io/bem-react/interfaces/ipreset.html
var BEM = (0, _classname.withNaming)({
  e: '-',
  m: '_',
  v: '='
});

exports.default = BEM;

/**
 * A core React component class which your elements can extend to add support for generating standard BEM classes on the fly. See [`@bem-react/classname`](https://github.com/bem/bem-react/tree/master/packages/classname#bem-reactclassname---) for further information on how we generate BEM classes.
 */

var Component = exports.Component = (_temp = _class = function (_React$Component) {
  _inherits(BEMComponent, _React$Component);

  function BEMComponent(props, rootClass) {
    _classCallCheck(this, BEMComponent);

    var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));

    var bemRoot = rootClass || ('' + _this.constructor).match(/function\s?(\S*)\s?\(/)[1];
    var bemClass = BEM(bemRoot);

    _this.bem = function (E, M, X) {
      return bemClass(E, M, X);
    };

    _this.bem.modifiersFromArray = function (arg) {
      return Array.isArray(arg) && arg.reduce(function (sum, key) {
        sum[key] = true;
        return sum;
      }, {}) || arg;
    };

    _this.bem.classes = function () {
      var bem = Array.isArray(_this.props.bem) ? _this.props.bem : [_this.props.bem];
      var cls = [_this.props.className || ''];
      return _this.bem.apply(_this, bem.map(_this.bem.modifiersFromArray).concat([cls]));
    };
    return _this;
  }

  return BEMComponent;
}(_react2.default.Component), _class.propTypes = {
  bem: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.array, _propTypes2.default.object])
}, _class.defaultProps = {
  bem: ''
}, _temp);