/*
    *
    * Wijmo Library 5.20173.409
    * 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/
    *
    */
System.register(["wijmo/wijmo","wijmo/wijmo.grid","wijmo/wijmo.grid.grouppanel"],function(e,t){"use strict";var i,r,n,o,s=this&&this.__extends||function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])};return function(t,i){function r(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(r.prototype=i.prototype,new r)}}();t&&t.id;return{setters:[function(e){i=e},function(e){r=e},function(e){n=e}],execute:function(){window.wijmo=window.wijmo||{},window.wijmo.grid=window.wijmo.grid||{},window.wijmo.grid.grouppanel=n,o=function(e){function t(t,n){var o=e.call(this,t)||this;o._hideGroupedCols=!0,o._maxGroups=6,o._hiddenCols=[];i.assert(null!=r,"Missing dependency: GroupPanel requires wijmo.grid.");var s=o.getTemplate();o.applyTemplate("wj-grouppanel wj-control",s,{_divMarkers:"div-markers",_divPH:"div-ph"});var d=o.hostElement;return o.addEventListener(d,"dragstart",o._dragStart.bind(o)),o.addEventListener(d,"dragover",o._dragOver.bind(o)),o.addEventListener(d,"drop",o._drop.bind(o)),o.addEventListener(d,"dragend",o._dragEnd.bind(o)),o.addEventListener(d,"click",o._click.bind(o)),o.initialize(n),o}return s(t,e),Object.defineProperty(t.prototype,"hideGroupedColumns",{get:function(){return this._hideGroupedCols},set:function(e){e!=this._hideGroupedCols&&(this._hideGroupedCols=i.asBoolean(e))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"maxGroups",{get:function(){return this._maxGroups},set:function(e){e!=this._maxGroups&&(this._maxGroups=i.asNumber(e))},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"placeholder",{get:function(){return this._divPH.textContent},set:function(e){this._divPH.textContent=e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"grid",{get:function(){return this._g},set:function(e){(e=i.asType(e,r.FlexGrid,!0))!=this._g&&(this._g&&(this._g.draggingColumn.removeHandler(this._draggingColumn),this._g.sortedColumn.removeHandler(this.invalidate),this._g.itemsSourceChanging.removeHandler(this._itemsSourceChanging),this._g.itemsSourceChanged.removeHandler(this._itemsSourceChanged),this._g.columns.collectionChanged.removeHandler(this._itemsSourceChanged)),this._g=e,this._hiddenCols=[],this._g&&(this._g.draggingColumn.addHandler(this._draggingColumn,this),this._g.sortedColumn.addHandler(this.invalidate,this),this._g.itemsSourceChanging.addHandler(this._itemsSourceChanging,this),this._g.itemsSourceChanged.addHandler(this._itemsSourceChanged,this),this._g.columns.collectionChanged.addHandler(this._itemsSourceChanged,this)),this._itemsSourceChanged(this._g,null))},enumerable:!0,configurable:!0}),t.prototype.refresh=function(){if(e.prototype.refresh.call(this),this._divMarkers.innerHTML="",this._dragMarker=this._dragCol=null,this._gds){for(var t=0;t<this._gds.length;t++){for(var r=this._gds[t],n=this._g.columnHeaders,o=-1,s=-1,d=n.rows.length-1;d>=0&&s<0;d--)for(var a=0;a<n.columns.length&&s<0;a++){var l=this._g._getBindingColumn(n,d,n.columns[a]);if(l&&l.binding==r.propertyName){s=a,o=d;break}}if(s>-1&&o>-1){var h=document.createElement("div");this._g.cellFactory.updateCell(this._g.columnHeaders,o,s,h),h.setAttribute("class","wj-cell wj-header wj-groupmarker"),i.setCss(h,{position:"static",display:"inline-block",verticalAlign:"top",left:"",top:"",right:"",height:"auto",width:"auto"});var g=h.querySelector(".wj-elem-filter");g&&i.removeChild(g);i.createElement('<span wj-remove="" style="font-weight:normal;cursor:pointer;pointer;padding:12px;padding-right:3px">&times;</span>',h);this._divMarkers.appendChild(h)}}this._divMarkers.children.length>0?(this._divPH.style.display="none",this._divMarkers.style.display=""):(this._divPH.style.display="",this._divMarkers.style.display="none")}},t.prototype._addGroup=function(e,t){for(var r=this._getIndex(t),n=this._gds,o=0;o<n.length;o++)if(n[o].propertyName==e.binding){n.removeAt(o),o<r&&r--;break}for(o=this.maxGroups-1;o<n.length;o++)this._removeGroup(o,n),o<r&&r--;n.deferUpdate(function(){var t=new i.PropertyGroupDescription(e.binding);n.insert(r,t)}),e&&this.hideGroupedColumns&&(e.visible=!1,this._hiddenCols.push(e)),this.invalidate()},t.prototype._moveGroup=function(e,t){var i=this._gds,r=this._getElementIndex(this._dragMarker),n=this._getIndex(t);n>r&&n--,n>=this._gds.length&&(n=this._gds.length),r!=n&&i.deferUpdate(function(){var e=i[r];i.removeAt(r),i.insert(n,e)})},t.prototype._removeGroup=function(e,t){void 0===t&&(t=this._gds);var i=t[e].propertyName,r=this._g.columns.getColumn(i),n=this._hiddenCols.indexOf(r);t.removeAt(e),r&&(r.visible=!0,n>-1&&this._hiddenCols.splice(n,1))},t.prototype._getIndex=function(e){for(var t=this._divMarkers.children,i=0;i<t.length;i++){var r=t[i].getBoundingClientRect();if(e.clientX<r.left+r.width/2)return i}return t.length},t.prototype._getElementIndex=function(e){if(e&&e.parentElement)for(var t=e.parentElement.children,i=0;i<t.length;i++)if(t[i]==e)return i;return-1},t.prototype._draggingColumn=function(e,t){var i=this._g,r=i._getBindingColumn(t.panel,t.row,i.columns[t.col]);this._dragCol=r.binding?r:null},t.prototype._itemsSourceChanging=function(e,t){this._hiddenCols.forEach(function(e){e.visible=!0}),this._hiddenCols=[]},t.prototype._itemsSourceChanged=function(e,t){this._gds&&this._gds.collectionChanged.removeHandler(this._groupsChanged),this._gds=null,this._g.collectionView&&(this._gds=this._g.collectionView.groupDescriptions,this._gds.collectionChanged.addHandler(this._groupsChanged,this)),this.invalidate()},t.prototype._groupsChanged=function(e,t){this.invalidate()},t.prototype._dragStart=function(e){i._startDrag(e.dataTransfer,"move"),this._dragMarker=e.target,this._dragCol=null},t.prototype._dragOver=function(e){(this._dragCol||this._dragMarker)&&(e.dataTransfer.dropEffect="move",e.preventDefault(),e.stopPropagation())},t.prototype._drop=function(e){this._dragMarker?this._moveGroup(this._dragMarker,e):this._dragCol&&this._addGroup(this._dragCol,e)},t.prototype._dragEnd=function(e){this._dragMarker=this._dragCol=null},t.prototype._click=function(e){for(var t=document.elementFromPoint(e.clientX,e.clientY),r=null!=t.getAttribute("wj-remove"),n=t;n.parentElement&&!i.hasClass(n,"wj-cell");)n=n.parentElement;if(i.hasClass(n,"wj-cell")){var o=this._getElementIndex(n),s=this._g.collectionView.sortDescriptions;if(r)this._removeGroup(o);else if(e.ctrlKey)s.clear(),this.invalidate();else{for(var d=this._gds[o],a=!0,l=0;l<s.length;l++)if(s[l].property==d.propertyName){a=!s[l].ascending;break}var h=new i.SortDescription(d.propertyName,a);s.splice(0,s.length,h),this.invalidate()}}},t.controlTemplate='<div style="cursor:default;overflow:hidden;height:100%;width:100%;min-height:1em"><div wj-part="div-ph"></div><div wj-part="div-markers"></div></div>',t}(i.Control),e("GroupPanel",o)}}});