import e from"../../_util/props-util/initDefaultProps.mjs";import{filterEmpty as t,isValidElement as n}from"../../_util/props-util/index.mjs";import r from"../../config-provider/hooks/useConfigInject.mjs";import{getTransitionGroupProps as i}from"../../_util/transition.mjs";import a from"../../_util/collapseMotion.mjs";import o from"../../button/index.mjs";import{uploadListProps as s}from"../interface.mjs";import{isImageUrl as c,previewImage as l}from"../utils.mjs";import u from"./ListItem.mjs";import{TransitionGroup as d,computed as f,createVNode as p,defineComponent as m,onMounted as h,shallowRef as g,triggerRef as _,vShow as v,watch as y,watchEffect as b,withDirectives as x}from"vue";import{FileTwoTone as S,LoadingOutlined as C,PaperClipOutlined as w,PictureTwoTone as T}from"@antsoo-lib/icons";var E=(e,{slots:n})=>t(n.default?.())[0],D=m({compatConfig:{MODE:3},name:`AUploadList`,props:e(s(),{listType:`text`,progress:{strokeWidth:2,showInfo:!1},showRemoveIcon:!0,showDownloadIcon:!1,showPreviewIcon:!0,previewFile:l,isImageUrl:c,items:[],appendActionVisible:!0}),setup(e,{slots:t,expose:s}){let c=g(!1);h(()=>{c.value});let l=g([]);y(()=>e.items,(e=[])=>{l.value=e.slice()},{immediate:!0,deep:!0}),b(()=>{if(e.listType!==`picture`&&e.listType!==`picture-card`)return;let t=!1;(e.items||[]).forEach((n,r)=>{typeof document>`u`||typeof window>`u`||!window.FileReader||!window.File||!(n.originFileObj instanceof File||n.originFileObj instanceof Blob)||n.thumbUrl!==void 0||(n.thumbUrl=``,e.previewFile&&e.previewFile(n.originFileObj).then(e=>{let i=e||``;i!==n.thumbUrl&&(l.value[r].thumbUrl=i,t=!0)}))}),t&&_(l)});let m=(t,n)=>{if(e.onPreview)return n?.preventDefault(),e.onPreview(t)},D=t=>{typeof e.onDownload==`function`?e.onDownload(t):t.url&&window.open(t.url)},O=t=>{e.onRemove?.(t)},k=({file:n})=>{let r=e.iconRender||t.iconRender;if(r)return r({file:n,listType:e.listType});let i=n.status===`uploading`,a=e.isImageUrl&&e.isImageUrl(n)?p(T,null,null):p(S,null,null),o=p(i?C:w,null,null);return e.listType===`picture`?o=i?p(C,null,null):a:e.listType===`picture-card`&&(o=i?e.locale.uploading:a),o},A=t=>{let{customIcon:r,callback:i,prefixCls:a,title:s}=t,c={type:`text`,size:`small`,title:s,onClick:e=>{i();try{e?.currentTarget?.blur?.()}catch{}},class:`${a}-list-item-action`};return s===e.locale?.downloadFile&&(c.disabled=!1),n(r)?p(o,c,{icon:()=>r}):p(o,c,{default:()=>[p(`span`,null,[r])]})};s({handlePreview:m,handleDownload:D});let{prefixCls:j,rootPrefixCls:M}=r(`upload`,e),N=f(()=>({[`${j.value}-list`]:!0,[`${j.value}-list-${e.listType}`]:!0})),P=f(()=>{let t={...a(`${M.value}-motion-collapse`)};delete t.onAfterAppear,delete t.onAfterEnter,delete t.onAfterLeave;let n={...i(`${j.value}-${e.listType===`picture-card`?`animate-inline`:`animate`}`),class:N.value,appear:c.value};return e.listType===`picture-card`?n:{...t,...n}});return()=>{let{listType:n,locale:r,isImageUrl:i,showPreviewIcon:a,showRemoveIcon:o,showDownloadIcon:s,removeIcon:c,previewIcon:f,downloadIcon:h,progress:g,appendAction:_,itemRender:y,appendActionVisible:b}=e,S=_?.(),C=l.value;return p(d,{...P.value,tag:`div`},{default:()=>[C.map(e=>{let{uid:l}=e;return p(u,{key:l,locale:r,prefixCls:j.value,file:e,items:C,progress:g,listType:n,isImgUrl:i,showPreviewIcon:a,showRemoveIcon:o,showDownloadIcon:s,onPreview:m,onDownload:D,onClose:O,removeIcon:c,previewIcon:f,downloadIcon:h,itemRender:y},{...t,iconRender:k,actionIconRender:A})}),_?x(p(E,{key:`__ant_upload_appendAction`},{default:()=>S}),[[v,!!b]]):null]})}}});export{D as default};