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{PictureTwoTone as z,FileTwoTone as H,LoadingOutlined as P,PaperClipOutlined as W}from"@antsoo-lib/icons";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 ne from"./ListItem.mjs";import oe from"../../_util/props-util/initDefaultProps.mjs";import b from"../../button/button.mjs";const te=(e,{slots:s})=>K(s.default?.())[0],ve=_({compatConfig:{MODE:3},name:"AUploadList",props:oe(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,(n=[])=>{c.value=n.slice()},{immediate:!0,deep:!0}),G(()=>{if(e.listType!=="picture"&&e.listType!=="picture-card")return;let n=!1;(e.items||[]).forEach((o,l)=>{typeof document>"u"||typeof window>"u"||!window.FileReader||!window.File||!(o.originFileObj instanceof File||o.originFileObj instanceof Blob)||o.thumbUrl!==void 0||(o.thumbUrl="",e.previewFile&&e.previewFile(o.originFileObj).then(r=>{const t=r||"";t!==o.thumbUrl&&(c.value[l].thumbUrl=t,n=!0)}))}),n&&M(c)});const f=(n,o)=>{if(e.onPreview)return o?.preventDefault(),e.onPreview(n)},w=n=>{typeof e.onDownload=="function"?e.onDownload(n):n.url&&window.open(n.url)},R=n=>{e.onRemove?.(n)},U=({file:n})=>{const o=e.iconRender||s.iconRender;if(o)return o({file:n,listType:e.listType});const l=n.status==="uploading",r=e.isImageUrl&&e.isImageUrl(n)?i(z,null,null):i(H,null,null);let t=l?i(P,null,null):i(W,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=n=>{const{customIcon:o,callback:l,prefixCls:r,title:t}=n,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(o)?i(b,a,{icon:()=>o}):i(b,a,{default:()=>[i("span",null,[o])]})};D({handlePreview:f,handleDownload:w});const{prefixCls:u,rootPrefixCls:A}=X("upload",e),F=T(()=>({[`${u.value}-list`]:!0,[`${u.value}-list-${e.listType}`]:!0})),k=T(()=>{const n={...q(`${A.value}-motion-collapse`)};delete n.onAfterAppear,delete n.onAfterEnter,delete n.onAfterLeave;const o={...Q(`${u.value}-${e.listType==="picture-card"?"animate-inline":"animate"}`),class:F.value,appear:m.value};return e.listType!=="picture-card"?{...n,...o}:o});return()=>{const{listType:n,locale:o,isImageUrl:l,showPreviewIcon:r,showRemoveIcon:t,showDownloadIcon:a,removeIcon:p,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(ne,{key:O,locale:o,prefixCls:u.value,file:g,items:h,progress:x,listType:n,isImgUrl:l,showPreviewIcon:r,showRemoveIcon:t,showDownloadIcon:a,onPreview:f,onDownload:w,onClose:R,removeIcon:p,previewIcon:d,downloadIcon:v,itemRender:L},{...s,iconRender:U,actionIconRender:C})}),I?N(i(te,{key:"__ant_upload_appendAction"},{default:()=>E}),[[S,!!$]]):null]})}}});export{ve as default};
