/*
    *
    * Wijmo Library 5.20181.436
    * http://wijmo.com/
    *
    * Copyright(c) GrapeCity, Inc.  All rights reserved.
    *
    * Licensed under the GrapeCity Commercial License.
    * sales@wijmo.com
    * wijmo.com/products/wijmo-5/license/
    *
    */
var __extends=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};return function(t,n){function o(){this.constructor=t}e(t,n),t.prototype=null===n?Object.create(n):(o.prototype=n.prototype,new o)}}();define(["require","exports","wijmo/wijmo.grid","wijmo/wijmo","wijmo/wijmo.grid.multirow"],function(e,t,n,o,r){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var l=r||t;window.wijmo=window.wijmo||{},window.wijmo.grid=window.wijmo.grid||{},window.wijmo.grid.multirow=l;var s=function(e){function t(t,n,o){var r=e.call(this,t)||this;return r._idxData=n,r._idxRecord=o,r}return __extends(t,e),Object.defineProperty(t.prototype,"recordIndex",{get:function(){return this._idxRecord},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"dataIndex",{get:function(){return this._idxData},enumerable:!0,configurable:!0}),t}(n.Row);t._MultiRow=s;var i=function(e){function t(t){var n=e.call(this)||this;return n._row=n._col=0,n._rowspan=n._colspan=1,t&&o.copy(n,t),n}return __extends(t,e),Object.defineProperty(t.prototype,"colspan",{get:function(){return this._colspan},set:function(e){this._colspan=o.asInt(e,!1,!0)},enumerable:!0,configurable:!0}),t}(n.Column);t._Cell=i;var a=function(e){function t(t,n){var r=e.call(this)||this;if(r._colstart=0,r._g=t,n&&o.copy(r,n),!r._cells)throw"Cell group with no cells?";for(var l=0,s=0,i=0,a=0;a<r._cells.length;a++)s+(c=r._cells[a]).colspan>r._colspan&&(l++,s=0),c._row=l,c._col=s,s+=c.colspan,i+=c.colspan;r._rowspan=l+1,r._colspan>i&&(r._colspan=i);for(a=0;a<r._cells.length;a++){var c=r._cells[a];(a==r._cells.length-1||r._cells[a+1]._row>c._row)&&(s=c._col,c._colspan=r._colspan-s)}return r}return __extends(t,e),t.prototype._copy=function(e,t){if("cells"==e){if(this._cells=[],o.isArray(t))for(var n=0;n<t.length;n++){var r=new i(t[n]);!t[n].header&&r.binding&&(t.header=o.toHeaderCase(r.binding)),this._cells.push(r),this._colspan=Math.max(this._colspan,r.colspan)}return!0}return!1},Object.defineProperty(t.prototype,"cells",{get:function(){return this._cells},enumerable:!0,configurable:!0}),t.prototype.closeGroup=function(e){if(e>this._rowspan){for(t=0;t<this._cells.length;t++)(o=this._cells[t])._row==this._rowspan-1&&(o._rowspan=e-o._row);this._rowspan=e}this._cols=new n.ColumnCollection(this._g,this._g.columns.defaultSize),this._rng=new Array(e*this._colspan);for(var t=0;t<this._cells.length;t++)for(var o=this._cells[t],r=0;r<o._rowspan;r++)for(var l=0;l<o._colspan;l++){var s=(o._row+r)*this._colspan+o._col+l;this._cols.setAt(s,o);var i=new n.CellRange(0-r,0-l,0-r+o._rowspan-1,0-l+o._colspan-1);i.isSingleCell||(this._rng[s]=i)}this._rng[-1]=new n.CellRange(0,this._colstart,0,this._colstart+this._colspan-1)},t.prototype.getColumnWidth=function(e){for(var t=0;t<this._cells.length;t++){var n=this._cells[t];if(n._col==e&&1==n.colspan)return n.width}return null},t.prototype.getMergedRange=function(e,t,o){if(t<0)return this._rng[-1];var r=e.rows[t],l=null!=r.recordIndex?r.recordIndex:t%this._rowspan,s=o-this._colstart,i=this._rng[l*this._colspan+s];return e.cellType==n.CellType.ColumnHeader&&t++,i?new n.CellRange(t+i.row,o+i.col,t+i.row2,o+i.col2):null},t.prototype.getBindingColumn=function(e,t,n){if(t<0)return this;var o=e.rows[t],r=o&&null!=o.recordIndex?o.recordIndex:t%this._rowspan,l=n-this._colstart;return this._cols[r*this._colspan+l]},t.prototype.getColumn=function(e){return this._cols.getColumn(e)},t}(i);t._CellGroup=a;var c=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.getMergedRange=function(t,r,l,s){void 0===s&&(s=!0);var i=t.grid;switch(t.cellType){case n.CellType.Cell:case n.CellType.RowHeader:if(t.rows[r]instanceof n.GroupRow)return e.prototype.getMergedRange.call(this,t,r,l,s)}switch(t.cellType){case n.CellType.Cell:case n.CellType.ColumnHeader:var c=i._cellGroupsByColumn[l];o.assert(c instanceof a,"Failed to get the group!");var d=t.cellType==n.CellType.ColumnHeader?c.getMergedRange(t,r-1,l):c.getMergedRange(t,r,l);if(d&&t.columns.frozen){p=t.columns.frozen;d.col<p&&d.col2>=p&&(l<p?d.col2=p-1:d.col=p)}if(d&&t.rows.frozen&&t.cellType==n.CellType.Cell){var p=t.rows.frozen;d.row<p&&d.row2>=p&&(r<p?d.row2=p-1:d.row=p)}return d;case n.CellType.RowHeader:var u=i._rowsPerItem,h=r-t.rows[r].recordIndex,g=Math.min(h+u-1,t.rows.length-1);return new n.CellRange(h,0,g,t.columns.length-1);case n.CellType.TopLeft:return new n.CellRange(0,0,t.rows.length-1,t.columns.length-1)}return null},t}(n.MergeManager);t._MergeManager=c;var d=function(e){function t(t){return t._addHdl._detach(),e.call(this,t)||this}return __extends(t,e),t.prototype.updateNewRowTemplate=function(){for(var e=this._g.editableCollectionView,t=this._g,n=t.rows,o=e&&e.canAddNew&&t.allowAddNew&&!t.isReadOnly,r=!0,l=n.length-t.rowsPerItem;l<n.length;l++)if(!(n[l]instanceof p)){r=!1;break}if(o&&!r)for(l=0;l<t.rowsPerItem;l++){var s=new p(l);n.push(s)}if(!o&&r)for(l=0;l<n.length;l++)n[l]instanceof p&&(n.removeAt(l),l--)},t}(n._AddNewHandler);t._AddNewHandler=d;var p=function(e){function t(t){var n=e.call(this)||this;return n._idxRecord=t,n}return __extends(t,e),Object.defineProperty(t.prototype,"recordIndex",{get:function(){return this._idxRecord},enumerable:!0,configurable:!0}),t}(n._NewRowTemplate),u=function(e){function t(t,r){var l=e.call(this,t)||this;l._rowsPerItem=1,l._cellBindingGroups=[],l._centerVert=!0,l._collapsedHeaders=!1,l.collapsedHeadersChanging=new o.Event,l.collapsedHeadersChanged=new o.Event,o.addClass(l.hostElement,"wj-multirow");var s=l.columnHeaders.hostElement.parentElement,i=o.createElement('<div class="wj-hdr-collapse"><span></span></div>');i.style.display="none",s.appendChild(i),l._btnCollapse=i,l._updateButtonGlyph(),l.addEventListener(i,"mousedown",function(e){switch(l.collapsedHeaders){case null:case!1:l._collapsedHeadersWasNull=null==l.collapsedHeaders,l.collapsedHeaders=!0;break;case!0:l.collapsedHeaders=!!l._collapsedHeadersWasNull&&null}e.preventDefault(),l.focus()},!0),l.autoGenerateColumns=!1,l.mergeManager=new c(l);var a=l.hostElement;return l.removeEventListener(a,"dragover"),l.removeEventListener(a,"dragleave"),l.removeEventListener(a,"dragdrop"),l._addHdl=new d(l),l.formatItem.addHandler(l._formatItem,l),l.addEventListener(l.rowHeaders.hostElement,"click",function(e){if(!e.defaultPrevented&&l.selectionMode!=n.SelectionMode.None){var t=l.hitTest(e);if(t.panel==l.rowHeaders&&t.row>-1){var o=l.selection,r=l.rows[o.topRow],s=l.selectionMode!=n.SelectionMode.Row?l.rows[o.bottomRow]:r;if(r&&null!=r.recordIndex){var i=r.index-r.recordIndex,a=s.index-s.recordIndex+l.rowsPerItem-1,c=l.columns.length-1,d=o.row!=o.topRow?new n.CellRange(a,0,i,c):new n.CellRange(i,0,a,c);l.select(d),e.preventDefault()}}}},!0),l.initialize(r),l}return __extends(t,e),t.prototype._getProductInfo=function(){return"H87K,MultiRow"},Object.defineProperty(t.prototype,"layoutDefinition",{get:function(){return this._layoutDef},set:function(e){this._layoutDef=o.asArray(e),this._rowsPerItem=1,this._cellBindingGroups=this._parseCellGroups(this._layoutDef);for(var t=0;t<this._cellBindingGroups.length;t++){var n=this._cellBindingGroups[t];this._rowsPerItem=Math.max(this._rowsPerItem,n._rowspan)}this._bindGrid(!0)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"rowsPerItem",{get:function(){return this._rowsPerItem},enumerable:!0,configurable:!0}),t.prototype.getBindingColumn=function(e,t,n){return this._getBindingColumn(e,t,e.columns[n])},t.prototype.getColumn=function(e){for(var t=this._cellBindingGroups,n=0;n<t.length;n++){var o=t[n].getColumn(e);if(t[n].getBindingColumn,o)return o}return null},Object.defineProperty(t.prototype,"centerHeadersVertically",{get:function(){return this._centerVert},set:function(e){e!=this._centerVert&&(this._centerVert=o.asBoolean(e),this.invalidate())},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"collapsedHeaders",{get:function(){return this._collapsedHeaders},set:function(e){if(e!=this._collapsedHeaders){var t=new o.CancelEventArgs;this.onCollapsedHeadersChanging(t)&&(this._collapsedHeaders=o.asBoolean(e,!0),this._updateCollapsedHeaders(),this._updateButtonGlyph(),this.onCollapsedHeadersChanged(t))}},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"showHeaderCollapseButton",{get:function(){return""==this._btnCollapse.style.display},set:function(e){e!=this.showHeaderCollapseButton&&(this._btnCollapse.style.display=o.asBoolean(e)?"":"none")},enumerable:!0,configurable:!0}),t.prototype.onCollapsedHeadersChanging=function(e){return this.collapsedHeadersChanging.raise(this,e),!e.cancel},t.prototype.onCollapsedHeadersChanged=function(e){this.collapsedHeadersChanged.raise(this,e)},t.prototype._addBoundRow=function(e,t){for(var n=e[t],o=0;o<this._rowsPerItem;o++)this.rows.push(new s(n,t,o))},t.prototype._addNode=function(e,t,n){this._addBoundRow(e,t)},t.prototype._bindColumns=function(){for(var e=this.columnHeaders.rows,t=this._rowsPerItem+1;e.length>t;)e.removeAt(e.length-1);for(;e.length<t;)e.push(new n.Row);this._updateCollapsedHeaders(),this.columns.clear(),this._cellGroupsByColumn={};var r=this.collectionView;if(r&&r.sourceCollection&&r.sourceCollection.length&&r.sourceCollection[0],this._cellBindingGroups)for(var l=0;l<this._cellBindingGroups.length;l++)for(var s=this._cellBindingGroups[l],i=0;i<s._colspan;i++){this._cellGroupsByColumn[this.columns.length]=s;for(var a=new n.Column,c=0;c<s.cells.length;c++){var d=s.cells[c];if(d._col==i){d.width&&(a.width=d.width),d.binding&&(a.binding=d.binding),d.format&&(a.format=d.format),d.aggregate!=o.Aggregate.None&&(a.aggregate=d.aggregate);break}}this.columns.push(a)}},t.prototype._updateCollapsedHeaders=function(){var e=this.columnHeaders.rows,t=this.collapsedHeaders;e[0].visible=0!=t;for(var n=1;n<e.length;n++)e[n].visible=1!=t},t.prototype._updateColumnTypes=function(){e.prototype._updateColumnTypes.call(this);var t=this.collectionView;if(o.hasItems(t))for(var n=t.items[0],r=0;r<this._cellBindingGroups.length;r++)for(var l=this._cellBindingGroups[r],s=0;s<l._cols.length;s++){var i=l._cols[s];null==i.dataType&&i._binding&&(i.dataType=o.getType(i._binding.getValue(n)))}},t.prototype._getBindingColumn=function(e,t,n){if(e==this.cells||e==this.columnHeaders){var o=this._cellGroupsByColumn[n.index];e==this.columnHeaders&&t--,n=o.getBindingColumn(e,t,n.index)}return n},t.prototype._cvCollectionChanged=function(e,t){if(this.autoGenerateColumns&&0==this.columns.length)this._bindGrid(!0);else switch(t.action){case o.NotifyCollectionChangedAction.Change:this.invalidate();break;case o.NotifyCollectionChangedAction.Add:if(t.index==this.collectionView.items.length-1){for(var r=this.rows.length;r>0&&this.rows[r-1]instanceof n._NewRowTemplate;)r--;for(var l=0;l<this._rowsPerItem;l++)this.rows.insert(r+l,new s(t.item,t.index,l));return}o.assert(!1,"added item should be the last one.");break;default:this._bindGrid(!1)}},t.prototype._parseCellGroups=function(e){var t=[],n=1;if(e){for(var o=0,r=0;o<e.length;o++){var l=new a(this,e[o]);l._colstart=r,r+=l._colspan,n=Math.max(n,l._rowspan),t.push(l)}for(o=0;o<t.length;o++)t[o].closeGroup(n)}return t},t.prototype._formatItem=function(e,t){var r=this._rowsPerItem,l=t.panel.cellType,i=t.panel.rows[t.range.row],c=t.panel.rows[t.range.row2];if(l==n.CellType.ColumnHeader&&o.toggleClass(t.cell,"wj-group-header",0==t.range.row),l==n.CellType.Cell||l==n.CellType.ColumnHeader){var d=this._cellGroupsByColumn[t.col];o.assert(d instanceof a,"Failed to get the group!"),o.toggleClass(t.cell,"wj-group-start",d._colstart==t.range.col),o.toggleClass(t.cell,"wj-group-end",d._colstart+d._colspan-1==t.range.col2)}if(r>1&&(l!=n.CellType.Cell&&l!=n.CellType.RowHeader||(o.toggleClass(t.cell,"wj-record-start",i instanceof s&&0==i.recordIndex),o.toggleClass(t.cell,"wj-record-end",c instanceof s&&c.recordIndex==r-1))),this.showAlternatingRows&&o.toggleClass(t.cell,"wj-alt",i instanceof s&&i.dataIndex%2!=0),this._centerVert)if(t.cell.hasChildNodes&&t.range.rowSpan>1){var p=o.createElement('<div style="display:table-cell;vertical-align:middle"></div>'),u=document.createRange();u.selectNodeContents(t.cell),u.surroundContents(p),o.setCss(t.cell,{display:"table",tableLayout:"fixed",paddingTop:0,paddingBottom:0})}else{var h=t.cell.querySelector("input")?"0px":"";o.setCss(t.cell,{display:"",tableLayout:"",paddingTop:h,paddingBottom:h})}},t.prototype._updateButtonGlyph=function(){var e=this._btnCollapse.querySelector("span");e instanceof HTMLElement&&(e.className=this.collapsedHeaders?"wj-glyph-left":"wj-glyph-down-left")},t}(n.FlexGrid);t.MultiRow=u});