var _class, _temp;

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

import React from 'react';
import PropTypes from 'prop-types';
import { withNaming as SetupBem } from '@bem-react/classname';

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

export 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.
 */
export var 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;
}(React.Component), _class.propTypes = {
  bem: PropTypes.oneOfType([PropTypes.string, PropTypes.array, PropTypes.object])
}, _class.defaultProps = {
  bem: ''
}, _temp);