require("../../vc-util/warning.js");const e=require("../../_util/classNames.js"),t=require("../../vc-util/Dom/addEventListener.js"),n=require("../../_util/KeyCode.js"),r=require("../../vc-util/Dom/css.js"),i=require("../../vc-dialog/IDialogPropTypes.js"),a=require("../../vc-dialog/index.js"),o=require("./PreviewGroup.js"),s=require("./getFixScaleEleTransPosition.js"),ee=require("./hooks/useFrameSetState.js");let c=require("vue");var l={x:0,y:0},u={...i.default(),src:String,alt:String,rootClassName:String,icons:{type:Object,default:()=>({})}},d=(0,c.defineComponent)({compatConfig:{MODE:3},name:`Preview`,inheritAttrs:!1,props:u,emits:[`close`,`afterClose`],setup(i,{emit:u,attrs:d}){let{rotateLeft:te,rotateRight:f,zoomIn:p,zoomOut:m,close:h,left:g,right:_,flipX:ne,flipY:v}=(0,c.reactive)(i.icons),y=(0,c.shallowRef)(1),b=(0,c.shallowRef)(0),x=(0,c.reactive)({x:1,y:1}),[S,C]=ee.default(l),w=()=>u(`close`),T=(0,c.shallowRef)(),E=(0,c.reactive)({originX:0,originY:0,deltaX:0,deltaY:0}),D=(0,c.shallowRef)(!1),{previewUrls:O,current:k,isPreviewGroup:A,setCurrent:j}=o.context.inject(),M=(0,c.computed)(()=>O.value.size),N=(0,c.computed)(()=>Array.from(O.value.keys())),P=(0,c.computed)(()=>N.value.indexOf(k.value)),F=(0,c.computed)(()=>A.value?O.value.get(k.value):i.src),I=(0,c.computed)(()=>A.value&&M.value>1),L=(0,c.shallowRef)({wheelDirection:0}),R=()=>{y.value=1,b.value=0,x.x=1,x.y=1,C(l),u(`afterClose`)},z=e=>{e?y.value+=.5:y.value++,C(l)},B=e=>{y.value>1&&(e?y.value-=.5:y.value--),C(l)},V=()=>{b.value+=90},H=()=>{b.value-=90},U=()=>{x.x=-x.x},W=()=>{x.y=-x.y},G=e=>{e.preventDefault(),e.stopPropagation(),P.value>0&&j(N.value[P.value-1])},K=e=>{e.preventDefault(),e.stopPropagation(),P.value<M.value-1&&j(N.value[P.value+1])},q=e.default({[`${i.prefixCls}-moving`]:D.value}),J=`${i.prefixCls}-operations-operation`,Y=`${i.prefixCls}-operations-icon`,X=[{icon:h,onClick:w,type:`close`},{icon:p,onClick:()=>z(),type:`zoomIn`},{icon:m,onClick:()=>B(),type:`zoomOut`,disabled:(0,c.computed)(()=>y.value===1)},{icon:f,onClick:V,type:`rotateRight`},{icon:te,onClick:H,type:`rotateLeft`},{icon:ne,onClick:U,type:`flipX`},{icon:v,onClick:W,type:`flipY`}],Z=()=>{if(i.visible&&D.value){let e=T.value.offsetWidth*y.value,t=T.value.offsetHeight*y.value,{left:n,top:i}=r.getOffset(T.value),a=b.value%180!=0;D.value=!1;let o=s.default(a?t:e,a?e:t,n,i);o&&C({...o})}},re=e=>{e.button===0&&(e.preventDefault(),e.stopPropagation(),E.deltaX=e.pageX-S.x,E.deltaY=e.pageY-S.y,E.originX=S.x,E.originY=S.y,D.value=!0)},Q=e=>{i.visible&&D.value&&C({x:e.pageX-E.deltaX,y:e.pageY-E.deltaY})},ie=e=>{if(!i.visible)return;e.preventDefault();let t=e.deltaY;L.value={wheelDirection:t}},ae=e=>{!i.visible||!I.value||(e.preventDefault(),e.keyCode===n.default.LEFT?P.value>0&&j(N.value[P.value-1]):e.keyCode===n.default.RIGHT&&P.value<M.value-1&&j(N.value[P.value+1]))},oe=()=>{i.visible&&(y.value!==1&&(y.value=1),(S.x!==l.x||S.y!==l.y)&&C(l))},$=()=>{};return(0,c.onMounted)(()=>{(0,c.watch)([()=>i.visible,D],()=>{$();let e,n,r=t.default(window,`mouseup`,Z,!1),i=t.default(window,`mousemove`,Q,!1),a=t.default(window,`wheel`,ie,{passive:!1}),o=t.default(window,`keydown`,ae,!1);try{window.top!==window.self&&(e=t.default(window.top,`mouseup`,Z,!1),n=t.default(window.top,`mousemove`,Q,!1))}catch(e){`${e}`}$=()=>{r.remove(),i.remove(),a.remove(),o.remove(),e&&e.remove(),n&&n.remove()}},{flush:`post`,immediate:!0}),(0,c.watch)([L],()=>{let{wheelDirection:e}=L.value;e>0?B(!0):e<0&&z(!0)})}),(0,c.onUnmounted)(()=>{$()}),()=>{let{visible:t,prefixCls:n,rootClassName:r}=i;return(0,c.createVNode)(a.default,{...d,transitionName:i.transitionName,maskTransitionName:i.maskTransitionName,closable:!1,keyboard:!0,prefixCls:n,onClose:w,afterClose:R,visible:t,wrapClassName:q,rootClassName:r,getContainer:i.getContainer},{default:()=>[(0,c.createVNode)(`div`,{class:[`${i.prefixCls}-operations-wrapper`,r]},[(0,c.createVNode)(`ul`,{class:`${i.prefixCls}-operations`},[X.map(({icon:t,onClick:n,type:r,disabled:a})=>(0,c.createVNode)(`li`,{class:e.default(J,{[`${i.prefixCls}-operations-operation-disabled`]:a&&a?.value}),onClick:n,key:r},[(0,c.cloneVNode)(t,{class:Y})]))])]),(0,c.createVNode)(`div`,{class:`${i.prefixCls}-img-wrapper`,style:{transform:`translate3d(${S.x}px, ${S.y}px, 0)`}},[(0,c.createVNode)(`img`,{onMousedown:re,onDblclick:oe,ref:T,class:`${i.prefixCls}-img`,src:F.value,alt:i.alt,style:{transform:`scale3d(${x.x*y.value}, ${x.y*y.value}, 1) rotate(${b.value}deg)`}},null)]),I.value&&(0,c.createVNode)(`div`,{class:e.default(`${i.prefixCls}-switch-left`,{[`${i.prefixCls}-switch-left-disabled`]:P.value<=0}),onClick:G},[g]),I.value&&(0,c.createVNode)(`div`,{class:e.default(`${i.prefixCls}-switch-right`,{[`${i.prefixCls}-switch-right-disabled`]:P.value>=M.value-1}),onClick:K},[_])]})}}});exports.default=d,exports.previewProps=u;