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 { extend } from '../../../vue';
import { PROP_TYPE_ARRAY_OBJECT_STRING, PROP_TYPE_BOOLEAN, PROP_TYPE_BOOLEAN_STRING, PROP_TYPE_STRING } from '../../../constants/props';
import { identity } from '../../../utils/identity';
import { isBoolean } from '../../../utils/inspect';
import { makeProp } from '../../../utils/props';
import { safeVueInstance } from '../../../utils/safe-vue-instance';
import { toString } from '../../../utils/string';
import { attrsMixin } from '../../../mixins/attrs';

// Main `<table>` render mixin
// Includes all main table styling options

// --- Props ---

export var props = {
  bordered: makeProp(PROP_TYPE_BOOLEAN, false),
  borderless: makeProp(PROP_TYPE_BOOLEAN, false),
  captionTop: makeProp(PROP_TYPE_BOOLEAN, false),
  dark: makeProp(PROP_TYPE_BOOLEAN, false),
  fixed: makeProp(PROP_TYPE_BOOLEAN, false),
  hover: makeProp(PROP_TYPE_BOOLEAN, false),
  noBorderCollapse: makeProp(PROP_TYPE_BOOLEAN, false),
  outlined: makeProp(PROP_TYPE_BOOLEAN, false),
  responsive: makeProp(PROP_TYPE_BOOLEAN_STRING, false),
  small: makeProp(PROP_TYPE_BOOLEAN, false),
  // If a string, it is assumed to be the table `max-height` value
  stickyHeader: makeProp(PROP_TYPE_BOOLEAN_STRING, false),
  striped: makeProp(PROP_TYPE_BOOLEAN, false),
  tableClass: makeProp(PROP_TYPE_ARRAY_OBJECT_STRING),
  tableVariant: makeProp(PROP_TYPE_STRING)
};

// --- Mixin ---

// @vue/component
export var tableRendererMixin = extend({
  mixins: [attrsMixin],
  provide: function provide() {
    var _this = this;
    return {
      getBvTable: function getBvTable() {
        return _this;
      }
    };
  },
  // Don't place attributes on root element automatically,
  // as table could be wrapped in responsive `<div>`
  inheritAttrs: false,
  props: props,
  computed: {
    isTableSimple: function isTableSimple() {
      return false;
    },
    // Layout related computed props
    isResponsive: function isResponsive() {
      var responsive = this.responsive;
      return responsive === '' ? true : responsive;
    },
    isStickyHeader: function isStickyHeader() {
      var stickyHeader = this.stickyHeader;
      stickyHeader = stickyHeader === '' ? true : stickyHeader;
      return this.isStacked ? false : stickyHeader;
    },
    wrapperClasses: function wrapperClasses() {
      var isResponsive = this.isResponsive;
      return [this.isStickyHeader ? 'b-table-sticky-header' : '', isResponsive === true ? 'table-responsive' : isResponsive ? "table-responsive-".concat(this.responsive) : ''].filter(identity);
    },
    wrapperStyles: function wrapperStyles() {
      var isStickyHeader = this.isStickyHeader;
      return isStickyHeader && !isBoolean(isStickyHeader) ? {
        maxHeight: isStickyHeader
      } : {};
    },
    tableClasses: function tableClasses() {
      var _safeVueInstance = safeVueInstance(this),
        hover = _safeVueInstance.hover,
        tableVariant = _safeVueInstance.tableVariant,
        selectableTableClasses = _safeVueInstance.selectableTableClasses,
        stackedTableClasses = _safeVueInstance.stackedTableClasses,
        tableClass = _safeVueInstance.tableClass,
        computedBusy = _safeVueInstance.computedBusy;
      hover = this.isTableSimple ? hover : hover && this.computedItems.length > 0 && !computedBusy;
      return [
      // User supplied classes
      tableClass,
      // Styling classes
      {
        'table-striped': this.striped,
        'table-hover': hover,
        'table-dark': this.dark,
        'table-bordered': this.bordered,
        'table-borderless': this.borderless,
        'table-sm': this.small,
        // The following are b-table custom styles
        border: this.outlined,
        'b-table-fixed': this.fixed,
        'b-table-caption-top': this.captionTop,
        'b-table-no-border-collapse': this.noBorderCollapse
      }, tableVariant ? "".concat(this.dark ? 'bg' : 'table', "-").concat(tableVariant) : '',
      // Stacked table classes
      stackedTableClasses,
      // Selectable classes
      selectableTableClasses];
    },
    tableAttrs: function tableAttrs() {
      var _safeVueInstance2 = safeVueInstance(this),
        items = _safeVueInstance2.computedItems,
        filteredItems = _safeVueInstance2.filteredItems,
        fields = _safeVueInstance2.computedFields,
        selectableTableAttrs = _safeVueInstance2.selectableTableAttrs,
        computedBusy = _safeVueInstance2.computedBusy;
      var ariaAttrs = this.isTableSimple ? {} : {
        'aria-busy': toString(computedBusy),
        'aria-colcount': toString(fields.length),
        // Preserve user supplied `aria-describedby`, if provided
        'aria-describedby': this.bvAttrs['aria-describedby'] || this.$refs.caption ? this.captionId : null
      };
      var rowCount = items && filteredItems && filteredItems.length > items.length ? toString(filteredItems.length) : null;
      return _objectSpread(_objectSpread(_objectSpread({
        // We set `aria-rowcount` before merging in `$attrs`,
        // in case user has supplied their own
        'aria-rowcount': rowCount
      }, this.bvAttrs), {}, {
        // Now we can override any `$attrs` here
        id: this.safeId(),
        role: this.bvAttrs.role || 'table'
      }, ariaAttrs), selectableTableAttrs);
    }
  },
  render: function render(h) {
    var _safeVueInstance3 = safeVueInstance(this),
      wrapperClasses = _safeVueInstance3.wrapperClasses,
      renderCaption = _safeVueInstance3.renderCaption,
      renderColgroup = _safeVueInstance3.renderColgroup,
      renderThead = _safeVueInstance3.renderThead,
      renderTbody = _safeVueInstance3.renderTbody,
      renderTfoot = _safeVueInstance3.renderTfoot;
    var $content = [];
    if (this.isTableSimple) {
      $content.push(this.normalizeSlot());
    } else {
      // Build the `<caption>` (from caption mixin)
      $content.push(renderCaption ? renderCaption() : null);

      // Build the `<colgroup>`
      $content.push(renderColgroup ? renderColgroup() : null);

      // Build the `<thead>`
      $content.push(renderThead ? renderThead() : null);

      // Build the `<tbody>`
      $content.push(renderTbody ? renderTbody() : null);

      // Build the `<tfoot>`
      $content.push(renderTfoot ? renderTfoot() : null);
    }

    // Assemble `<table>`
    var $table = h('table', {
      staticClass: 'table b-table',
      class: this.tableClasses,
      attrs: this.tableAttrs,
      key: 'b-table'
    }, $content.filter(identity));

    // Add responsive/sticky wrapper if needed and return table
    return wrapperClasses.length > 0 ? h('div', {
      class: wrapperClasses,
      style: this.wrapperStyles,
      key: 'wrap'
    }, [$table]) : $table;
  }
});