const e=require("../../_virtual/_rolldown/runtime.js"),t=require("../../_util/classNames.js"),n=require("../../_util/vue-types/index.js"),r=require("../../vc-util/Dom/css.js"),i=require("../../_util/hooks/useMergedState.js"),a=require("./PreviewGroup.js"),o=require("./Preview.js");let s=require("vue"),c=require("lodash-es/isNumber");c=e.__toESM(c,1);var l=()=>({src:String,wrapperClassName:String,wrapperStyle:{type:Object,default:void 0},rootClassName:String,prefixCls:String,previewPrefixCls:String,width:[Number,String],height:[Number,String],previewMask:{type:[Boolean,Function],default:void 0},placeholder:n.default.any,fallback:String,preview:{type:[Boolean,Object],default:!0},onClick:{type:Function},onError:{type:Function}}),u=(e,t)=>{let n={...e};return Object.keys(t).forEach(r=>{e[r]===void 0&&(n[r]=t[r])}),n},d=0,f=(0,s.defineComponent)({compatConfig:{MODE:3},name:`VcImage`,inheritAttrs:!1,props:l(),emits:[`click`,`error`],setup(e,{attrs:n,slots:l,emit:f}){let p=(0,s.computed)(()=>e.prefixCls),m=(0,s.computed)(()=>`${p.value}-preview`),h=(0,s.computed)(()=>{let t={visible:void 0,onVisibleChange:()=>{},getContainer:void 0};return typeof e.preview==`object`?u(e.preview,t):t}),g=(0,s.computed)(()=>h.value.src??e.src),_=(0,s.computed)(()=>e.placeholder&&e.placeholder!==!0||l.placeholder),v=(0,s.computed)(()=>h.value.visible),y=(0,s.computed)(()=>h.value.getContainer),b=(0,s.computed)(()=>v.value!==void 0),[x,S]=i.default(!!v.value,{value:v,onChange:(e,t)=>{h.value.onVisibleChange?.(e,t)}}),C=(0,s.ref)(_.value?`loading`:`normal`);(0,s.watch)(()=>e.src,()=>{C.value=_.value?`loading`:`normal`});let w=(0,s.ref)(null),T=(0,s.computed)(()=>C.value===`error`),{isPreviewGroup:E,setCurrent:D,setShowPreview:O,setMousePosition:k,registerImage:A}=a.context.inject(),j=(0,s.ref)(d++),M=(0,s.computed)(()=>e.preview&&!T.value),N=()=>{C.value=`normal`},P=e=>{C.value=`error`,f(`error`,e)},F=e=>{if(!b.value){let{left:t,top:n}=r.getOffset(e.target);E.value?(D(j.value),k({x:t,y:n})):w.value={x:t,y:n}}E.value?O(!0):S(!0),f(`click`,e)},I=()=>{S(!1),b.value||(w.value=null)},L=(0,s.ref)(null);(0,s.watch)(()=>L,()=>{C.value===`loading`&&L.value.complete&&(L.value.naturalWidth||L.value.naturalHeight)&&N()});let R=()=>{};(0,s.onMounted)(()=>{(0,s.watch)([g,M],()=>{if(R(),!E.value)return()=>{};R=A(j.value,g.value,M.value),M.value||R()},{flush:`post`,immediate:!0})}),(0,s.onUnmounted)(()=>{R()});let z=e=>(0,c.default)(e)?`${e}px`:e;return()=>{let{prefixCls:r,wrapperClassName:i,fallback:a,src:c,placeholder:u,wrapperStyle:d,rootClassName:p,width:_,height:v,crossorigin:b,decoding:S,alt:D,sizes:O,srcset:k,usemap:A,class:j,style:R}={...e,...n},{icons:B,maskClassName:V,...H}=h.value,U=t.default(r,i,p,{[`${r}-error`]:T.value}),W=T.value&&a?a:g.value,G={crossorigin:b,decoding:S,alt:D,sizes:O,srcset:k,usemap:A,width:_,height:v,class:t.default(`${r}-img`,{[`${r}-img-placeholder`]:u===!0},j),style:{height:z(v),...R}};return(0,s.createVNode)(s.Fragment,null,[(0,s.createVNode)(`div`,{class:U,onClick:M.value?F:e=>{f(`click`,e)},style:{width:z(_),height:z(v),...d}},[(0,s.createVNode)(`img`,{...G,...T.value&&a?{src:a}:{onLoad:N,onError:P,src:c},ref:L},null),C.value===`loading`&&(0,s.createVNode)(`div`,{"aria-hidden":`true`,class:`${r}-placeholder`},[u||l.placeholder&&l.placeholder()]),l.previewMask&&M.value&&(0,s.createVNode)(`div`,{class:[`${r}-mask`,V]},[l.previewMask()])]),!E.value&&M.value&&(0,s.createVNode)(o.default,{...H,"aria-hidden":!x.value,visible:x.value,prefixCls:m.value,onClose:I,mousePosition:w.value,src:W,alt:D,getContainer:y.value,icons:B,rootClassName:p},null)])}}});f.PreviewGroup=a.default,exports.default=f,exports.imageProps=l,exports.mergeDefaultValue=u;