define(["exports", "require", "../../../lit-element/lit-element.js", "./editable-table-behaviors.js", "../../responsive-utility/lib/responsive-utility-behaviors.js", "../../simple-picker/simple-picker.js"], function (_exports, _require, _litElement, _editableTableBehaviors, _responsiveUtilityBehaviors, _simplePicker) {
  "use strict";

  Object.defineProperty(_exports, "__esModule", {
    value: true
  });
  _exports.EditableTableDisplay = void 0;
  _require = babelHelpers.interopRequireWildcard(_require);

  function _templateObject12_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral(["<span class=\"cell\"\n            >", "</span\n          >"]);

    _templateObject12_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject12_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  function _templateObject11_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral(["\n            <editable-table-filter\n              class=\"cell\"\n              column-index=\"", "\"\n              ?filtered=\"", "\"\n            >\n              ", "\n            </editable-table-filter>\n          "]);

    _templateObject11_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject11_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  function _templateObject10_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral(["<td\n      part=\"td\"\n      class=\"td th-or-td\"\n      cell-index=\"", "\"\n      ?numeric=\"", "\"\n      ?negative=\"", "\"\n      ?xs-hidden=\"", "\"\n    >\n      ", "\n    </td>"]);

    _templateObject10_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject10_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  function _templateObject9_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral(["<th\n      class=\"th th-or-td\"\n      cell-index=\"", "\"\n      ?numeric=\"", "\"\n      scope=\"row\"\n      ?xs-hidden=\"", "\"\n    >\n      ", "\n    </th>"]);

    _templateObject9_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject9_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  function _templateObject8_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral(["\n      <tr class=\"tr ", "\">\n        ", "\n      </tr>\n    "]);

    _templateObject8_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject8_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { babelHelpers.defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

  function _templateObject7_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral(["\n              <tfoot class=\"tfoot\" part=\"tfoot\">\n                ", "\n              </tfoot>\n            "]);

    _templateObject7_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject7_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  function _templateObject6_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral(["\n                        <editable-table-sort\n                          column-index=\"", "\"\n                          sort-column=\"", "\"\n                        >\n                          ", "\n                        </editable-table-sort>\n                      "]);

    _templateObject6_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject6_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  function _templateObject5_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral(["\n                <th\n                  class=\"th th-or-td\"\n                  cell-index=\"", "\"\n                  ?numeric=\"", "\"\n                  scope=\"col\"\n                  part=\"th\"\n                  ?xs-hidden=\"", "\"\n                >\n                  ", "\n                </th>\n              "]);

    _templateObject5_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject5_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  function _templateObject4_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral(["\n                  <button id=\"print\" @click=\"", "\">\n                    <span class=\"sr-only\">Print table.</span>\n                    <simple-icon-lite icon=\"print\"></simple-icon-lite>\n                  </button>\n                  <simple-tooltip\n                    id=\"print-tooltip\"\n                    for=\"print\"\n                    aria-hidden=\"true\"\n                    >Print table.\n                  </simple-tooltip>\n                "]);

    _templateObject4_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject4_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  function _templateObject3_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral(["\n                  <button id=\"download\" @click=\"", "\">\n                    <span class=\"sr-only\">Download as CSV.</span>\n                    <simple-icon-lite icon=\"file-download\"></simple-icon-lite>\n                  </button>\n                  <simple-tooltip\n                    id=\"download-tooltip\"\n                    for=\"download\"\n                    aria-hidden=\"true\"\n                    >Download as CSV.\n                  </simple-tooltip>\n                "]);

    _templateObject3_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject3_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  function _templateObject2_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral([" <simple-picker\n                  id=\"column\"\n                  align-right\n                  aria-label=\"Select Column\"\n                  @change=\"", "\"\n                  hide-sample\n                  .options=\"", "\"\n                  .value=\"", "\"\n                >\n                </simple-picker>"]);

    _templateObject2_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject2_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  function _templateObject_3c8f9a3099b011eb851ed31c596cbbd8() {
    var data = babelHelpers.taggedTemplateLiteral(["\n      <table\n        id=\"table\"\n        ?bordered=\"", "\"\n        class=\"table\"\n        ?column-header=\"", "\"\n        ?column-striped=\"", "\"\n        ?condensed=\"", "\"\n        ?filter=\"", "\"\n        ?footer=\"", "\"\n        ?hidden=\"", "\"\n        ?numeric-styles=\"", "\"\n        ?row-header=\"", "\"\n        ?sort=\"", "\"\n        ?striped=\"", "\"\n        part=\"table\"\n      >\n        <caption part=\"caption\">\n          <div>\n            <div>", "</div>\n            ", "\n            ", "\n            ", "\n          </div>\n        </caption>\n        <thead ?hidden=\"", "\" class=\"thead\" part=\"thead\">\n          <tr class=\"tr thead-tr\" part=\"tr\">\n            ", "\n          </tr>\n        </thead>\n        <tbody class=\"tbody\" part=\"tbody\">\n          ", "\n        </tbody>\n        ", "\n      </table>\n      <div id=\"htmlImport\" hidden><slot></slot></div>\n    "]);

    _templateObject_3c8f9a3099b011eb851ed31c596cbbd8 = function _templateObject_3c8f9a3099b011eb851ed31c596cbbd8() {
      return data;
    };

    return data;
  }

  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; } }

  /**
   * `editable-table-display`
   * `An editor interface for editable-table
   *
   * @demo ./demo/editor.html
   * @customElement
   * @extends displayBehaviors
   * @extends editableTableDisplayStyles
   * @extends ResponsiveUtilityBehaviors
   * @extends LitElement
   */
  var EditableTableDisplay = /*#__PURE__*/function (_displayBehaviors) {
    babelHelpers.inherits(EditableTableDisplay, _displayBehaviors);

    var _super = _createSuper(EditableTableDisplay);

    babelHelpers.createClass(EditableTableDisplay, [{
      key: "render",
      value: function render() {
        var _this2 = this;

        return (0, _litElement.html)(_templateObject_3c8f9a3099b011eb851ed31c596cbbd8(), this.bordered, this.columnHeader, this.columnStriped, this.condensed, this.filter, this.footer, this.hidden, this.numericStyles, this.rowHeader, this.sort, this.striped, this.getHTML(this.caption), !this.disableResponsive ? (0, _litElement.html)(_templateObject2_3c8f9a3099b011eb851ed31c596cbbd8(), this._selectedChanged, this.options, this.selected) : "", !this.downloadable ? "" : (0, _litElement.html)(_templateObject3_3c8f9a3099b011eb851ed31c596cbbd8(), this.download), !this.printable ? "" : (0, _litElement.html)(_templateObject4_3c8f9a3099b011eb851ed31c596cbbd8(), this.print), !this.columnHeader, (this.thead[0] || []).map(function (th, index) {
          return (0, _litElement.html)(_templateObject5_3c8f9a3099b011eb851ed31c596cbbd8(), index, _this2._isNumericColumn(index), _this2._isColHidden(index, 1), !_this2.sort ? _this2.getHTML(_this2._replaceBlankCell(th)) : (0, _litElement.html)(_templateObject6_3c8f9a3099b011eb851ed31c596cbbd8(), index, _this2.sortColumn, _this2.getHTML(_this2._replaceBlankCell(th))));
        }), this.tbody.map(function (tr) {
          return _this2._isRowFiltered(tr) ? "" : _this2._tbodyTr(tr);
        }), !this.footer ? "" : (0, _litElement.html)(_templateObject7_3c8f9a3099b011eb851ed31c596cbbd8(), this._tbodyTr(this.tfoot[0], true, true)));
      }
    }], [{
      key: "styles",
      get: function get() {
        return [].concat(babelHelpers.toConsumableArray(babelHelpers.get(babelHelpers.getPrototypeOf(EditableTableDisplay), "styles", this) || []), babelHelpers.toConsumableArray(_editableTableBehaviors.editableTableDisplayStyles));
      }
    }, {
      key: "haxProperties",
      get: function get() {
        return {
          type: "element",
          editingElement: {
            tag: "editable-table",
            import: "@lrnwebcomponents/editable-table/editable-table.js"
          },
          canScale: true,
          canPosition: true,
          canEditSource: true,
          gizmo: {
            title: "Enhanced table",
            description: "A table for displaying data",
            icon: "image:grid-on",
            color: "blue-grey",
            groups: ["Content", "Table", "Data"],
            meta: {
              author: "ELMS:LN"
            }
          },
          settings: {
            configure: [],
            advanced: []
          },
          demoSchema: [{
            tag: "editable-table-display",
            content: "<table striped><tr><td>-</td><td>-</td><td>-</td></tr><tr><td>-</td><td>-</td><td>-</td></tr><tr><td>-</td><td>-</td><td>-</td></tr></table>",
            properties: {}
          }]
        };
      }
    }, {
      key: "tag",
      get: function get() {
        return "editable-table-display";
      }
    }, {
      key: "properties",
      get: function get() {
        return _objectSpread(_objectSpread(_objectSpread({}, _editableTableBehaviors.displayBehaviors.properties), _responsiveUtilityBehaviors.ResponsiveUtilityBehaviors.properties), {}, {
          /**
           * Index of current filter column
           */
          filterColumn: {
            type: Number,
            attribute: "filter-column"
          },

          /**
           * whether column only needs to contain filter text
           * instead of default requiriwhich requires an exact match
           */
          filterContains: {
            type: Boolean,
            attribute: "filter-contains"
          },

          /**
           * whether filter is case sensitive
           */
          filterCaseSensitive: {
            type: Boolean,
            attribute: "filter-case-sensitive"
          },

          /**
           * Whether table is filtered
           */
          filtered: {
            type: Boolean
          },

          /**
           * Text for Filtering
           */
          filterText: {
            type: String,
            attribute: "filter-text"
          },

          /**
           * Selected column to display when in responsive mode
           */
          selected: {
            type: Number
          },

          /**
           * Sort mode: ascending, descending or none
           */
          sortMode: {
            type: String,
            attribute: "sort-mode"
          },

          /**
           * Index of current sort column
           */
          sortColumn: {
            type: Number,
            attribute: "sort-column"
          }
        });
      }
    }]);

    function EditableTableDisplay() {
      var _this;

      babelHelpers.classCallCheck(this, EditableTableDisplay);
      _this = _super.call(this);
      _this.selected = 1;
      _this.sortMode = "none";
      _this.sortColumn = -1;
      _this.filterContains = true;
      new Promise(function (res, rej) {
        return _require.default(["./editable-table-sort.js"], res, rej);
      });
      new Promise(function (res, rej) {
        return _require.default(["./editable-table-filter.js"], res, rej);
      }); // notice changes and update the data to match

      _this._observer = new MutationObserver(function (mutations) {
        if (_this.shadowRoot) {
          _this.importHTML(_this.children.item(0));
        }
      });

      _this._observer.observe(babelHelpers.assertThisInitialized(_this), {
        childList: true,
        subtree: true
      });

      return _this;
    }

    babelHelpers.createClass(EditableTableDisplay, [{
      key: "connectedCallback",
      value: function connectedCallback() {
        var _this3 = this;

        babelHelpers.get(babelHelpers.getPrototypeOf(EditableTableDisplay.prototype), "connectedCallback", this).call(this);
        setTimeout(function () {
          _this3.addEventListener("change-sort-mode", _this3._changeSortMode.bind(_this3));

          _this3.addEventListener("toggle-filter", _this3.toggleFilter.bind(_this3));
        }, 0);
      }
    }, {
      key: "disconnectedCallback",
      value: function disconnectedCallback() {
        this.removeEventListener("change-sort-mode", this._changeSortMode.bind(this));
        this.removeEventListener("toggle-filter", this.toggleFilter.bind(this));
        babelHelpers.get(babelHelpers.getPrototypeOf(EditableTableDisplay.prototype), "disconnectedCallback", this).call(this);
      }
      /**
       *
       * Hides table if it has no data
       * @readonly
       * @memberof EditableTableDisplay
       */

    }, {
      key: "sortData",

      /**
       * initialize responsive columns menu
       *
       * @param {string} type  sort order ascending: "asc", descending: "desc", or "non"
       * @param {number} column column number
       * @memberof EditableTableDisplay
       */
      value: function sortData(type, column) {
        if (type !== "none" && type !== false) {
          var temp = this.tbody.map(function (row) {
            return [row[column]].concat(babelHelpers.toConsumableArray(row));
          });

          if (type === "asc") {
            temp.sort();
          } else {
            temp.reverse();
          }
        }
      }
      /**
       * Handle filter button click
       *
       * @param {event} e event
       * @memberof EditableTableDisplay
       */

    }, {
      key: "toggleFilter",
      value: function toggleFilter(e) {
        if (e === undefined || this.filterColumn == e.detail.columnIndex && this.filtered) {
          this.filtered = false;
          this.filterText = undefined;
          this.filterColumn = undefined;
        } else {
          this.filterText = e.detail.innerHTML;
          this.filterColumn = e.detail.columnIndex;
          this.filtered = true;
        }
      }
      /**
       * Fires when data changed
       * @event change
       * @param {event} event
       */

    }, {
      key: "_dataChanged",
      value: function _dataChanged(newValue, oldValue) {
        if (!newValue || newValue.length < 1 || newValue[0].length < 1) {
          var table = this.children.item(0);

          if (babelHelpers.typeof(table) !== (typeof undefined === "undefined" ? "undefined" : babelHelpers.typeof(undefined)) && table !== null && table.tagName === "TABLE") {
            this.importHTML(table);
          }
        }

        this.dispatchEvent(new CustomEvent("change", {
          bubbles: true,
          cancelable: true,
          composed: true,
          detail: newValue
        }));
      }
      /**
       * Handles sort button click
       * @param {event} e event
       */

    }, {
      key: "_changeSortMode",
      value: function _changeSortMode(e) {
        if (this.sortColumn === e.detail.columnIndex && this.sortMode === "asc") {
          this.sortMode = "desc";
        } else if (this.sortColumn === e.detail.columnIndex && this.sortMode === "desc") {
          this.sortMode = "none";
        } else {
          this.sortMode = "asc";
          this.sortColumn = e.detail.columnIndex;
        }

        e.detail.setSortMode(this.sortMode);
      }
      /**
       * Determines whether or not a cell is hidden in responsive mode
       * @param {number} index current column number
       * @param {number} selected selected column number
       * @returns {boolean} whether column is hidden (i.e. not selected column)
       */

    }, {
      key: "_isColHidden",
      value: function _isColHidden(index) {
        var selected = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
        selected = selected || 1;
        return parseInt(index) !== 0 && parseInt(index) !== parseInt(selected);
      }
      /**
       * Sets a column's cells to filtered when in filtered mode so that filter can toggle
       * @param {number} index current column number
       * @param {number} selected filtered column number
       * @param {boolean} filtered is table in filtered mode
       * @returns {boolean} whether column is filtered
       */

    }, {
      key: "_isCellFiltered",
      value: function _isCellFiltered(column, filterColumn, filtered) {
        return !!filterColumn && filterColumn === column && filtered;
      }
      /**
       * Handles column  selector change
       */

    }, {
      key: "_selectedChanged",
      value: function _selectedChanged() {
        this._updateCols();
      }
      /**
       * Handles table change
       */

    }, {
      key: "_tableChanged",
      value: function _tableChanged() {
        this._updateCols();
      }
      /**
       * table row template
       *
       * @param {array} [row=[]] array of cells
       * @param {boolean} [noFilter=false] has filter buttons
       * @param {boolean} [tfoot=false] is a footer row
       * @returns {html}
       * @memberof EditableTableDisplay
       */

    }, {
      key: "_tbodyTr",
      value: function _tbodyTr() {
        var _this4 = this;

        var row = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
        var noFilter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
        var tfoot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
        return (0, _litElement.html)(_templateObject8_3c8f9a3099b011eb851ed31c596cbbd8(), tfoot ? "tfoot-tr" : "tbody-tr", row.map(function (cell, index) {
          return _this4._isRowHeader(_this4.rowHeader, index) ? _this4._tbodyTh(cell, index) : _this4._tbodyTd(cell, index, noFilter);
        }));
      }
      /**
       * table header template
       *
       * @param {string} cell cell contents
       * @param {number} index column number
       * @returns {html}
       * @memberof EditableTableDisplay
       */

    }, {
      key: "_tbodyTh",
      value: function _tbodyTh(cell, index) {
        return (0, _litElement.html)(_templateObject9_3c8f9a3099b011eb851ed31c596cbbd8(), index, this._isNumericColumn(index), this._isColHidden(index, 1), this.getHTML(this._replaceBlankCell(cell)));
      }
      /**
       * table cell template
       *
       * @param {*} cell cell contents
       * @param {*} index column number
       * @param {boolean} [noFilter=false] whether to include a filter button
       * @returns {html}
       * @memberof EditableTableDisplay
       */

    }, {
      key: "_tbodyTd",
      value: function _tbodyTd(cell, index) {
        var noFilter = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
        return (0, _litElement.html)(_templateObject10_3c8f9a3099b011eb851ed31c596cbbd8(), index, this._isNumericColumn(index), this._isNegative(cell), this._isColHidden(index, 1), this.filter ? (0, _litElement.html)(_templateObject11_3c8f9a3099b011eb851ed31c596cbbd8(), index, this._isCellFiltered(index, this.filterColumn, this.filtered), this.getHTML(this._replaceBlankCell(cell))) : !noFilter ? (0, _litElement.html)(_templateObject12_3c8f9a3099b011eb851ed31c596cbbd8(), this.getHTML(this._replaceBlankCell(cell))) : this.getHTML(this._replaceBlankCell(cell)));
      }
      /**
       * update responsive columns menu
       */

    }, {
      key: "_updateCols",
      value: function _updateCols() {
        var selected = this.shadowRoot.querySelector("#column").value,
            cols = this.shadowRoot.querySelector("#table").querySelectorAll("th,td");

        if (cols.length > 0) {
          for (var i = 0; i < cols.length; i++) {
            var col = cols[i];

            if (this._isColHidden(col.cellIndex, selected)) {
              col.setAttribute("xs-hidden", true);
            } else {
              col.removeAttribute("xs-hidden");
            }
          }
        }
      }
    }, {
      key: "hidden",
      get: function get() {
        return !this.data || this.data.length < 1 || this.data[0].length < 1;
      }
      /**
       *
       * Gets columns in `<thead>`
       * @readonly
       * @memberof EditableTableDisplay
       */

    }, {
      key: "options",
      get: function get() {
        var head = this.thead || [[]],
            cols = (head[0] || []).map(function (th, i) {
          return [{
            alt: th,
            value: i
          }];
        });
        return cols;
      }
    }]);
    return EditableTableDisplay;
  }((0, _editableTableBehaviors.displayBehaviors)((0, _responsiveUtilityBehaviors.ResponsiveUtilityBehaviors)(_litElement.LitElement)));

  _exports.EditableTableDisplay = EditableTableDisplay;
  window.customElements.define(EditableTableDisplay.tag, EditableTableDisplay);
});