text: define(["exports", "../../../@polymer/polymer/lib/utils/flattened-nodes-observer.js", "../../../@polymer/polymer/lib/utils/debounce.js", "../../../@polymer/polymer/lib/utils/async.js", "../../../@polymer/polymer/polymer-element.js"], function (_exports, _flattenedNodesObserver, _debounce, _async, _polymerElement) {
    "use strict";
  
    Object.defineProperty(_exports, "__esModule", {
      value: true
    });
    _exports.DynamicColumnsMixin = void 0;
  
    function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = babelHelpers.getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = babelHelpers.getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return babelHelpers.possibleConstructorReturn(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; } }
  
    /**
     * @polymerMixin
     */
    var DynamicColumnsMixin = function DynamicColumnsMixin(superClass) {
      return /*#__PURE__*/function (_superClass) {
        babelHelpers.inherits(DynamicColumnsMixin, _superClass);
  
        var _super = _createSuper(DynamicColumnsMixin);
  
        function DynamicColumnsMixin() {
          babelHelpers.classCallCheck(this, DynamicColumnsMixin);
          return _super.apply(this, arguments);
        }
  
        babelHelpers.createClass(DynamicColumnsMixin, [{
          key: "ready",
  
          /** @protected */
          value: function ready() {
            babelHelpers.get(babelHelpers.getPrototypeOf(DynamicColumnsMixin.prototype), "ready", this).call(this);
  
            this._addNodeObserver();
          }
          /** @private */
  
        }, {
          key: "_hasColumnGroups",
          value: function _hasColumnGroups(columns) {
            for (var i = 0; i < columns.length; i++) {
              if (columns[i].localName === 'vaadin-grid-column-group') {
                return true;
              }
            }
  
            return false;
          }
          /**
           * @param {!GridColumnGroupElement} el
           * @return {!Array<!GridColumnElement>}
           * @protected
           */
  
        }, {
          key: "_getChildColumns",
          value: function _getChildColumns(el) {
            return _flattenedNodesObserver.FlattenedNodesObserver.getFlattenedNodes(el).filter(this._isColumnElement);
          }
          /** @private */
  
        }, {
          key: "_flattenColumnGroups",
          value: function _flattenColumnGroups(columns) {
            var _this = this;
  
            return columns.map(function (col) {
              if (col.localName === 'vaadin-grid-column-group') {
                return _this._getChildColumns(col);
              } else {
                return [col];
              }
            }).reduce(function (prev, curr) {
              return prev.concat(curr);
            }, []);
          }
          /** @private */
  
        }, {
          key: "_getColumnTree",
          value: function _getColumnTree() {
            var rootColumns = _flattenedNodesObserver.FlattenedNodesObserver.getFlattenedNodes(this).filter(this._isColumnElement);
  
            var _columnTree = [];
  
            for (var c = rootColumns;;) {
              _columnTree.push(c);
  
              if (!this._hasColumnGroups(c)) {
                break;
              }
  
              c = this._flattenColumnGroups(c);
            }
  
            return _columnTree;
          }
          /** @protected */
  
        }, {
          key: "_updateColumnTree",
          value: function _updateColumnTree() {
            var columnTree = this._getColumnTree();
  
            if (!this._arrayEquals(columnTree, this._columnTree)) {
              this._columnTree = columnTree;
            }
          }
          /** @private */
  
        }, {
          key: "_addNodeObserver",
          value: function _addNodeObserver() {
            var _this2 = this;
  
            this._observer = new _flattenedNodesObserver.FlattenedNodesObserver(this, function (info) {
              var rowDetailsTemplate = info.addedNodes.filter(function (n) {
                return n.localName === 'template' && n.classList.contains('row-details');
              })[0];
  
              if (rowDetailsTemplate && _this2._rowDetailsTemplate !== rowDetailsTemplate) {
                _this2._rowDetailsTemplate = rowDetailsTemplate;
              }
  
              if (info.addedNodes.filter(_this2._isColumnElement).length > 0 || info.removedNodes.filter(_this2._isColumnElement).length > 0) {
                _this2._updateColumnTree();
              }
  
              _this2._debouncerCheckImports = _debounce.Debouncer.debounce(_this2._debouncerCheckImports, _async.timeOut.after(2000), _this2._checkImports.bind(_this2));
  
              _this2._ensureFirstPageLoaded();
            });
          }
          /** @private */
  
        }, {
          key: "_arrayEquals",
          value: function _arrayEquals(arr1, arr2) {
            if (!arr1 || !arr2 || arr1.length != arr2.length) {
              return false;
            }
  
            for (var i = 0, l = arr1.length; i < l; i++) {
              // Check if we have nested arrays
              if (babelHelpers.instanceof(arr1[i], Array) && babelHelpers.instanceof(arr2[i], Array)) {
                // recurse into the nested arrays
                if (!this._arrayEquals(arr1[i], arr2[i])) {
                  return false;
                }
              } else if (arr1[i] != arr2[i]) {
                return false;
              }
            }
  
            return true;
          }
          /** @protected */
  
        }, {
          key: "_checkImports",
          value: function _checkImports() {
            var _this3 = this;
  
            ['vaadin-grid-column-group', 'vaadin-grid-filter', 'vaadin-grid-filter-column', 'vaadin-grid-tree-toggle', 'vaadin-grid-selection-column', 'vaadin-grid-sort-column', 'vaadin-grid-sorter'].forEach(function (elementName) {
              var element = _this3.querySelector(elementName);
  
              if (element && !babelHelpers.instanceof(element, _polymerElement.PolymerElement)) {
                console.warn("Make sure you have imported the required module for <".concat(elementName, "> element."));
              }
            });
          }
          /** @protected */
  
        }, {
          key: "_updateFirstAndLastColumn",
          value: function _updateFirstAndLastColumn() {
            var _this4 = this;
  
            Array.from(this.shadowRoot.querySelectorAll('tr')).forEach(function (row) {
              return _this4._updateFirstAndLastColumnForRow(row);
            });
          }
          /**
           * @param {!HTMLElement} row
           * @protected
           */
  
        }, {
          key: "_updateFirstAndLastColumnForRow",
          value: function _updateFirstAndLastColumnForRow(row) {
            var _this5 = this;
  
            Array.from(row.querySelectorAll('[part~="cell"]:not([part~="details-cell"])')).sort(function (a, b) {
              return a._column._order - b._column._order;
            }).forEach(function (cell, cellIndex, children) {
              _this5._toggleAttribute('first-column', cellIndex === 0, cell);
  
              _this5._toggleAttribute('last-column', cellIndex === children.length - 1, cell);
            });
          }
          /**
           * @param {!Node} node
           * @return {boolean}
           * @protected
           */
  
        }, {
          key: "_isColumnElement",
          value: function _isColumnElement(node) {
            return node.nodeType === Node.ELEMENT_NODE && /\bcolumn\b/.test(node.localName);
          }
        }]);
        return DynamicColumnsMixin;
      }(superClass);
    };
  
    _exports.DynamicColumnsMixin = DynamicColumnsMixin;
  });