function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { mergeData } from '../../vue';
import { NAME_ROW } from '../../constants/components';
import { PROP_TYPE_BOOLEAN, PROP_TYPE_NUMBER_STRING, PROP_TYPE_STRING } from '../../constants/props';
import { arrayIncludes, concat } from '../../utils/array';
import { getBreakpointsUpCached } from '../../utils/config';
import { identity } from '../../utils/identity';
import { memoize } from '../../utils/memoize';
import { create, keys, sortKeys } from '../../utils/object';
import { makeProp, makePropsConfigurable, suffixPropName } from '../../utils/props';
import { lowerCase, toString, trim } from '../../utils/string';

// --- Constants ---

var COMMON_ALIGNMENT = ['start', 'end', 'center'];

// --- Helper methods ---

// Compute a `row-cols-{breakpoint}-{cols}` class name
// Memoized function for better performance on generating class names
var computeRowColsClass = memoize(function (breakpoint, cols) {
  cols = trim(toString(cols));
  return cols ? lowerCase(['row-cols', breakpoint, cols].filter(identity).join('-')) : null;
});

// Get the breakpoint name from the `rowCols` prop name
// Memoized function for better performance on extracting breakpoint names
var computeRowColsBreakpoint = memoize(function (prop) {
  return lowerCase(prop.replace('cols', ''));
});

// Cached copy of the `row-cols` breakpoint prop names
// Will be populated when the props are generated
var rowColsPropList = [];

// --- Props ---

// Prop generator for lazy generation of props
export var generateProps = function generateProps() {
  // i.e. 'row-cols-2', 'row-cols-md-4', 'row-cols-xl-6', ...
  var rowColsProps = getBreakpointsUpCached().reduce(function (props, breakpoint) {
    props[suffixPropName(breakpoint, 'cols')] = makeProp(PROP_TYPE_NUMBER_STRING);
    return props;
  }, create(null));

  // Cache the row-cols prop names
  rowColsPropList = keys(rowColsProps);

  // Return the generated props
  return makePropsConfigurable(sortKeys(_objectSpread(_objectSpread({}, rowColsProps), {}, {
    alignContent: makeProp(PROP_TYPE_STRING, null, function (value) {
      return arrayIncludes(concat(COMMON_ALIGNMENT, 'between', 'around', 'stretch'), value);
    }),
    alignH: makeProp(PROP_TYPE_STRING, null, function (value) {
      return arrayIncludes(concat(COMMON_ALIGNMENT, 'between', 'around'), value);
    }),
    alignV: makeProp(PROP_TYPE_STRING, null, function (value) {
      return arrayIncludes(concat(COMMON_ALIGNMENT, 'baseline', 'stretch'), value);
    }),
    noGutters: makeProp(PROP_TYPE_BOOLEAN, false),
    tag: makeProp(PROP_TYPE_STRING, 'div')
  })), NAME_ROW);
};

// --- Main component ---

// We do not use `extend()` here as that would evaluate the props
// immediately, which we do not want to happen
// @vue/component
export var BRow = {
  name: NAME_ROW,
  functional: true,
  get props() {
    // Allow props to be lazy evaled on first access and
    // then they become a non-getter afterwards
    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get#Smart_self-overwriting_lazy_getters
    delete this.props;
    this.props = generateProps();
    return this.props;
  },
  render: function render(h, _ref) {
    var props = _ref.props,
      data = _ref.data,
      children = _ref.children;
    var alignV = props.alignV,
      alignH = props.alignH,
      alignContent = props.alignContent;

    // Loop through row-cols breakpoint props and generate the classes
    var classList = [];
    rowColsPropList.forEach(function (prop) {
      var c = computeRowColsClass(computeRowColsBreakpoint(prop), props[prop]);
      // If a class is returned, push it onto the array
      if (c) {
        classList.push(c);
      }
    });
    classList.push(_defineProperty(_defineProperty(_defineProperty({
      'no-gutters': props.noGutters
    }, "align-items-".concat(alignV), alignV), "justify-content-".concat(alignH), alignH), "align-content-".concat(alignContent), alignContent));
    return h(props.tag, mergeData(data, {
      staticClass: 'row',
      class: classList
    }), children);
  }
};