"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const o=require("vue"),re=require("../../_util/classNames.js"),se=require("../../_util/eagerComputed.js"),h=require("../../_util/props-util/index.js"),ae=require("../../_util/vnode.js"),ce=require("../../table/context.js"),B=require("../../vc-util/Dom/class.js"),de=require("../context/HoverContext.js"),ue=require("../context/StickyContext.js"),fe=require("../utils/legacyUtil.js"),G=require("../utils/valueUtil.js");function xe(t,d,x,p){const C=t+d-1;return t<=p&&C>=x}function pe(t){return t&&typeof t=="object"&&!Array.isArray(t)&&!o.isVNode(t)}const ve=o.defineComponent({name:"Cell",props:["prefixCls","record","index","renderIndex","dataIndex","customRender","component","colSpan","rowSpan","fixLeft","fixRight","firstFixLeft","lastFixLeft","firstFixRight","lastFixRight","appendNode","additionalProps","ellipsis","align","rowType","isSticky","column","cellType","transformCellText"],setup(t,{slots:d}){const x=ce.useInjectSlots(),{onHover:p,startRow:C,endRow:J}=de.useInjectHover(),K=o.computed(()=>t.colSpan??t.additionalProps?.colSpan??t.additionalProps?.colspan),b=o.computed(()=>t.rowSpan??t.additionalProps?.rowSpan??t.additionalProps?.rowspan),T=se.default(()=>{const{index:l}=t;return xe(l,b.value||1,C.value,J.value)}),r=ue.useInjectSticky(),Q=(l,n)=>{const{record:a,index:v,additionalProps:w}=t;a&&p(v,v+n-1),w?.onMouseenter?.(l)},W=l=>{const{record:n,additionalProps:a}=t;n&&p(-1,-1),a?.onMouseleave?.(l)},q=l=>{const n=h.filterEmpty(l)[0];return o.isVNode(n)?n.type===o.Text?n.children:Array.isArray(n.children)?q(n.children):void 0:n},S=o.shallowRef(null);return o.watch([T,()=>t.prefixCls,S],()=>{const l=h.findDOMNode(S.value);l&&(T.value?B.addClass(l,`${t.prefixCls}-cell-row-hover`):B.removeClass(l,`${t.prefixCls}-cell-row-hover`))}),()=>{const{prefixCls:l,record:n,index:a,renderIndex:v,dataIndex:w,customRender:F,component:X="td",fixLeft:A,fixRight:k,firstFixLeft:Y,lastFixLeft:I,firstFixRight:L,lastFixRight:Z,appendNode:V=d.appendNode?.(),additionalProps:R={},ellipsis:y,align:j,rowType:ee,isSticky:te,column:u={},cellType:M}=t,i=`${l}-cell`;let E,e;const H=d.default?.();if(G.validateValue(H)||M==="header")e=H;else{const s=G.getPathValue(n,w);if(e=s,F){const c=F({text:s,value:s,record:n,index:a,renderIndex:v,column:u.__originColumn__});pe(c)?(e=c.children,E=c.props):e=c}if(!(fe.INTERNAL_COL_DEFINE in u)&&M==="body"&&x.value.bodyCell&&!u.slots?.customRender){const c=ae.customRenderSlot(x.value,"bodyCell",{text:s,value:s,record:n,index:a,column:u.__originColumn__},()=>{const g=e===void 0?s:e;return[typeof g=="object"&&h.isValidElement(g)||typeof g!="object"?g:null]});e=h.flattenChildren(c)}t.transformCellText&&(e=t.transformCellText({text:e,record:n,index:a,column:u.__originColumn__}))}typeof e=="object"&&!Array.isArray(e)&&!o.isVNode(e)&&(e=null),y&&(I||L)&&(e=o.createVNode("span",{class:`${i}-content`},[e])),Array.isArray(e)&&e.length===1&&(e=e[0]);const{colSpan:D,rowSpan:O,style:ne,class:le,...oe}=E||{},_=(D!==void 0?D:K.value)??1,m=(O!==void 0?O:b.value)??1;if(_===0||m===0)return null;const f={},N=typeof A=="number"&&r.value,$=typeof k=="number"&&r.value;N&&(f.position="sticky",f.left=`${A}px`),$&&(f.position="sticky",f.right=`${k}px`);const U={};j&&(U.textAlign=j);let P;const z=y===!0?{showTitle:!0}:y;z&&(z.showTitle||ee==="header")&&(typeof e=="string"||typeof e=="number"?P=e.toString():o.isVNode(e)&&(P=q([e])));const ie={title:P,...oe,...R,colSpan:_!==1?_:null,rowSpan:m!==1?m:null,class:re.default(i,{[`${i}-fix-left`]:N&&r.value,[`${i}-fix-left-first`]:Y&&r.value,[`${i}-fix-left-last`]:I&&r.value,[`${i}-fix-right`]:$&&r.value,[`${i}-fix-right-first`]:L&&r.value,[`${i}-fix-right-last`]:Z&&r.value,[`${i}-ellipsis`]:y,[`${i}-with-append`]:V,[`${i}-fix-sticky`]:(N||$)&&te&&r.value},R.class,le),onMouseenter:s=>{Q(s,m)},onMouseleave:W,style:[R.style,U,f,ne]};return o.createVNode(X,{...ie,ref:S},{default:()=>[V,e,d.dragHandle?.()]})}}});exports.default=ve;
