import{inject as j,ref as c,computed as t,shallowRef as h,provide as A,defineComponent as O,reactive as D,watch as E,watchEffect as I,createVNode as C,Fragment as K}from"vue";import N from"../../_util/hooks/useMergedState.mjs";import{mergeDefaultValue as R}from"./Image.mjs";import k from"./Preview.mjs";const P=Symbol("previewGroupContext"),B={provide:o=>{A(P,o)},inject:()=>j(P,{isPreviewGroup:h(!1),previewUrls:t(()=>new Map),setPreviewUrls:()=>{},current:c(null),setCurrent:()=>{},setShowPreview:()=>{},setMousePosition:()=>{},registerImage:null,rootClassName:""})},F=()=>({previewPrefixCls:String,preview:{type:[Boolean,Object],default:!0},icons:{type:Object,default:()=>({})}}),L=O({compatConfig:{MODE:3},name:"PreviewGroup",inheritAttrs:!1,props:F(),setup(o,{slots:p}){const n=t(()=>{const e={visible:void 0,onVisibleChange:()=>{},getContainer:void 0,current:0};return typeof o.preview=="object"?R(o.preview,e):e}),i=D(new Map),s=c(),l=t(()=>n.value.visible),b=t(()=>n.value.getContainer),y=(e,r)=>{n.value.onVisibleChange?.(e,r)},[u,w]=N(!!l.value,{value:l,onChange:y}),f=c(null),x=t(()=>l.value!==void 0),G=t(()=>Array.from(i.keys())),m=t(()=>G.value[n.value.current]),d=t(()=>new Map(Array.from(i).filter(([,{canPreview:e}])=>!!e).map(([e,{url:r}])=>[e,r]))),M=(e,r,v=!0)=>{i.set(e,{url:r,canPreview:v})},a=e=>{s.value=e},g=e=>{f.value=e},U=(e,r,v=!0)=>{const S=()=>{i.delete(e)};return i.set(e,{url:r,canPreview:v}),S},V=e=>{e?.stopPropagation(),w(!1),g(null)};return E(m,e=>{a(e)},{immediate:!0,flush:"post"}),I(()=>{u.value&&x.value&&a(m.value)},{flush:"post"}),B.provide({isPreviewGroup:h(!0),previewUrls:d,setPreviewUrls:M,current:s,setCurrent:a,setShowPreview:w,setMousePosition:g,registerImage:U}),()=>{const{...e}=n.value;return C(K,null,[p.default&&p.default(),C(k,{...e,"ria-hidden":!u.value,visible:u.value,prefixCls:o.previewPrefixCls,onClose:V,mousePosition:f.value,src:d.value.get(s.value),icons:o.icons,getContainer:b.value},null)])}}});export{B as context,L as default,F as imageGroupProps};
