/*
    *
    * 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","@angular/core","@angular/core","@angular/core","@angular/common","@angular/forms","wijmo/wijmo.angular2.directiveBase"],function(e,t,o,n,i,r,l,a,s,d){"use strict";function u(){var e,t;return(e=window.wijmo)&&(t=e.grid)&&t.detail}function c(){var e;return(e=window.wijmo)&&e.input}Object.defineProperty(t,"__esModule",{value:!0}),t.wjFlexGridMeta={selector:"wj-flex-grid",template:"<div><ng-content></ng-content></div>",inputs:["wjModelProperty","isDisabled","newRowAtTop","allowAddNew","allowDelete","allowDragging","allowMerging","allowResizing","allowSorting","quickAutoSize","autoScroll","autoSearch","autoSizeMode","autoGenerateColumns","childItemsPath","groupHeaderFormat","headersVisibility","showSelectedHeaders","showMarquee","itemFormatter","isReadOnly","imeEnabled","mergeManager","selectionMode","showGroups","showSort","showDropDown","showAlternatingRows","showErrors","validateEdits","treeIndent","itemsSource","autoClipboard","frozenRows","frozenColumns","cloneFrozenCells","deferResizing","sortRowIndex","stickyHeaders","preserveSelectedState","preserveOutlineState","keyActionTab","keyActionEnter","rowHeaderPath","virtualizationThreshold"],outputs:["initialized","gotFocusNg: gotFocus","lostFocusNg: lostFocus","beginningEditNg: beginningEdit","cellEditEndedNg: cellEditEnded","cellEditEndingNg: cellEditEnding","prepareCellForEditNg: prepareCellForEdit","formatItemNg: formatItem","resizingColumnNg: resizingColumn","resizedColumnNg: resizedColumn","autoSizingColumnNg: autoSizingColumn","autoSizedColumnNg: autoSizedColumn","draggingColumnNg: draggingColumn","draggingColumnOverNg: draggingColumnOver","draggedColumnNg: draggedColumn","sortingColumnNg: sortingColumn","sortedColumnNg: sortedColumn","resizingRowNg: resizingRow","resizedRowNg: resizedRow","autoSizingRowNg: autoSizingRow","autoSizedRowNg: autoSizedRow","draggingRowNg: draggingRow","draggingRowOverNg: draggingRowOver","draggedRowNg: draggedRow","deletingRowNg: deletingRow","deletedRowNg: deletedRow","loadingRowsNg: loadingRows","loadedRowsNg: loadedRows","rowEditStartingNg: rowEditStarting","rowEditStartedNg: rowEditStarted","rowEditEndingNg: rowEditEnding","rowEditEndedNg: rowEditEnded","rowAddedNg: rowAdded","groupCollapsedChangedNg: groupCollapsedChanged","groupCollapsedChangingNg: groupCollapsedChanging","itemsSourceChangedNg: itemsSourceChanged","selectionChangingNg: selectionChanging","selectionChangedNg: selectionChanged","scrollPositionChangedNg: scrollPositionChanged","updatingViewNg: updatingView","updatedViewNg: updatedView","updatingLayoutNg: updatingLayout","updatedLayoutNg: updatedLayout","pastingNg: pasting","pastedNg: pasted","pastingCellNg: pastingCell","pastedCellNg: pastedCell","copyingNg: copying","copiedNg: copied"],providers:[{provide:s.NG_VALUE_ACCESSOR,useFactory:d.WjValueAccessorFactory,multi:!0,deps:["WjComponent"]}]};var p=function(e){function o(t,o,i,r){var l=e.call(this,d.WjDirectiveBehavior.getHostElement(t,o))||this;l.isInitialized=!1;l._wjBehaviour=d.WjDirectiveBehavior.attach(l,t,o,i);return new C(l,r),l.deferUpdate(function(){if(l.rows.defaultSize<10){var e=l.hostElement,t=getComputedStyle(e),o=getComputedStyle(document.body),i=2*parseInt(t.fontSize&&n.contains(document.body,e)?t.fontSize:o.fontSize);l.rows.defaultSize=i,l.columns.defaultSize=4*i,l.columnHeaders.rows.defaultSize=i,l.rowHeaders.columns.defaultSize=Math.round(1.25*i)}}),l.created(),l}return __extends(o,e),o.prototype.created=function(){},o.prototype.ngOnInit=function(){this._wjBehaviour.ngOnInit()},o.prototype.ngAfterViewInit=function(){this._wjBehaviour.ngAfterViewInit()},o.prototype.ngOnDestroy=function(){this._wjBehaviour.ngOnDestroy()},o.prototype.addEventListener=function(t,o,n,i){var r=this;void 0===i&&(i=!1);var l=d.WjDirectiveBehavior,a=l.ngZone;a&&l.outsideZoneEvents[o]?a.runOutsideAngular(function(){e.prototype.addEventListener.call(r,t,o,n,i)}):e.prototype.addEventListener.call(this,t,o,n,i)},o.meta={outputs:t.wjFlexGridMeta.outputs},o.decorators=[{type:i.Component,args:[{selector:t.wjFlexGridMeta.selector,template:t.wjFlexGridMeta.template,inputs:t.wjFlexGridMeta.inputs,outputs:t.wjFlexGridMeta.outputs,providers:[{provide:"WjComponent",useExisting:r.forwardRef(function(){return o})}].concat(t.wjFlexGridMeta.providers)}]}],o.ctorParameters=function(){return[{type:r.ElementRef,decorators:[{type:l.Inject,args:[r.ElementRef]}]},{type:r.Injector,decorators:[{type:l.Inject,args:[r.Injector]}]},{type:void 0,decorators:[{type:l.Inject,args:["WjComponent"]},{type:l.SkipSelf},{type:r.Optional}]},{type:l.ChangeDetectorRef,decorators:[{type:l.Inject,args:[l.ChangeDetectorRef]}]}]},o}(o.FlexGrid);t.WjFlexGrid=p,t.wjFlexGridColumnMeta={selector:"wj-flex-grid-column",template:"<div><ng-content></ng-content></div>",inputs:["asyncBindings","wjProperty","name","dataMap","dataType","binding","sortMemberPath","format","header","width","maxLength","minWidth","maxWidth","align","allowDragging","allowSorting","allowResizing","allowMerging","aggregate","isReadOnly","cssClass","isContentHtml","isSelected","visible","wordWrap","multiLine","mask","inputType","isRequired","showDropDown","dropDownCssClass","quickAutoSize"],outputs:["initialized","isSelectedChangePC: isSelectedChange"],providers:[]};var g=function(e){function o(t,o,n){var i=e.call(this)||this;i.isInitialized=!1,i.wjProperty="columns";var r=(i._wjBehaviour=d.WjDirectiveBehavior.attach(i,t,o,n)).parentBehavior.directive;return r.autoGenerateColumns&&(r.autoGenerateColumns=!1,r.columns.clear()),i.created(),i}return __extends(o,e),o.prototype.created=function(){},o.prototype.ngOnInit=function(){this._wjBehaviour.ngOnInit()},o.prototype.ngAfterViewInit=function(){this._wjBehaviour.ngAfterViewInit()},o.prototype.ngOnDestroy=function(){this._wjBehaviour.ngOnDestroy()},o.meta={outputs:t.wjFlexGridColumnMeta.outputs,changeEvents:{"grid.selectionChanged":["isSelected"]}},o.decorators=[{type:i.Component,args:[{selector:t.wjFlexGridColumnMeta.selector,template:t.wjFlexGridColumnMeta.template,inputs:t.wjFlexGridColumnMeta.inputs,outputs:t.wjFlexGridColumnMeta.outputs,providers:[{provide:"WjComponent",useExisting:r.forwardRef(function(){return o})}].concat(t.wjFlexGridColumnMeta.providers)}]}],o.ctorParameters=function(){return[{type:r.ElementRef,decorators:[{type:l.Inject,args:[r.ElementRef]}]},{type:r.Injector,decorators:[{type:l.Inject,args:[r.Injector]}]},{type:void 0,decorators:[{type:l.Inject,args:["WjComponent"]},{type:l.SkipSelf},{type:r.Optional}]}]},o}(o.Column);t.WjFlexGridColumn=g;var m=function(){function e(e,t,o,n,i,r,l){this.viewContainerRef=e,this.templateRef=t,this.elRef=o,this.domRenderer=i,this.cdRef=l,this.autoSizeRows=!0,this.forceFullEdit=!0,n instanceof p?this.grid=n:n instanceof g&&(this.column=n,this.grid=d.WjDirectiveBehavior.getBehavior(n).parentBehavior.directive)}return e._getTemplContextProp=function(e){return"$__cellTempl"+f[e]},e.prototype.ngOnInit=function(){this.ownerControl=this.column&&this.column.grid===this.grid?this.column:this.grid,this._attachToControl()},e.prototype.ngOnDestroy=function(){this.cellTypeStr&&(this.viewContainerRef.clear(),this.ownerControl[e._getTemplContextProp(this.cellType)]=null,this.grid.invalidate())},e.prototype._instantiateTemplate=function(e,t){return d.WjDirectiveBehavior.instantiateTemplate(e,this.viewContainerRef,this.templateRef,this.domRenderer,!1,t)},e.prototype._attachToControl=function(){if(this.cellTypeStr){var t=this.cellType=n.asEnum(this.cellTypeStr,f),i=this.ownerControl;i[e._getTemplContextProp(t)]=this,i instanceof o.Column&&(t===f.Cell||t===f.ColumnHeader||t===f.ColumnFooter)&&i._setFlag(o.RowColFlags.HasTemplate,!0),this.grid.invalidate()}},e.decorators=[{type:r.Directive,args:[{selector:"[wjFlexGridCellTemplate]",inputs:["wjFlexGridCellTemplate","cellTypeStr: cellType","cellOverflow","valuePaths","autoSizeRows","forceFullEdit"],exportAs:"wjFlexGridCellTemplate",providers:[{provide:"WjComponent",useExisting:r.forwardRef(function(){return e})}]}]}],e.ctorParameters=function(){return[{type:r.ViewContainerRef,decorators:[{type:l.Inject,args:[r.ViewContainerRef]}]},{type:r.TemplateRef,decorators:[{type:l.Inject,args:[r.TemplateRef]},{type:r.Optional}]},{type:r.ElementRef,decorators:[{type:l.Inject,args:[r.ElementRef]}]},{type:void 0,decorators:[{type:l.Inject,args:["WjComponent"]},{type:l.SkipSelf},{type:r.Optional}]},{type:r.Renderer,decorators:[{type:l.Inject,args:[r.Renderer]}]},{type:r.Injector,decorators:[{type:l.Inject,args:[r.Injector]}]},{type:l.ChangeDetectorRef,decorators:[{type:l.Inject,args:[l.ChangeDetectorRef]}]}]},e}();t.WjFlexGridCellTemplate=m;var f;!function(e){e[e.Cell=0]="Cell",e[e.CellEdit=1]="CellEdit",e[e.ColumnHeader=2]="ColumnHeader",e[e.RowHeader=3]="RowHeader",e[e.RowHeaderEdit=4]="RowHeaderEdit",e[e.TopLeft=5]="TopLeft",e[e.GroupHeader=6]="GroupHeader",e[e.Group=7]="Group",e[e.NewCellTemplate=8]="NewCellTemplate",e[e.ColumnFooter=9]="ColumnFooter",e[e.BottomLeft=10]="BottomLeft"}(f=t.CellTemplateType||(t.CellTemplateType={}));var C=function(e){function t(o,i){var r=e.call(this)||this;if(r._needsCdCheck=!1,r._lastApplyTimeStamp=0,r._noApplyLag=!1,r._startingEditing=!1,r._cellStampCounter=0,r._composing=!1,r.grid=o,r._gridCdRef=i,!t._templateTypes){t._templateTypes=[];for(var l in f)isNaN(l)&&t._templateTypes.push(l)}var a=r;return r._baseCf=o.cellFactory,o.cellFactory=r,r._evtInput=document.createEvent("HTMLEvents"),r._evtInput.initEvent("input",!0,!1),r._evtBlur=document.createEvent("HTMLEvents"),r._evtBlur.initEvent("blur",!1,!1),o.prepareCellForEdit.addHandler(function(e,t){a._noApplyLag=!0}),o.cellEditEnded.addHandler(function(e,t){(t.range.col<0||t.range.col<o.columns.length&&!o.columns[t.range.col][m._getTemplContextProp(f.CellEdit)])&&(a._editChar=null),setTimeout(function(){a._noApplyLag=!1},300)}),o.beginningEdit.addHandler(function(e,t){a._startingEditing=!0}),o.hostElement.addEventListener("keydown",function(e){a._startingEditing=!1},!0),o.hostElement.addEventListener("keypress",function(e){var t=e.charCode>32?String.fromCharCode(e.charCode):null;t&&n.closest(e.target,".wj-flexgrid")===o.hostElement&&(!o.activeEditor||a._startingEditing?(a._editChar=t,setTimeout(function(){o.activeEditor||(a._editChar=null)},0)):a._editChar&&(a._editChar+=t))},!0),o.hostElement.addEventListener("compositionstart",function(e){a._composing=!0},!0),o.hostElement.addEventListener("compositionend",function(e){a._composing=!1},!0),o.updatedView.addHandler(function(){r._needsCdCheck&&(r._needsCdCheck=!1,r._gridCdRef.markForCheck())},r),r}return __extends(t,e),t.prototype.updateCell=function(e,i,r,l,a){var s=this;this._cellStampCounter=(this._cellStampCounter+1)%1e7;var d=l[t._cellStampProp]=this._cellStampCounter;l.style.overflow&&(l.style.overflow="");var p=i,g=r;a&&!a.isSingleCell&&(i=a.row,r=a.col);var C,v=this,w=e.grid,h=w.editRange,y=e.rows[i],E=y.dataItem,_=!1,R=!1,j=!1,S=!1;switch(e.cellType){case o.CellType.Cell:if(h&&h.row===i&&h.col===r)C=f.CellEdit,R=j=!0;else if(y instanceof o.GroupRow){var T=!((S=E instanceof n.CollectionViewGroup)||y.hasChildren);r==e.columns.firstVisibleIndex?C=T?f.Cell:f.GroupHeader:(C=T?f.Cell:f.Group,R=!0)}else y instanceof o._NewRowTemplate?C=f.NewCellTemplate:u()&&u().DetailRow&&y instanceof u().DetailRow||(C=f.Cell);break;case o.CellType.ColumnHeader:C=f.ColumnHeader;break;case o.CellType.RowHeader:C=w.collectionView&&w.collectionView.currentEditItem===E?f.RowHeaderEdit:f.RowHeader,_=!0;break;case o.CellType.TopLeft:C=f.TopLeft,_=!0;break;case o.CellType.ColumnFooter:C=f.ColumnFooter,R=!0;break;case o.CellType.BottomLeft:C=f.BottomLeft,_=!0}var I=!1;if(null!=C){var N=S&&C==f.GroupHeader?w.columns.getColumn(E.groupDescription.propertyName):r>=0&&r<e.columns.length?e.columns[r]:null;if(N){var x=m._getTemplContextProp(C),F=(_?w:N)[x];if(F||(C===f.RowHeaderEdit?(C=f.RowHeader,x=m._getTemplContextProp(C),F=w[x]):C!==f.Group&&C!==f.GroupHeader||S||(C=f.Cell,x=m._getTemplContextProp(C),F=N[x])),F){var H;R&&(H=e.getCellData(i,r,!1)),I=!0;var z=l.getAttribute(o.FlexGrid._WJS_MEASURE),b=z&&"true"===z.toLowerCase();j&&this._baseCf.updateCell(e,p,g,l,a,!0);var D,G=l[x]||{},O=G.column!==N||!G.viewRef||G.templateContextProperty!==x||l.firstChild!=G.rootElement,V=j&&this._composing&&w.imeEnabled;if(O){if(j){var L=l.firstElementChild;L&&(V||l.focus(),L.style.display="none")}else l.textContent="";this._doDisposeCell(l);var P={};D=this._setViewRefContext(P,y,N,E,H,F.valuePaths);var M=F._instantiateTemplate(l,P);G.column=N,G.viewRef=M.viewRef,G.rootElement=M.rootElement,G.templateContextProperty=x,l[x]=G}else D=this._setViewRefContext(G.viewRef.context,y,N,E,H,F.valuePaths);if(F.cellOverflow&&(l.style.overflow=F.cellOverflow),b?F.cdRef.detectChanges():F.autoSizeRows&&!V?setTimeout(function(){if(d===l[t._cellStampProp]){var o=l.scrollHeight,n=e.rows,r=a&&a.rowSpan||1;if(i<n.length&&n[i].renderHeight*r<o-1){if(n.defaultSize=o/r,j){var u=v._isFullEdit();return w.refresh(),void w.startEditing(u)}}else j&&s._initEditInput(G,F,null)}},0):j&&setTimeout(function(){V?s._initImeEditInput(G,F):s._initEditInput(G,F,null)},0),j){v._cellEditorVars=D.localVars;var A=function(e,t){if(w.cellEditEnding.removeHandler(A),!t.stayInEditMode){var o=n.getActiveElement();o&&o.dispatchEvent(v._evtBlur),n.contains(l,n.getActiveElement())&&l.focus()}if(v._triggerEditorEvents(l),!t.cancel&&!t.stayInEditMode)for(var i=D.localVars,r=0,a=Object.getOwnPropertyNames(D.bindings);r<a.length;r++){var s=a[r];D.bindings[s].setValue(i,D.localVars.values[s])}var d=l.querySelectorAll(".wj-dropdown");[].forEach.call(d,function(e){var t=n.Control.getControl(e);t&&c()&&t instanceof c().DropDown&&(t.isDroppedDown=!1)})},B=function(e,t){w.cellEditEnded.removeHandler(B),v._cellEditorVars=null};w.cellEditEnding.addHandler(A),w.cellEditEnded.addHandler(B)}else this._baseCf.updateCell(e,p,g,l,a,!1)}}}I||(this._doDisposeCell(l),this._baseCf.updateCell(e,p,g,l,a))},t.prototype.getEditorValue=function(t){if(this._cellEditorVars){var o=t.editRange;return o&&o.isValid&&this._triggerEditorEvents(t.cells.getCellElement(o.row,o.col)),this._cellEditorVars.value}return e.prototype.getEditorValue.call(this,t)},t.prototype.disposeCell=function(e){this._doDisposeCell(e)},t.prototype._doDisposeCell=function(e){for(var o=t._templateTypes,n=0;n<o.length;n++){var i=m._getTemplContextProp(f[o[n]]),r=e[i];if(r&&r.viewRef){var l=(r.column||this.grid)[i];if(l){var a=l.viewContainerRef.indexOf(r.viewRef);a>-1&&l.viewContainerRef.remove(a)}r.viewRef=null,r.rootElement=null,r.column=null,r.templateContextProperty=null,e[i]=null}}},t.prototype._setViewRefContext=function(e,t,o,i,r,l){this._needsCdCheck=!0,e.row=t,e.col=o,e.item=i;var a={},s=e.cell||{},d={},u={localVars:s,bindings:d};if(s.row=t,s.col=o,s.item=i,s.value=r,s.values=a,l)for(var c=0,p=Object.getOwnPropertyNames(l);c<p.length;c++){var g=p[c],m=new n.Binding(l[g]);d[g]=m,a[g]=m.getValue(s)}return e.cell!==s&&(e.cell=s),u},t.prototype._initEditInput=function(e,o,n){var i=this;this._setFullEdit(o);var r=this._findInitialInput(e);if(r){var l=function(){r.removeEventListener("focus",l),setTimeout(function(){var e=null!=n?n:i._editChar;e&&(r.value=e,i._editChar=null,t._setSelectionRange(r,e.length,e.length),r.dispatchEvent(i._evtInput))},t._FOCUS_INTERVAL)};r.addEventListener("focus",l),r.focus()}},t.prototype._initImeEditInput=function(e,t){var i=this,r=n.getActiveElement();if(r&&r instanceof HTMLInputElement&&n.hasClass(r,"wj-grid-ime")){var l=function(a){r.removeEventListener("compositionend",l),n.setCss(r,o._ImeHandler._cssHidden),i._initEditInput(e,t,r.value)};r.addEventListener("compositionend",l);var a=this._findInitialInput(e);if(a){var s=a.getBoundingClientRect(),d=r.getBoundingClientRect(),u=window.getComputedStyle(r),c=parseFloat(u.left),p=parseFloat(u.top);n.setCss(r,{left:c+s.left-d.left+"px",top:p+s.top-d.top+"px",width:s.width+"px",height:s.height+"px"})}}},t.prototype._findInitialInput=function(e){var t=e&&e.rootElement&&e.rootElement.querySelectorAll("input,textarea");if(t)for(var o=0;o<t.length;o++){var n=t[o],i=window.getComputedStyle(n);if("none"!==i.display&&"visible"===i.visibility)return n}return null},t._setSelectionRange=function(e,t,o){if(void 0===o&&(o=t),n.contains(document.body,e)&&!e.disabled&&"none"!=e.style.display)try{e.setSelectionRange(n.asNumber(t),n.asNumber(o),n.isIE()?null:"backward"),e.focus()}catch(e){}},t.prototype._triggerEditorEvents=function(e){if(e)for(var t=e.querySelectorAll(".wj-control"),o=0;o<t.length;o++){var i=t[o],r=n.Control.getControl(i);if(r){var l=d.WjDirectiveBehavior.getBehavior(r);l&&l.flushPendingEvents()}}},t.prototype._isFullEdit=function(){var e=this.grid;return!e.activeEditor||e._edtHdl._fullEdit},t.prototype._setFullEdit=function(e){var t=this.grid;e.forceFullEdit&&t.activeEditor&&(t._edtHdl._fullEdit=!0)},t._cellStampProp="__wjCellStamp",t._FOCUS_INTERVAL=n.Control._FOCUS_INTERVAL+20,t}(o.CellFactory),v=[p,g,m],w=function(){function e(){}return e.decorators=[{type:i.NgModule,args:[{imports:[d.WjDirectiveBaseModule,a.CommonModule],declarations:v.slice(),exports:v.slice()}]}],e.ctorParameters=function(){return[]},e}();t.WjGridModule=w});