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