import{defineComponent as w,computed as h,createVNode as d}from"vue";import S from"../../_util/classNames.mjs";import{useInjectTable as H}from"../context/TableContext.mjs";import b from"./HeaderRow.mjs";function k(p){const o=[];function f(t,r,a=0){o[a]=o[a]||[];let c=r;return t.filter(Boolean).map(e=>{const n={key:e.key,class:S(e.className,e.class),column:e,colStart:c};let s=1;const l=e.children;return l&&l.length>0&&(s=f(l,c,a+1).reduce((m,C)=>m+C,0),n.hasSubColumns=!0),"colSpan"in e&&({colSpan:s}=e),"rowSpan"in e&&(n.rowSpan=e.rowSpan),n.colSpan=s,n.colEnd=n.colStart+s-1,o[a].push(n),c+=s,s})}f(p,0);const u=o.length;for(let t=0;t<u;t+=1)o[t].forEach(r=>{!("rowSpan"in r)&&!r.hasSubColumns&&(r.rowSpan=u-t)});return o}const O=w({name:"TableHeader",inheritAttrs:!1,props:["columns","flattenColumns","stickyOffsets","customHeaderRow"],setup(p){const o=H(),f=h(()=>k(p.columns));return()=>{const{prefixCls:u,getComponent:t}=o,{stickyOffsets:r,flattenColumns:a,customHeaderRow:c}=p,i=t(["header","wrapper"],"thead"),e=t(["header","row"],"tr"),n=t(["header","cell"],"th");return d(i,{class:`${u}-thead`},{default:()=>[f.value.map((s,l)=>d(b,{key:l,flattenColumns:a,cells:s,stickyOffsets:r,rowComponent:e,cellComponent:n,customHeaderRow:c,index:l},null))]})}}});export{O as default};
