/*
    *
    * Wijmo Library 5.20182.500
    * 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 o in t)t.hasOwnProperty(o)&&(e[o]=t[o])};return function(t,o){function n(){this.constructor=t}e(t,o),t.prototype=null===o?Object.create(o):(n.prototype=o.prototype,new n)}}();define(["require","exports","wijmo/wijmo.grid","wijmo/wijmo","wijmo/wijmo.grid.multirow"],function(e,t,o,n,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,o,n){var r=e.call(this,t)||this;return r._idxData=o,r._idxRecord=n,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}(o.Row);t._MultiRow=s;var i=function(e){function t(t){var o=e.call(this)||this;return o._row=o._col=0,o._rowspan=o._colspan=1,t&&n.copy(o,t),o}return __extends(t,e),Object.defineProperty(t.prototype,"colspan",{get:function(){return this._colspan},set:function(e){this._colspan=n.asInt(e,!1,!0)},enumerable:!0,configurable:!0}),t}(o.Column);t._Cell=i;var a=function(e){function t(t,o){var r=e.call(this)||this;if(r._colstart=0,r._g=t,o&&n.copy(r,o),!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){var o=this;return"cells"==e&&(this._cells=[],n.isArray(t)&&t.forEach(function(e){var t=new i(e);!e.header&&t.binding&&(t.header=n.toHeaderCase(t.binding)),o._cells.push(t),o._colspan=Math.max(o._colspan,t.colspan)}),!0)},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++)(n=this._cells[t])._row==this._rowspan-1&&(n._rowspan=e-n._row);this._rowspan=e}this._cols=new o.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 n=this._cells[t],r=0;r<n._rowspan;r++)for(var l=0;l<n._colspan;l++){var s=(n._row+r)*this._colspan+n._col+l;this._cols.setAt(s,n);var i=new o.CellRange(0-r,0-l,0-r+n._rowspan-1,0-l+n._colspan-1);i.isSingleCell||(this._rng[s]=i)}this._rng[-1]=new o.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 o=this._cells[t];if(o._col==e&&1==o.colspan)return o.width}return null},t.prototype.getMergedRange=function(e,t,n){if(t<0)return this._rng[-1];var r=e.rows[t],l=null!=r.recordIndex?r.recordIndex:t%this._rowspan,s=n-this._colstart,i=this._rng[l*this._colspan+s];return e.cellType==o.CellType.ColumnHeader&&t++,i?new o.CellRange(t+i.row,n+i.col,t+i.row2,n+i.col2):null},t.prototype.getBindingColumn=function(e,t,o){if(t<0)return this;var n=e.rows[t],r=n&&null!=n.recordIndex?n.recordIndex:t%this._rowspan,l=o-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 o.CellType.Cell:case o.CellType.RowHeader:if(t.rows[r]instanceof o.GroupRow)return e.prototype.getMergedRange.call(this,t,r,l,s)}switch(t.cellType){case o.CellType.Cell:case o.CellType.ColumnHeader:var c=i._cellGroupsByColumn[l];n.assert(c instanceof a,"Failed to get the group!");var d=t.cellType==o.CellType.ColumnHeader?c.getMergedRange(t,r-1,l):c.getMergedRange(t,r,l);if(d&&t.columns.frozen){u=t.columns.frozen;d.col<u&&d.col2>=u&&(l<u?d.col2=u-1:d.col=u)}if(d&&t.rows.frozen&&t.cellType==o.CellType.Cell){var u=t.rows.frozen;d.row<u&&d.row2>=u&&(r<u?d.row2=u-1:d.row=u)}return d;case o.CellType.RowHeader:var p=i._rowsPerItem,h=r-t.rows[r].recordIndex,g=Math.min(h+p-1,t.rows.length-1);return new o.CellRange(h,0,g,t.columns.length-1);case o.CellType.TopLeft:return new o.CellRange(0,0,t.rows.length-1,t.columns.length-1)}return null},t}(o.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,o=t.rows,n=e&&e.canAddNew&&t.allowAddNew&&!t.isReadOnly,r=!0,l=o.length-t.rowsPerItem;l<o.length;l++)if(!(o[l]instanceof u)){r=!1;break}if(n&&!r)for(l=0;l<t.rowsPerItem;l++){var s=new u(l);o.push(s)}if(!n&&r)for(l=0;l<o.length;l++)o[l]instanceof u&&(o.removeAt(l),l--)},t}(o._AddNewHandler);t._AddNewHandler=d;var u=function(e){function t(t){var o=e.call(this)||this;return o._idxRecord=t,o}return __extends(t,e),Object.defineProperty(t.prototype,"recordIndex",{get:function(){return this._idxRecord},enumerable:!0,configurable:!0}),t}(o._NewRowTemplate),p=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 n.Event,l.collapsedHeadersChanged=new n.Event,n.addClass(l.hostElement,"wj-multirow");var s=l.columnHeaders.hostElement.parentElement,i=n.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!=o.SelectionMode.None){var t=l.hitTest(e);if(t.panel==l.rowHeaders&&t.row>-1){var n=l.selection,r=l.rows[n.topRow],s=l.selectionMode!=o.SelectionMode.Row?l.rows[n.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=n.row!=n.topRow?new o.CellRange(a,0,i,c):new o.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=n.asArray(e),this._rowsPerItem=1,this._cellBindingGroups=this._parseCellGroups(this._layoutDef);for(var t=0;t<this._cellBindingGroups.length;t++){var o=this._cellBindingGroups[t];this._rowsPerItem=Math.max(this._rowsPerItem,o._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,o){return this._getBindingColumn(e,t,e.columns[o])},t.prototype.getColumn=function(e){for(var t=this._cellBindingGroups,o=0;o<t.length;o++){var n=t[o].getColumn(e);if(t[o].getBindingColumn,n)return n}return null},Object.defineProperty(t.prototype,"centerHeadersVertically",{get:function(){return this._centerVert},set:function(e){e!=this._centerVert&&(this._centerVert=n.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 n.CancelEventArgs;this.onCollapsedHeadersChanging(t)&&(this._collapsedHeaders=n.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=n.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 o=e[t],n=0;n<this._rowsPerItem;n++)this.rows.push(new s(o,t,n))},t.prototype._addNode=function(e,t,o){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 o.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 o.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!=n.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 o=1;o<e.length;o++)e[o].visible=1!=t},t.prototype._updateColumnTypes=function(){e.prototype._updateColumnTypes.call(this);var t=this.collectionView;if(n.hasItems(t))for(var o=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=n.getType(i._binding.getValue(o)))}},t.prototype._getBindingColumn=function(e,t,o){if(e==this.cells||e==this.columnHeaders){var n=this._cellGroupsByColumn[o.index];e==this.columnHeaders&&t--,o=n.getBindingColumn(e,t,o.index)}return o},t.prototype._cvCollectionChanged=function(e,t){if(this.autoGenerateColumns&&0==this.columns.length)this._bindGrid(!0);else switch(t.action){case n.NotifyCollectionChangedAction.Change:this.invalidate();break;case n.NotifyCollectionChangedAction.Add:if(t.index==this.collectionView.items.length-1){for(var r=this.rows.length;r>0&&this.rows[r-1]instanceof o._NewRowTemplate;)r--;for(var l=0;l<this._rowsPerItem;l++)this.rows.insert(r+l,new s(t.item,t.index,l));return}n.assert(!1,"added item should be the last one.");break;default:this._bindGrid(!1)}},t.prototype._parseCellGroups=function(e){var t=[],o=1;if(e){for(var n=0,r=0;n<e.length;n++){var l=new a(this,e[n]);l._colstart=r,r+=l._colspan,o=Math.max(o,l._rowspan),t.push(l)}for(n=0;n<t.length;n++)t[n].closeGroup(o)}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==o.CellType.ColumnHeader&&n.toggleClass(t.cell,"wj-group-header",0==t.range.row),l==o.CellType.Cell||l==o.CellType.ColumnHeader){var d=this._cellGroupsByColumn[t.col];n.assert(d instanceof a,"Failed to get the group!"),n.toggleClass(t.cell,"wj-group-start",d._colstart==t.range.col),n.toggleClass(t.cell,"wj-group-end",d._colstart+d._colspan-1==t.range.col2)}if(r>1&&(l!=o.CellType.Cell&&l!=o.CellType.RowHeader||(n.toggleClass(t.cell,"wj-record-start",i instanceof s&&0==i.recordIndex),n.toggleClass(t.cell,"wj-record-end",c instanceof s&&c.recordIndex==r-1))),this.showAlternatingRows&&n.toggleClass(t.cell,"wj-alt",i instanceof s&&i.dataIndex%2!=0),this._centerVert)if(t.cell.hasChildNodes&&t.range.rowSpan>1){var u=n.createElement('<div style="display:table-cell;vertical-align:middle"></div>'),p=document.createRange();p.selectNodeContents(t.cell),p.surroundContents(u),n.setCss(t.cell,{display:"table",tableLayout:"fixed",paddingTop:0,paddingBottom:0})}else{var h=t.cell.querySelector("input")?"0px":"";n.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.prototype._getError=function(t,o,r){if(n.isFunction(this.itemValidator)&&t==this.rowHeaders)for(var l=0;l<this._rowsPerItem;l++)for(r=0;r<this.columns.length;r++){var s=this.itemValidator(o+l,r);if(s)return s}return e.prototype._getError.call(this,t,o,r)},t}(o.FlexGrid);t.MultiRow=p});