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