"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Component = exports["default"] = void 0;

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));

var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

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

var _class, _temp;

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; 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 (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }

// http://bem.github.io/bem-react/interfaces/ipreset.html
var BEM = (0, _classname.withNaming)({
  e: '-',
  m: '_',
  v: '='
});
var _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.
 */

exports["default"] = _default;
var Component = (_temp = _class = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(BEMComponent, _React$Component);

  var _super = _createSuper(BEMComponent);

  function BEMComponent(props, rootClass) {
    var _this;

    (0, _classCallCheck2["default"])(this, BEMComponent);
    _this = _super.call(this, props);
    var bemRoot = rootClass || "".concat(_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 _this2;

      var bem = Array.isArray(_this.props.bem) ? _this.props.bem : [_this.props.bem];
      var cls = [_this.props.className || ''];
      return (_this2 = _this).bem.apply(_this2, (0, _toConsumableArray2["default"])(bem.map(_this.bem.modifiersFromArray)).concat([cls]));
    };

    return _this;
  }

  return BEMComponent;
}(_react["default"].Component), (0, _defineProperty2["default"])(_class, "propTypes", {
  bem: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].array, _propTypes["default"].object])
}), (0, _defineProperty2["default"])(_class, "defaultProps", {
  bem: ''
}), _temp);
exports.Component = Component;