"use strict";

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

exports.__esModule = true;
exports.default = void 0;

require("core-js/modules/web.dom.iterable");

var _keys = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/object/keys"));

var _isArray = _interopRequireDefault(require("@babel/runtime-corejs2/core-js/array/is-array"));

// from https://github.com/youzan/vant/blob/dev/packages/mixins/bem.js

/**
 * bem helper
 * bem() // 'button'
 * bem('text') // 'button__text'
 * bem({ disabled }) // 'button button--disabled'
 * bem('text', { disabled }) // 'button__text button__text--disabled'
 * bem(['disabled', 'primary']) // 'button button--disabled button--primary'
 */
var ELEMENT = '__';
var MODS = '--';

var join = function join(name, el, symbol) {
  return el ? name + symbol + el : name;
};

var prefix = function prefix(name, mods) {
  if (typeof mods === 'string') {
    return join(name, mods, MODS);
  }

  if ((0, _isArray.default)(mods)) {
    return mods.filter(function (m) {
      return m;
    }).map(function (item) {
      return prefix(name, item);
    });
  }

  var ret = {};
  (0, _keys.default)(mods).forEach(function (key) {
    if (key) ret[name + MODS + key] = mods[key];
  });
  return ret;
};
/**
 * @mixin
*/


var _default = {
  methods: {
    bem(el, mods) {
      var name = this.$options.name;

      if (el && typeof el !== 'string') {
        mods = el;
        el = '';
      }

      el = join(name, el, ELEMENT);
      return mods ? [el, prefix(el, mods)] : el;
    }

  }
};
exports.default = _default;