"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _xeUtils=_interopRequireDefault(require("xe-utils/methods/xe-utils")),_tools=require("../../tools");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _defineProperty(e,l,t){return l in e?Object.defineProperty(e,l,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[l]=t,e}var getAllColumns=function l(e){var t=[];return e.forEach(function(e){e.visible&&(e.children&&e.children.length&&e.children.some(function(e){return e.visible})?(t.push(e),t.push.apply(t,l(e.children))):t.push(e))}),t},convertToRows=function(e){var n=1;e.forEach(function(e){e.level=1,function l(t,e){if(e&&(t.level=e.level+1,n<t.level&&(n=t.level)),t.children&&t.children.length&&t.children.some(function(e){return e.visible})){var o=0;t.children.forEach(function(e){e.visible&&(l(e,t),o+=e.colSpan)}),t.colSpan=o}else t.colSpan=1}(e)});for(var l=[],t=0;t<n;t++)l.push([]);return getAllColumns(e).forEach(function(e){e.children&&e.children.length&&e.children.some(function(e){return e.visible})?e.rowSpan=1:e.rowSpan=n-e.level+1,l[e.level-1].push(e)}),l},_default={name:"PlxTableHeader",props:{tableData:Array,tableColumn:Array,visibleColumn:Array,collectColumn:Array,fixedColumn:Array,size:String,fixedType:String,isGroup:Boolean},data:function(){return{headerColumn:[]}},watch:{tableColumn:function(){this.uploadColumn()}},created:function(){this.uploadColumn()},mounted:function(){var e=this.$parent,l=this.$el,t=this.$refs,o=this.fixedType,n=e.elemStore,r="".concat(o||"main","-header-");n["".concat(r,"wrapper")]=l,n["".concat(r,"table")]=t.table,n["".concat(r,"colgroup")]=t.colgroup,n["".concat(r,"list")]=t.thead,n["".concat(r,"xSpace")]=t.xSpace,n["".concat(r,"repair")]=t.repair},render:function(C){var w=this,e=this._e,$=this.$parent,T=this.fixedType,l=this.headerColumn,t=this.tableColumn,o=this.fixedColumn,z=$.$listeners,n=$.id,I=$.resizable,S=$.border,P=$.columnKey,r=$.headerRowClassName,E=$.headerCellClassName,i=$.headerRowStyle,R=$.headerCellStyle,U=$.showHeaderOverflow,k=$.headerAlign,D=$.align,W=$.highlightCurrentColumn,a=$.mouseConfig,s=$.mouseOpts,A=$.scrollXLoad,M=$.scrollYLoad,H=$.overflowX,c=$.scrollbarWidth,L=$.getColumnIndex,O=$.sortOpts,q=a&&s.selected,N=a&&(s.range||s.checked);return A&&T&&(t=o),C("div",{class:["plx-table--header-wrapper",T?"fixed-".concat(T,"--wrapper"):"body--wrapper"],attrs:{"data-tid":n}},[T?e():C("div",{class:"plx-body--x-space",ref:"xSpace"}),C("table",{class:"plx-table--header",attrs:{"data-tid":n,cellspacing:0,cellpadding:0,border:0},ref:"table"},[C("colgroup",{ref:"colgroup"},t.map(function(e,l){var t=e.children&&e.children.length;return C("col",{attrs:{name:e.id},key:P||t?e.id:l})}).concat(c?[C("col",{attrs:{name:"col_gutter"}})]:[])),C("thead",{ref:"thead"},l.map(function(_,y){return C("tr",{class:["plx-header--row",r?_xeUtils.default.isFunction(r)?r({$table:$,$rowIndex:y,fixed:T}):r:""],style:i?_xeUtils.default.isFunction(i)?i({$table:$,$rowIndex:y,fixed:T}):i:null},_.map(function(l,t){var e,o=l.showHeaderOverflow,n=l.headerAlign,r=l.align,i=l.headerClassName,a=l.children&&l.children.length,s=T?l.fixed!==T&&!a:l.fixed&&H,c=_xeUtils.default.isUndefined(o)||_xeUtils.default.isNull(o)?U:o,d=n||r||k||D,u="ellipsis"===c,f="title"===c,h=!0===c||"tooltip"===c,p=f||h||u,m={},x=l.filters&&l.filters.some(function(e){return e.checked}),v=L(l),b={$table:$,$rowIndex:y,column:l,columnIndex:v,$columnIndex:t,fixed:T,isHidden:s,hasFilter:x};!A&&!M||p||(u=p=!0),(f||h)&&(m.mouseenter=function(e){$._isResize||(f?_tools.DomTools.updateCellTitle(e):h&&$.triggerHeaderTooltipEvent(e,{$table:$,$rowIndex:y,column:l,columnIndex:v,$columnIndex:t,fixed:T}))}),h&&(m.mouseleave=function(e){$._isResize||h&&$.handleTargetLeaveEvent(e)}),(W||z["header-cell-click"]||N||"cell"===O.trigger)&&(m.click=function(e){return $.triggerHeaderCellClickEvent(e,{$table:$,$rowIndex:y,column:l,columnIndex:v,$columnIndex:t,fixed:T,cell:e.currentTarget})}),z["header-cell-dblclick"]&&(m.dblclick=function(e){return _tools.UtilTools.emitEvent($,"header-cell-dblclick",[{$table:$,$rowIndex:y,column:l,columnIndex:v,$columnIndex:t,fixed:T,cell:e.currentTarget},e])}),(q||N)&&(m.mousedown=function(e){return $.triggerHeaderCellMousedownEvent(e,{$table:$,$rowIndex:y,column:l,columnIndex:v,$columnIndex:t,fixed:T,cell:e.currentTarget})});var g="seq"===l.type||"index"===l.type?"seq":l.type;return C("th",{class:["plx-header--column",l.id,(_defineProperty(e={},"col--".concat(d),d),_defineProperty(e,"col--".concat(g),g),_defineProperty(e,"col--last",t===_.length-1),_defineProperty(e,"col--fixed",l.fixed),_defineProperty(e,"col--group",a),_defineProperty(e,"col--ellipsis",p),_defineProperty(e,"fixed--hidden",s),_defineProperty(e,"is--sortable",l.sortable),_defineProperty(e,"is--filter",l.filters),_defineProperty(e,"filter--active",x),e),_tools.UtilTools.getClass(i,b),_tools.UtilTools.getClass(E,b)],attrs:{"data-colid":l.id,colspan:l.colSpan,rowspan:l.rowSpan},style:R?_xeUtils.default.isFunction(R)?R(b):R:null,on:m,key:P||a?l.id:v},[C("div",{class:["plx-cell",{"c--title":f,"c--tooltip":h,"c--ellipsis":u}]},l.renderHeader(C,b)),!s&&!a&&(_xeUtils.default.isBoolean(l.resizable)?l.resizable:I)?C("div",{class:["plx-resizable",{"is--line":!S}],on:{mousedown:function(e){return w.resizeMousedown(e,b)}}}):null])}).concat(c?[C("th",{class:"col--gutter"})]:[]))}))]),C("div",{class:"plx-table--repair",ref:"repair"})])},methods:{uploadColumn:function(){this.headerColumn=this.isGroup?convertToRows(this.collectColumn):[this.$parent.scrollXLoad&&this.fixedType?this.fixedColumn:this.tableColumn]},resizeMousedown:function(e,l){var t=l.column,o=this.$parent,n=this.$el,r=this.fixedType,i=o.$refs,a=i.tableBody,s=i.leftContainer,c=i.rightContainer,d=i.resizeBar,u=e.target,f=e.clientX,h=u.parentNode,p=0,m=a.$el,x=_tools.DomTools.getOffsetPos(u,n),v=u.clientWidth,b=x.left-h.clientWidth+v+36,g=x.left+Math.floor(v/2),_=document.onmousemove,y=document.onmouseup,C="left"===r,w="right"===r,$=0;if(C||w){for(var T=C?"nextElementSibling":"previousElementSibling",z=h[T];z&&!_tools.DomTools.hasClass(z,"fixed--hidden");)_tools.DomTools.hasClass(z,"col--group")||($+=z.offsetWidth),z=z[T];w&&c&&(g=c.offsetLeft+$)}function I(e){e.stopPropagation(),e.preventDefault();var l=e.clientX-f,t=g+l,o=r?0:m.scrollLeft;C?t=Math.min(t,(c?c.offsetLeft:m.clientWidth)-$-36):w&&(b=(s?s.clientWidth:0)+$+36,t=Math.min(t,g+h.clientWidth-36)),p=Math.max(t,b),d.style.left="".concat(p-o,"px")}o._isResize=!0,_tools.DomTools.addClass(o.$el,"c--resize"),d.style.display="block",document.onmousemove=I,document.onmouseup=function(e){document.onmousemove=_,document.onmouseup=y,t.resizeWidth=t.renderWidth+(w?g-p:p-g),d.style.display="none",o._isResize=!1,o._lastResizeTime=Date.now(),o.analyColumnWidth(),o.recalculate(!0),_tools.DomTools.removeClass(o.$el,"c--resize"),o.$toolbar&&o.$toolbar.updateResizable(),_tools.UtilTools.emitEvent(o,"resizable-change",[l])},I(e)}}};exports.default=_default;