/*
    *
    * Wijmo Library 5.20183.550
    * 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/
    *
    */
"use strict";var __extends=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 o(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(o.prototype=i.prototype,new o)}}();Object.defineProperty(exports,"__esModule",{value:!0});var wjcCore=require("wijmo/wijmo"),wjcGrid=require("wijmo/wijmo.grid"),__glob="undefined"!=typeof window?window:self,wjcSelfRef=require("wijmo/wijmo.grid.detail"),wjcSelf=wjcSelfRef||exports;__glob.wijmo=__glob.wijmo||{},__glob.wijmo.grid=__glob.wijmo.grid||{},__glob.wijmo.grid.detail=wjcSelf,wjcCore._addCultureInfo("FlexGridDetailProvider",{ariaLabels:{toggleDetail:"Toggle Row Detail"}});var KeyAction;!function(e){e[e.None=0]="None",e[e.ToggleDetail=1]="ToggleDetail"}(KeyAction=exports.KeyAction||(exports.KeyAction={}));var DetailVisibilityMode;!function(e){e[e.Code=0]="Code",e[e.Selection=1]="Selection",e[e.ExpandSingle=2]="ExpandSingle",e[e.ExpandMulti=3]="ExpandMulti"}(DetailVisibilityMode=exports.DetailVisibilityMode||(exports.DetailVisibilityMode={}));var FlexGridDetailProvider=function(){function e(e,t){var i=this;this._mode=DetailVisibilityMode.ExpandSingle,this._animated=!1,this._keyActionEnter=KeyAction.None,this._g=e,e.mergeManager=new DetailMergeManager(e),e.rowHeaders.hostElement.addEventListener("click",this._hdrClick.bind(this)),e.rowHeaders.hostElement.addEventListener("mousedown",function(t){var o=e.editableCollectionView;(e.activeEditor||o&&o.currentEditItem)&&(i._hdrClick(t),t.preventDefault())}),e.formatItem.addHandler(this._formatItem,this),e.selectionChanged.addHandler(this._selectionChanged,this),e.resizedRow.addHandler(this._resizedRow,this),e.loadingRows.addHandler(function(){i.hideDetail()}),e.updatedView.addHandler(function(){i._handleFixedCells()}),e.draggingRow.addHandler(function(e,t){t.row<e.rows.length-1&&e.rows[t.row+1]instanceof DetailRow&&(t.cancel=!0,i.hideDetail(t.row))}),e.hostElement.addEventListener("keydown",function(e){if(e.keyCode==wjcCore.Key.Enter&&i._keyActionEnter==KeyAction.ToggleDetail){var t=i._g.selection.row;i._toggleRowDetail(t)&&e.preventDefault()}},!0),t&&wjcCore.copy(this,t)}return Object.defineProperty(e.prototype,"grid",{get:function(){return this._g},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"detailVisibilityMode",{get:function(){return this._mode},set:function(e){(e=wjcCore.asEnum(e,DetailVisibilityMode))!=this._mode&&(this._mode=e,this.hideDetail(),this._g.invalidate())},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"maxHeight",{get:function(){return this._maxHeight},set:function(e){this._maxHeight=wjcCore.asNumber(e,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isAnimated",{get:function(){return this._animated},set:function(e){e!=this._animated&&(this._animated=wjcCore.asBoolean(e))},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"keyActionEnter",{get:function(){return this._keyActionEnter},set:function(e){this._keyActionEnter=wjcCore.asEnum(e,KeyAction)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"createDetailCell",{get:function(){return this._createDetailCellFn},set:function(e){this._createDetailCellFn=wjcCore.asFunction(e,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"disposeDetailCell",{get:function(){return this._disposeDetailCellFn},set:function(e){this._disposeDetailCellFn=wjcCore.asFunction(e,!0)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"rowHasDetail",{get:function(){return this._rowHasDetailFn},set:function(e){this._rowHasDetailFn=wjcCore.asFunction(e,!0)},enumerable:!0,configurable:!0}),e.prototype.getDetailRow=function(e){e=this._toIndex(e);var t=this._g.rows;return t[e]instanceof DetailRow?t[e]:e<t.length-1&&t[e+1]instanceof DetailRow?t[e+1]:null},e.prototype.isDetailVisible=function(e){return null!=this.getDetailRow(e)},e.prototype.isDetailAvailable=function(e){return e=this._toIndex(e),this._hasDetail(e)},e.prototype.hideDetail=function(e){var t=this._g.rows;if(null!=e){!(t[e=this._toIndex(e)]instanceof DetailRow)&&e<t.length-1&&t[e+1]instanceof DetailRow&&e++;var i=t[e];i instanceof DetailRow&&(this.disposeDetailCell&&this.disposeDetailCell(i),wjcCore.Control.disposeAll(i.detail),t.removeAt(e))}else for(var o=0;o<t.length;o++)t[o]instanceof DetailRow&&this.hideDetail(o)},e.prototype.showDetail=function(e,t){void 0===t&&(t=!1);var i=this._g,o=i.rows;if((e=this._toIndex(e))>0&&o[e]instanceof DetailRow&&e--,t){for(var n=i.selection,r=!1,l=0;l<o.length-1;l++)l!=e&&o[l+1]instanceof DetailRow&&(this.hideDetail(l),l<e&&e--,l<n.row&&(n.row--,n.row2--,r=!0));r&&i.select(n,!1)}if(!this.isDetailVisible(e)&&this._hasDetail(e)){var a=new DetailRow(o[e]);if(a.detail=this._createDetailCell(o[e]),a.detail){o.insert(e+1,a),i.autoSizeRow(e+1);var s=this._maxHeight;if(wjcCore.isNumber(s)&&a.renderHeight>s&&(a.height=s),this._animated){var c=a.detail.style;c.transform="translateY(-100%)",c.opacity="0",wjcCore.animate(function(t){t<1?(c.transform="translateY("+(100*-(1-t)).toFixed(0)+"%)",c.opacity=(t*t).toString()):(c.transform="",c.opacity="",wjcCore.Control.invalidateAll(a.detail),i.scrollIntoView(e+1,-1))})}else i.scrollIntoView(e+1,-1,!0)}}},e.prototype._handleFixedCells=function(){var e=this._g,t=e.hostElement;if(e.frozenRows||e.frozenColumns){var i=wjcCore.Control.getControl(t.querySelector(".wj-flexgrid"));if(i instanceof wjcGrid.FlexGrid&&(i.frozenRows||i.frozenColumns)){wjcCore.setCss([e._eTL,e._eBL,e._eCHdr,e._eCFtr,e._eRHdr,e._eMarquee],{zIndex:"6"});for(var o=e.hostElement.querySelectorAll(".wj-frozen"),n=0;n<o.length;n++){var r=o[n];if(wjcCore.closest(r,".wj-flexgrid")==e.hostElement){var l=parseInt(r.style.zIndex);r.style.zIndex=(l%3+3).toString()}}}}},e.prototype._toIndex=function(e){return e instanceof wjcGrid.Row&&(e=e.index),wjcCore.asNumber(e,!1,!0)},e.prototype._hdrClick=function(t){if(!t.defaultPrevented&&0==t.button&&wjcCore.closestClass(t.target,e._WJC_DETAIL))switch(this._mode){case DetailVisibilityMode.ExpandMulti:case DetailVisibilityMode.ExpandSingle:var i=this._g,o=i.hitTest(t.target);o.panel||(o=i.hitTest(t)),o.panel&&this._toggleRowDetail(o.row)&&t.preventDefault()}},e.prototype._toggleRowDetail=function(e){if(e>-1){if(this.isDetailVisible(e))return this.hideDetail(e),!0;if(this._hasDetail(e)){var t=this._g;return t.select(new wjcGrid.CellRange(e,0,e,t.columns.length-1)),this.showDetail(e,this._mode==DetailVisibilityMode.ExpandSingle),!0}}return!1},e.prototype._selectionChanged=function(e,t){var i=this;this._mode==DetailVisibilityMode.Selection&&(this._toSel&&clearTimeout(this._toSel),this._toSel=setTimeout(function(){e.selection.row>-1?i.showDetail(e.selection.row,!0):i.hideDetail()},300))},e.prototype._formatItem=function(t,i){var o=this._g,n=i.panel.rows[i.row];if(i.panel==o.cells&&n instanceof DetailRow&&null!=n.detail&&i.col==o.cells.columns.frozen)if(wjcCore.addClass(i.cell,"wj-detail"),i.cell.textContent="",i.cell.style.textAlign="",i.cell.appendChild(n.detail),null==n.height){wjcCore.Control.refreshAll(i.cell);var r=getComputedStyle(i.cell),l=parseInt(r.paddingTop)+parseInt(r.paddingBottom),a=n.detail.scrollHeight+l;this._maxHeight>0&&a>this._maxHeight&&(a=this._maxHeight),n.height=a,n.detail.style.height||(n.detail.style.height="100%");var s=n.detail.querySelector(".wj-flexgrid");s&&!s.style.height&&(s.style.height="100%")}else setTimeout(function(){wjcCore.Control.refreshAll(n.detail)});if(i.panel==o.rowHeaders&&0==i.col&&this._hasDetail(i.row))switch(i.cell.style.cursor="",this._mode){case DetailVisibilityMode.ExpandMulti:case DetailVisibilityMode.ExpandSingle:var c=i.cell,d=o.rows[i.row+1]instanceof DetailRow,w=d?"minus":"plus",h=e._WJC_DETAIL;c.innerHTML='<div class="wj-btn wj-btn-glyph '+h+'" role="button" tabindex="-1"><span class="wj-glyph-'+w+'"></span></div>';var u=c.children[0],f=wjcCore.culture.FlexGridDetailProvider.ariaLabels.toggleDetail;wjcCore.setAriaLabel(u,f),wjcCore.setAttribute(u,"aria-expanded",d)}},e.prototype._resizedRow=function(e,t){var i=t.panel.rows[t.row];i instanceof DetailRow&&i.detail&&wjcCore.Control.refreshAll(i.detail)},e.prototype._hasDetail=function(e){var t=this._g.rows[e];return wjcCore.isFunction(this._rowHasDetailFn)?this._rowHasDetailFn(t):this._isRegularRow(t)},e.prototype._isRegularRow=function(e){return!(e instanceof wjcGrid.GroupRow||e instanceof wjcGrid._NewRowTemplate)},e.prototype._createDetailCell=function(e,t){return this.createDetailCell?this.createDetailCell(e,t):null},e._WJC_DETAIL="wj-elem-detail",e}();exports.FlexGridDetailProvider=FlexGridDetailProvider;var DetailMergeManager=function(e){function t(t){return e.call(this,t)||this}return __extends(t,e),t.prototype.getMergedRange=function(t,i,o,n){switch(void 0===n&&(n=!0),t.cellType){case wjcGrid.CellType.Cell:if(t.rows[i]instanceof DetailRow){var r=t.columns,l=Math.min(r.length,r.frozen);return o<l?new wjcGrid.CellRange(i,0,i,l-1):new wjcGrid.CellRange(i,l,i,r.length-1)}break;case wjcGrid.CellType.RowHeader:if(t.rows[i]instanceof DetailRow)return new wjcGrid.CellRange(i-1,o,i,o);if(i<t.rows.length-1&&t.rows[i+1]instanceof DetailRow)return new wjcGrid.CellRange(i,o,i+1,o)}return e.prototype.getMergedRange.call(this,t,i,o,n)},t}(wjcGrid.MergeManager);exports.DetailMergeManager=DetailMergeManager;var DetailRow=function(e){function t(t){var i=e.call(this)||this;return i.isReadOnly=!0,i}return __extends(t,e),Object.defineProperty(t.prototype,"detail",{get:function(){return this._detail},set:function(e){this._detail=e},enumerable:!0,configurable:!0}),t}(wjcGrid.Row);exports.DetailRow=DetailRow;