const e=require("../_util/type.js"),t=require("../_util/classNames.js"),n=require("../_util/props-util/initDefaultProps.js"),r=require("../_util/props-util/index.js"),i=require("../config-provider/hooks/useConfigInject.js"),a=require("../_util/eagerComputed.js"),o=require("../_util/responsiveObserve.js"),s=require("../_util/hooks/useBreakpoint.js"),c=require("../grid/Row.js"),l=require("../pagination/index.js"),u=require("../spin/index.js"),d=require("./ItemMeta.js"),f=require("./contextKey.js"),p=require("./Item.js"),m=require("./style/index.js");let h=require("vue");var g=()=>({bordered:e.booleanType(),dataSource:e.arrayType(),extra:e.vNodeType(),grid:e.objectType(),itemLayout:String,loading:e.someType([Boolean,Object]),loadMore:e.vNodeType(),pagination:e.someType([Boolean,Object]),prefixCls:String,rowKey:e.someType([String,Number,Function]),renderItem:e.functionType(),size:String,split:e.booleanType(),header:e.vNodeType(),footer:e.vNodeType(),locale:e.objectType()}),_=(0,h.defineComponent)({compatConfig:{MODE:3},name:`AList`,inheritAttrs:!1,Item:p.default,props:n.default(g(),{dataSource:[],bordered:!1,split:!0,loading:!1,pagination:!1}),slots:Object,setup(e,{slots:n,attrs:d}){(0,h.provide)(f.ListContextKey,{grid:(0,h.toRef)(e,`grid`),itemLayout:(0,h.toRef)(e,`itemLayout`)});let p={current:1,total:0},{prefixCls:g,direction:_,renderEmpty:v}=i.default(`list`,e),[y,b]=m.default(g),x=(0,h.computed)(()=>e.pagination&&typeof e.pagination==`object`?e.pagination:{}),S=(0,h.ref)(x.value.defaultCurrent??1),C=(0,h.ref)(x.value.defaultPageSize??10);(0,h.watch)(x,()=>{`current`in x.value&&(S.value=x.value.current),`pageSize`in x.value&&(C.value=x.value.pageSize)});let w=[],T=e=>(t,n)=>{S.value=t,C.value=n,x.value[e]&&x.value[e](t,n)},E=T(`onChange`),D=T(`onShowSizeChange`),O=(0,h.computed)(()=>typeof e.loading==`boolean`?{spinning:e.loading}:e.loading),k=(0,h.computed)(()=>O.value&&O.value.spinning),A=(0,h.computed)(()=>{let t=``;switch(e.size){case`large`:t=`lg`;break;case`small`:t=`sm`;break;default:break}return t}),j=(0,h.computed)(()=>({[`${g.value}`]:!0,[`${g.value}-vertical`]:e.itemLayout===`vertical`,[`${g.value}-${A.value}`]:A.value,[`${g.value}-split`]:e.split,[`${g.value}-bordered`]:e.bordered,[`${g.value}-loading`]:k.value,[`${g.value}-grid`]:!!e.grid,[`${g.value}-rtl`]:_.value===`rtl`})),M=(0,h.computed)(()=>{let t={...p,total:e.dataSource.length,current:S.value,pageSize:C.value,...e.pagination||{}},n=Math.ceil(t.total/t.pageSize);return t.current>n&&(t.current=n),t}),N=(0,h.computed)(()=>{let t=[...e.dataSource];return e.pagination&&e.dataSource.length>(M.value.current-1)*M.value.pageSize&&(t=[...e.dataSource].splice((M.value.current-1)*M.value.pageSize,M.value.pageSize)),t}),P=s.default(),F=a.default(()=>{for(let e=0;e<o.responsiveArray.length;e+=1){let t=o.responsiveArray[e];if(P.value[t])return t}}),I=(0,h.computed)(()=>{if(!e.grid)return;let t=F.value&&e.grid[F.value]?e.grid[F.value]:e.grid.column;if(t)return{width:`${100/t}%`,maxWidth:`${100/t}%`}}),L=(t,r)=>{let i=e.renderItem??n.renderItem;if(!i)return null;let a,o=typeof e.rowKey;return a=o===`function`?e.rowKey(t):o===`string`||o===`number`?t[e.rowKey]:t.key,a||(a=`list-item-${r}`),w[r]=a,i({item:t,index:r})};return()=>{let i=e.loadMore??n.loadMore?.(),a=e.footer??n.footer?.(),o=e.header??n.header?.(),s=r.flattenChildren(n.default?.()),f=!!(i||e.pagination||a),p=t.default({...j.value,[`${g.value}-something-after-last-item`]:f},d.class,b.value),m=e.pagination?(0,h.createVNode)(`div`,{class:`${g.value}-pagination`},[(0,h.createVNode)(l.default,{...M.value,onChange:E,onShowSizeChange:D},null)]):null,_=k.value&&(0,h.createVNode)(`div`,{style:{minHeight:`53px`}},null);if(N.value.length>0){w.length=0;let t=N.value.map((e,t)=>L(e,t)),n=t.map((e,t)=>(0,h.createVNode)(`div`,{key:w[t],style:I.value},[e]));_=e.grid?(0,h.createVNode)(c.default,{gutter:e.grid.gutter},{default:()=>[n]}):(0,h.createVNode)(`ul`,{class:`${g.value}-items`},[t])}else!s.length&&!k.value&&(_=(0,h.createVNode)(`div`,{class:`${g.value}-empty-text`},[e.locale?.emptyText||v(`List`)]));let x=M.value.position||`bottom`;return y((0,h.createVNode)(`div`,{...d,class:p},[(x===`top`||x===`both`)&&m,o&&(0,h.createVNode)(`div`,{class:`${g.value}-header`},[o]),(0,h.createVNode)(u.default,O.value,{default:()=>[_,s]}),a&&(0,h.createVNode)(`div`,{class:`${g.value}-footer`},[a]),i||(x===`bottom`||x===`both`)&&m]))}}});_.install=function(e){return e.component(_.name,_),e.component(_.Item.name,_.Item),e.component(_.Item.Meta.name,_.Item.Meta),e},exports.ListItem=p.default,exports.ListItemMeta=d.default,exports.default=_,exports.listProps=g;