Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _xeUtils=_interopRequireDefault(require("xe-utils")),_util=require("../../src/util");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function calcMaxHeight(e){var t=e.customStore,e=e.$refs.refElem;let s=0;e&&(s=e.clientHeight-28),t.maxHeight=Math.max(88,s)}function emitCustomEvent(e,t,s){(e.$xeGrid||e).dispatchEvent("custom",{type:t},s)}var _default=exports.default={methods:{_getCustomVisible(){var e=this.customStore;return e.visible},_openCustom(){let e=this;var{initStore:t,customStore:s}=e;return s.visible=!0,t.custom=!0,e.handleUpdateCustomColumn(),e.checkCustomStatus(),calcMaxHeight(e),e.$nextTick().then(()=>calcMaxHeight(e))},_closeCustom(){var e=this,t=e.customStore,s=e.computeCustomOpts;return t.visible&&(t.visible=!1,s.immediate||e.handleCustom()),e.$nextTick()},_toggleCustom(){var e=this,t=e.customStore;return t.visible?e.closeCustom():e.openCustom()},_saveCustom(){var e=this,t=e,s=e;let{customColumnList:i,aggHandleFields:l,rowGroupList:o}=t,{allowVisible:r,allowSort:u,allowFixed:a,allowResizable:n,allowGroup:d,allowValues:m}=e.computeCustomOpts;return _xeUtils.default.eachTree(i,(e,t,s,i,l)=>{l?e.fixed=l.fixed:(u&&(e.renderSortNumber=t+1),a&&(e.fixed=e.renderFixed)),n&&e.renderVisible&&(!e.children||e.children.length)&&e.renderResizeWidth!==e.renderWidth&&(e.resizeWidth=e.renderResizeWidth,e.renderWidth=e.renderResizeWidth),r&&(e.visible=e.renderVisible),d&&m&&(e.aggFunc=e.renderAggFn)}),t.isCustomStatus=!0,d&&m&&e.handlePivotTableAggregateData&&(o.length!==l.length||o.some((e,t)=>e.field!==l[t])?l.length?e.setRowGroups(l):e.clearRowGroups():m&&e.handleUpdateAggData()),u&&(s.collectColumn=i),e.saveCustomStore("confirm")},_cancelCustom(){var e=this,{customColumnList:t,customStore:s}=e;let{oldSortMaps:l,oldFixedMaps:o,oldVisibleMaps:r}=s,{allowVisible:u,allowSort:a,allowFixed:n,allowResizable:d}=e.computeCustomOpts;return _xeUtils.default.eachTree(t,e=>{var t=e.getKey(),s=!!r[t],i=o[t]||"";u&&(e.renderVisible=s,e.visible=s),n&&(e.renderFixed=i,e.fixed=i),a&&(e.renderSortNumber=l[t]||0),d&&(e.renderResizeWidth=e.renderWidth)},{children:"children"}),e.$nextTick()},_resetCustom(e){let t=this;var s=t,i=t;let l=s.rowGroupList;var o=i.collectColumn;let r=t.computeCustomOpts.checkMethod,u=Object.assign({visible:!0,resizable:!0===e,fixed:!0===e,sort:!0===e,aggFunc:!0===e},e),a=[];return _xeUtils.default.eachTree(o,e=>{u.resizable&&(e.resizeWidth=0),u.fixed&&(e.fixed=e.defaultFixed),u.sort&&(e.renderSortNumber=e.sortNumber,e.parentId=e.defaultParentId),r&&!r({$table:t,column:e})||(e.visible=e.defaultVisible),u.aggFunc&&(e.aggFunc=e.defaultAggFunc,e.renderAggFn=e.defaultAggFunc),e.renderResizeWidth=e.renderWidth,a.push(e)}),u.sort&&(e=_xeUtils.default.toArrayTree(_xeUtils.default.orderBy(a,"renderSortNumber"),{key:"id",parentKey:"parentId",children:"children"}),i.collectColumn=e,i.tableFullColumn=(0,_util.getColumnList)(e)),s.isCustomStatus=!1,t.handleCustom().then(()=>{var e;u.aggFunc&&t.handlePivotTableAggregateData&&(((e=t.computeRowGroupFields)||l).length?e&&e.length?t.setRowGroups(e):t.clearRowGroups():t.handleUpdateAggData()),t.saveCustomStore("reset")})},_toggleCustomAllCheckbox(){var e=this.customStore,e=!e.isAll;return this.setCustomAllCheckbox(e)},_setCustomAllCheckbox(e){let t=this;var s=t,i=s.customStore,l=s.customColumnList,o=t.computeCustomOpts;let{checkMethod:r,visibleMethod:u}=o,a=!!e;o.immediate?(_xeUtils.default.eachTree(l,e=>{u&&!u({$table:t,column:e})||r&&!r({$table:t,column:e})||(e.visible=a,e.renderVisible=a,e.halfVisible=!1)}),i.isAll=a,s.isCustomStatus=!0,t.handleCustom(),t.saveCustomStore("update:visible")):(_xeUtils.default.eachTree(l,e=>{u&&!u({$table:t,column:e})||r&&!r({$table:t,column:e})||(e.renderVisible=a,e.halfVisible=!1)}),i.isAll=a),t.checkCustomStatus()},checkCustomStatus(){let t=this;var e=t.customStore,s=t.collectColumn;let i=t.computeCustomOpts.checkMethod;e.isAll=s.every(e=>!!i&&!i({$table:t,column:e})||e.renderVisible),e.isIndeterminate=!e.isAll&&s.some(e=>(!i||i({$table:t,column:e}))&&(e.renderVisible||e.halfVisible))},emitCustomEvent(e,t){(this.$xeGrid||this).dispatchEvent("custom",{type:e},t)},triggerCustomEvent(e){var t=this.customStore;t.visible?(this.closeCustom(),emitCustomEvent(this,"close",e)):(t.btnEl=e.target,this.openCustom(),emitCustomEvent(this,"open",e))},customOpenEvent(e){var t=this.customStore;t.visible&&(t.activeBtn=!0,t.btnEl=e.target,this.openCustom(),emitCustomEvent(this,"open",e))},customCloseEvent(e){var t=this.customStore;t.visible&&(t.activeBtn=!1,this.closeCustom(),emitCustomEvent(this,"close",e))},handleUpdateCustomColumn(){var e=this,t=e.customStore,o=this.collectColumn;if(t.visible){let s={},i={},l={};_xeUtils.default.eachTree(o,e=>{var t=e.getKey();e.renderFixed=e.fixed,e.renderVisible=e.visible,e.renderResizeWidth=e.renderWidth,s[t]=e.renderSortNumber,i[t]=e.fixed,l[t]=e.visible}),t.oldSortMaps=s,t.oldFixedMaps=i,t.oldVisibleMaps=l,e.customColumnList=o.slice(0)}}}};