"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.Cell=void 0;var _xeUtils=_interopRequireDefault(require("xe-utils/methods/xe-utils")),_conf=_interopRequireDefault(require("../../conf")),_vXETable=require("../../v-x-e-table"),_tools=require("../../tools");function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}var Cell={createColumn:function(e,r){var t=r.type,n=r.sortable,l=r.remoteSort,o=r.filters,d=r.editRender,i=r.treeNode,a=e.treeConfig,c=e.checkboxConfig||e.selectConfig,s=a&&i,u={renderHeader:this.renderHeader,renderCell:s?this.renderTreeCell:this.renderCell};switch(t){case"index":u.renderHeader=this.renderIndexHeader,u.renderCell=s?this.renderTreeIndexCell:this.renderIndexCell;break;case"radio":u.renderHeader=this.renderRadioHeader,u.renderCell=s?this.renderTreeRadioCell:this.renderRadioCell;break;case"checkbox":case"selection":u.renderHeader=this.renderSelectionHeader,u.renderCell=c&&c.checkField?s?this.renderTreeSelectionCellByProp:this.renderSelectionCellByProp:s?this.renderTreeSelectionCell:this.renderSelectionCell;break;case"expand":u.renderCell=this.renderExpandCell,u.renderData=this.renderExpandData;break;default:d?(u.renderHeader=this.renderEditHeader,u.renderCell=e.editConfig&&"cell"===e.editConfig.mode?s?this.renderTreeCellEdit:this.renderCellEdit:s?this.renderTreeRadioCell:this.renderRowEdit):o&&o.length&&(n||l)?u.renderHeader=this.renderSortAndFilterHeader:n||l?u.renderHeader=this.renderSortHeader:o&&o.length&&(u.renderHeader=this.renderFilterHeader)}return _tools.UtilTools.getColumnConfig(r,u)},renderHeader:function(e,r){var t=r.column,n=t.slots,l=t.own;return n&&n.header?n.header(r,e):[_tools.UtilTools.formatText(_tools.UtilTools.getFuncText(l.title||l.label),1)]},renderCell:function(e,r){var t,n=r.$table,l=r.row,o=r.column,d=o.slots,i=o.own,a=i.editRender||i.cellRender;if(d&&d.default)return d.default(r,e);if(a){var c=i.editRender?"renderCell":"renderDefault",s=_vXETable.Renderer.get(a.name);if(s&&s[c])return s[c].call(n,e,a,r,{$type:i.editRender?"edit":"cell",$excel:n.$parent,$table:n,$column:o})}return t=_tools.UtilTools.getCellLabel(l,o,r),[_tools.UtilTools.formatText(t,1)]},renderTreeCell:function(e,r){return Cell.renderTreeIcon(e,r).concat(Cell.renderCell.call(this,e,r))},renderTreeIcon:function(e,r){var t=_conf.default.icon,n=r.$table,l=n.treeConfig,o=n.treeExpandeds,d=r.row,i=r.level,a=l.children,c=l.indent,s=l.trigger,u=d[a],f={};return s&&"default"!==s||(f.click=function(e){return n.triggerTreeExpandEvent(e,r)}),[e("span",{class:"vxe-tree--indent",style:{width:"".concat(i*(c||16),"px")}}),e("span",{class:["vxe-tree-wrapper",{"is--active":-1<o.indexOf(d)}],on:f},u&&u.length?[e("i",{class:"vxe-tree--node-btn ".concat(t.tree)})]:[])]},renderIndexHeader:function(e,r){var t=r.column,n=t.slots,l=t.own;return n&&n.header?n.header(r,e):[_tools.UtilTools.formatText(_tools.UtilTools.getFuncText(l.title||l.label||"#"),1)]},renderIndexCell:function(e,r){var t=r.$table,n=r.column,l=t.startIndex,o=n.slots,d=n.indexMethod;if(o&&o.default)return o.default(r,e);var i=r.$seq,a=r.seq,c=r.level;return[_tools.UtilTools.formatText(d?d(r):c?"".concat(i,".").concat(a):l+a,1)]},renderTreeIndexCell:function(e,r){return Cell.renderTreeIcon(e,r).concat(Cell.renderIndexCell(e,r))},renderRadioHeader:function(e,r){var t=r.column,n=t.slots,l=t.own;return n&&n.header?n.header(r,e):[_tools.UtilTools.formatText(_tools.UtilTools.getFuncText(l.title||l.label),1)]},renderRadioCell:function(e,r){var t,n=r.$table,l=r.column,o=r.isHidden,d=n.vSize,i=n.radioConfig,a=void 0===i?{}:i,c=l.slots,s=a.labelField,u=a.checkMethod,f=!!u;if(c&&c.default)return c.default(r,e);var x=n.selectRow,C=r.row,h={attrs:{type:"radio",name:"vxe-radio--".concat(n.id)}};return o||(u&&(f=!u(r),h.attrs.disabled=f),h.domProps={checked:C===x},h.on={change:function(e){n.triggerRadioRowEvent(e,r)}}),[e("label",{class:["vxe-radio",(t={},_defineProperty(t,"size--".concat(d),d),_defineProperty(t,"is--disabled",f),t)]},[e("input",h),e("span",{class:"vxe-radio--icon"}),s?e("span",{class:"vxe-radio--label"},_xeUtils.default.get(C,s)):null])]},renderTreeRadioCell:function(e,r){return Cell.renderTreeIcon(e,r).concat(Cell.renderRadioCell(e,r))},renderSelectionHeader:function(e,r){var t,n=r.$table,l=r.column,o=r.isHidden,d=n.vSize,i=n.isIndeterminate,a=n.isAllCheckboxDisabled,c=l.slots,s=l.own,u=n.checkboxConfig||n.selectConfig,f=s.title||s.label,x={attrs:{type:"checkbox",disabled:a}};return c&&c.header?c.header(r,e):u&&(u.checkStrictly?!u.showHeader:!1===u.showHeader)?[]:(o||(x.domProps={checked:!a&&n.isAllSelected},x.on={change:function(e){n.triggerCheckAllEvent(e,e.target.checked)}}),[e("label",{class:["vxe-checkbox",(t={},_defineProperty(t,"size--".concat(d),d),_defineProperty(t,"is--disabled",x.attrs.disabled),_defineProperty(t,"is--indeterminate",i),t)]},[e("input",x),e("span",{class:"vxe-checkbox--icon"}),f?e("span",{class:"vxe-checkbox--label"},_tools.UtilTools.getFuncText(f)):null])])},renderSelectionCell:function(e,r){var t,n=r.$table,l=r.row,o=r.column,d=r.isHidden,i=n.vSize,a=n.treeConfig,c=n.treeIndeterminates,s=n.checkboxConfig||n.selectConfig||{},u=s.labelField,f=s.checkMethod,x=o.slots,C=!1,h=!!f,b={attrs:{type:"checkbox"}};return x&&x.default?x.default(r,e):(d||(f&&(h=!f(r),b.attrs.disabled=h),a&&(C=-1<c.indexOf(l)),b.domProps={checked:-1<n.selection.indexOf(l)},b.on={change:function(e){n.triggerCheckRowEvent(e,r,e.target.checked)}}),[e("label",{class:["vxe-checkbox",(t={},_defineProperty(t,"size--".concat(i),i),_defineProperty(t,"is--indeterminate",C),_defineProperty(t,"is--disabled",h),t)]},[e("input",b),e("span",{class:"vxe-checkbox--icon"}),u?e("span",{class:"vxe-checkbox--label"},_xeUtils.default.get(l,u)):null])])},renderTreeSelectionCell:function(e,r){return Cell.renderTreeIcon(e,r).concat(Cell.renderSelectionCell(e,r))},renderSelectionCellByProp:function(e,r){var t,n=r.$table,l=r.row,o=r.column,d=r.isHidden,i=n.vSize,a=n.treeConfig,c=n.treeIndeterminates,s=n.checkboxConfig||n.selectConfig||{},u=s.labelField,f=s.checkField,x=s.checkMethod,C=o.slots,h=!1,b=!!x,v={attrs:{type:"checkbox"}};return C&&C.default?C.default(r,e):(d||(x&&(b=!x(r),v.attrs.disabled=b),a&&(h=-1<c.indexOf(l)),v.domProps={checked:_xeUtils.default.get(l,f)},v.on={change:function(e){n.triggerCheckRowEvent(e,r,e.target.checked)}}),[e("label",{class:["vxe-checkbox",(t={},_defineProperty(t,"size--".concat(i),i),_defineProperty(t,"is--indeterminate",h),_defineProperty(t,"is--disabled",b),t)]},[e("input",v),e("span",{class:"vxe-checkbox--icon"}),u?e("span",{class:"vxe-checkbox--label"},_xeUtils.default.get(l,u)):null])])},renderTreeSelectionCellByProp:function(e,r){return Cell.renderTreeIcon(e,r).concat(Cell.renderSelectionCellByProp(e,r))},renderExpandCell:function(e,r){var t=r.$table,n=!1;return r.isHidden||(n=-1<t.expandeds.indexOf(r.row)),[e("span",{class:["vxe-table--expanded",{"expand--active":n}],on:{click:function(e){t.triggerRowExpandEvent(e,r)}}},[e("i",{class:"vxe-table--expand-icon"})])]},renderExpandData:function(e,r){var t=r.column.slots;return t&&t.default?t.default(r,e):[]},renderSortAndFilterHeader:function(e,r){return Cell.renderHeader(e,r).concat(Cell.renderSortIcon(e,r)).concat(Cell.renderFilterIcon(e,r))},renderSortHeader:function(e,r){return Cell.renderHeader(e,r).concat(Cell.renderSortIcon(e,r))},renderSortIcon:function(e,r){var t=_conf.default.icon,n=r.$table,l=r.column;return[e("span",{class:"vxe-sort-wrapper"},[e("i",{class:["vxe-sort--asc-btn",t.sortAsc,{"sort--active":"asc"===l.order}],on:{click:function(e){n.triggerSortEvent(e,l,"asc")}}}),e("i",{class:["vxe-sort--desc-btn",t.sortDesc,{"sort--active":"desc"===l.order}],on:{click:function(e){n.triggerSortEvent(e,l,"desc")}}})])]},renderFilterHeader:function(e,r){return Cell.renderHeader(e,r).concat(Cell.renderFilterIcon(e,r))},renderFilterIcon:function(e,r){var t=_conf.default.icon,n=r.$table,l=r.column,o=n.filterStore;return[e("span",{class:["vxe-filter-wrapper",{"is--active":o.visible&&o.column===l}]},[e("i",{class:"vxe-filter--btn ".concat(t.filter),on:{click:function(e){n.triggerFilterEvent(e,r.column,r)}}})])]},renderEditHeader:function(e,r){var t,n=_conf.default.icon,l=r.$table,o=r.column,d=l.editRules,i=l.editConfig,a=o.sortable,c=o.remoteSort,s=o.filters;if(d){var u=_xeUtils.default.get(d,r.column.property);u&&(t=u.some(function(e){return e.required}))}return[t?e("i",{class:"vxe-required-icon"}):null,i&&!1===i.showIcon?null:e("i",{class:"vxe-edit-icon ".concat(n.edit)})].concat(Cell.renderHeader(e,r)).concat(a||c?Cell.renderSortIcon(e,r):[]).concat(s&&s.length?Cell.renderFilterIcon(e,r):[])},renderRowEdit:function(e,r){var t=r.$table.editStore.actived;return Cell.runRenderer(e,r,this,t&&t.row===r.row)},renderTreeRowEdit:function(e,r){return Cell.renderTreeIcon(e,r).concat(Cell.renderRowEdit(e,r))},renderCellEdit:function(e,r){var t=r.$table.editStore.actived;return Cell.runRenderer(e,r,this,t&&t.row===r.row&&t.column===r.column)},renderTreeCellEdit:function(e,r){return Cell.renderTreeIcon(e,r).concat(Cell.renderCellEdit(e,r))},runRenderer:function(e,r,t,n){var l=r.$table,o=r.row,d=r.column,i=d.slots,a=d.own,c=d.formatter,s=a.editRender,u=_vXETable.Renderer.get(s.name);return"visible"===s.type||n?i&&i.edit?i.edit(r,e):u&&u.renderEdit?u.renderEdit.call(l,e,s,r,{$type:"edit",$excel:l.$parent,$table:l,$column:d}):[]:i&&i.default?i.default(r,e):c?[_tools.UtilTools.formatText(_tools.UtilTools.getCellLabel(o,d,r),1)]:Cell.renderCell.call(t,e,r)}},_default=exports.Cell=Cell;exports.default=_default;