import{d as P,w as U,o as j,f as D,g as r,i as J,A as g,J as m,B as k,j as p,a8 as E,O as h,P as T,Y as K,r as b,c as Y}from"./index-DOFLUERq.js";import{I as y}from"./iconify-p99pbjf9.js";import{_ as $}from"./_plugin-vue_export-helper-DlAUqK2U.js";const q={class:"image-wrapper"},z=["src","alt"],F={key:0,class:"image-index"},H=P({__name:"ImageGallery",props:{images:{},initialIndex:{}},emits:["close"],setup(s,{expose:_,emit:B}){const n=s,M=B,o=b(!1),t=b(0),u=b(!1),X=Y(()=>n.images[t.value]||""),N=(e=0)=>{t.value=Math.max(0,Math.min(e,n.images.length-1)),o.value=!0,u.value=!1},c=()=>{o.value=!1,M("close")},l=()=>{n.images.length<=1||(t.value=t.value>0?t.value-1:n.images.length-1,u.value=!1)},i=()=>{n.images.length<=1||(t.value=t.value<n.images.length-1?t.value+1:0,u.value=!1)},S=e=>{e.target===e.currentTarget&&c()},A=e=>{const a=e.target;if(!(a.tagName==="BUTTON"||a.closest("button"))&&!(a.classList.contains("image-index")||a.closest(".image-index"))){if(a.classList.contains("gallery-image")){const d=a.getBoundingClientRect(),f=e.clientX-d.left,O=d.width;f<O/2?l():i();return}c()}},R=e=>{e.stopPropagation();const v=e.currentTarget.getBoundingClientRect(),d=e.clientX-v.left,f=v.width;d<f/2?l():i()},V=()=>{u.value=!0},x=e=>{if(o.value)switch(e.key){case"Escape":c();break;case"ArrowLeft":l();break;case"ArrowRight":i();break}};let w=0,C=0;const I=e=>{e.touches.length===1&&(w=e.touches[0].clientX)},L=e=>{e.changedTouches.length===1&&(C=e.changedTouches[0].clientX,G())},G=()=>{const e=C-w;Math.abs(e)>50&&(e<0?i():l())};return U(()=>n.initialIndex,e=>{e!==void 0&&o.value&&(t.value=Math.max(0,Math.min(e,n.images.length-1)))}),j(()=>{document.addEventListener("keydown",x),document.addEventListener("touchstart",I,{passive:!0}),document.addEventListener("touchend",L,{passive:!0})}),D(()=>{document.removeEventListener("keydown",x),document.removeEventListener("touchstart",I),document.removeEventListener("touchend",L)}),_({open:N,close:c}),(e,a)=>(r(),J(K,{to:"body"},[o.value?(r(),g("div",{key:0,class:"image-gallery-modal",onClick:S},[m("div",{class:"image-gallery-container",onClick:A},[m("button",{class:"close-btn",onClick:c},[k(p(y),{icon:"tabler:x"})]),m("div",q,[m("img",{src:X.value,alt:`图片 ${t.value+1}`,class:"gallery-image",onLoad:V,onClick:R},null,40,z),s.images.length>1?(r(),g("button",{key:0,class:"nav-btn nav-left",onClick:E(l,["stop"])},[k(p(y),{icon:"tabler:chevron-left"})])):h("",!0),s.images.length>1?(r(),g("button",{key:1,class:"nav-btn nav-right",onClick:E(i,["stop"])},[k(p(y),{icon:"tabler:chevron-right"})])):h("",!0)]),s.images.length>1?(r(),g("div",F,T(t.value+1)+" / "+T(s.images.length),1)):h("",!0)])])):h("",!0)]))}}),ee=$(H,[["__scopeId","data-v-5cebea08"]]);export{ee as default};
