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