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