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