import{_ as D,c as s,g as h,w as g,l,j as o,a,n as A,b5 as F,t as m,h as n,i as u,F as E,p as M,ai as N,aM as y,ah as f,aN as I,o as d,a3 as x,b6 as O,k as b,af as v,b7 as j,X as $,aY as U,b8 as R,E as z,b9 as L,ba as V,ag as S,V as B,bb as Y,aS as X,b2 as q,bc as H,bd as Z}from"./Co0rzPff.js";import{D as J}from"./BqPDONPr.js";import{F as T}from"./B9e2zZjP.js";import{_ as K}from"./D4_3Zti7.js";import{N as Q}from"./DXpa0SRI.js";import{i as P}from"./BLsG2mcq.js";import{d as W}from"./BfaRX-7s.js";import{u as _}from"./DN-g_sLF.js";import"./z-xUYPp7.js";import"./CdDJKVfF.js";const ee={class:"modal-gallery universal-labels"},te={class:"gallery-file-input"},ie={class:"file-header"},ae=["src"],re={class:"textarea-wrapper"},le={class:"button-group"},de=["disabled"],ne=["disabled"],se={class:"content"},oe=["src","alt"],ue={class:"text"},pe={key:0},me={key:1},he={class:"controls"},ce={class:"buttons"},ge=["href"],ye={key:3,class:"card header-buttons"},fe={class:"indicator"},Ie={class:"items"},be=["onClick"],ve=["src","alt"],ke={class:"gallery-body"},we={class:"gallery-info"},Ce={key:0},Ge={key:1},Fe={class:"gallery-bottom"},je={class:"gallery-created"},$e={key:0,class:"gallery-buttons input-group"},Te=["onClick"],Pe=["onClick"],De=W({setup(){const{addNotification:i}=N();return{addNotification:i}},data(){return{expandedGalleryItem:null,expandedGalleryIndex:0,zoomedIn:!1,deleteIndex:-1,editIndex:-1,editTitle:"",editDescription:"",editFeatured:!1,editOrder:null,editFile:null,previewImage:null,shouldPreventActions:!1}},computed:{acceptFileTypes(){return"image/png,image/jpeg,image/gif,image/webp,.png,.jpeg,.gif,.webp"}},mounted(){this._keyListener=function(i){this.expandedGalleryItem&&(i.preventDefault(),i.key==="Escape"?this.expandedGalleryItem=null:i.key==="ArrowLeft"?(i.stopPropagation(),this.previousImage()):i.key==="ArrowRight"&&(i.stopPropagation(),this.nextImage()))},document.addEventListener("keydown",this._keyListener.bind(this))},methods:{nextImage(){this.expandedGalleryIndex++,this.expandedGalleryIndex>=this.project.gallery.length&&(this.expandedGalleryIndex=0),this.expandedGalleryItem=this.project.gallery[this.expandedGalleryIndex]},previousImage(){this.expandedGalleryIndex--,this.expandedGalleryIndex<0&&(this.expandedGalleryIndex=this.project.gallery.length-1),this.expandedGalleryItem=this.project.gallery[this.expandedGalleryIndex]},expandImage(i,p){this.expandedGalleryItem=i,this.expandedGalleryIndex=p,this.zoomedIn=!1},resetEdit(){this.editIndex=-1,this.editTitle="",this.editDescription="",this.editFeatured=!1,this.editOrder=null,this.editFile=null,this.previewImage=null},handleFiles(i){this.resetEdit(),this.editFile=i[0],this.showPreviewImage(),this.$refs.modal_edit_item.show()},showPreviewImage(){const i=new FileReader;this.editFile instanceof Blob&&(i.readAsDataURL(this.editFile),i.onload=p=>{this.previewImage=p.target.result})},async createGalleryItem(){this.shouldPreventActions=!0,y();try{let i=`project/${this.project.id}/gallery?ext=${this.editFile?this.editFile.type.split("/")[this.editFile.type.split("/").length-1]:null}&featured=${this.editFeatured}`;this.editTitle&&(i+=`&title=${encodeURIComponent(this.editTitle)}`),this.editDescription&&(i+=`&description=${encodeURIComponent(this.editDescription)}`),this.editOrder&&(i+=`&ordering=${this.editOrder}`),await f(i,{method:"POST",body:this.editFile}),await this.resetProject(),this.$refs.modal_edit_item.hide()}catch(i){this.addNotification({title:"An error occurred",text:i.data?i.data.description:i,type:"error"})}I(),this.shouldPreventActions=!1},async editGalleryItem(){this.shouldPreventActions=!0,y();try{let i=`project/${this.project.id}/gallery?url=${encodeURIComponent(this.project.gallery[this.editIndex].url)}&featured=${this.editFeatured}`;this.editTitle&&(i+=`&title=${encodeURIComponent(this.editTitle)}`),this.editDescription&&(i+=`&description=${encodeURIComponent(this.editDescription)}`),this.editOrder&&(i+=`&ordering=${this.editOrder}`),await f(i,{method:"PATCH"}),await this.resetProject(),this.$refs.modal_edit_item.hide()}catch(i){this.addNotification({title:"An error occurred",text:i.data?i.data.description:i,type:"error"})}I(),this.shouldPreventActions=!1},async deleteGalleryImage(){y();try{await f(`project/${this.project.id}/gallery?url=${encodeURIComponent(this.project.gallery[this.deleteIndex].url)}`,{method:"DELETE"}),await this.resetProject()}catch(i){this.addNotification({title:"An error occurred",text:i.data?i.data.description:i,type:"error"})}I()}}},"$hmZNw8N2Nv"),Ae=Object.assign(De,{__name:"gallery",props:{project:{type:Object,default(){return{}}},currentMember:{type:Object,default(){return null}},resetProject:{type:Function,required:!0,default:()=>{}}},setup(i){const p=i,k=`${p.project.title} - Gallery`,w=`View ${p.project.gallery.length} images of ${p.project.title} on Modrinth.`;return _({title:k,description:w,ogTitle:k,ogDescription:w}),(e,t)=>{var C,G;return d(),s("div",null,[i.currentMember?(d(),h(l(Q),{key:0,ref:"modal_edit_item",header:e.editIndex===-1?"Upload gallery image":"Edit gallery item"},{default:g(()=>[a("div",ee,[a("div",te,[a("div",ie,[n(l(x),{"aria-hidden":"true"}),a("strong",null,m(e.editFile?e.editFile.name:"Current image"),1),e.editIndex===-1?(d(),h(l(T),{key:0,class:"iconified-button raised-button",prompt:"Replace",accept:e.acceptFileTypes,"max-size":5242880,"should-always-reset":"","aria-label":"Replace image",onChange:t[0]||(t[0]=r=>{e.editFile=r[0],e.showPreviewImage()})},{default:g(()=>[n(l(O),{"aria-hidden":"true"})]),_:1},8,["accept"])):o("",!0)]),a("img",{src:e.previewImage?e.previewImage:i.project.gallery[e.editIndex]&&i.project.gallery[e.editIndex].url?i.project.gallery[e.editIndex].url:"https://cdn.modrinth.com/placeholder-banner.svg",alt:"gallery-preview"},null,8,ae)]),t[21]||(t[21]=a("label",{for:"gallery-image-title"},[a("span",{class:"label__title"},"Title")],-1)),b(a("input",{id:"gallery-image-title","onUpdate:modelValue":t[1]||(t[1]=r=>e.editTitle=r),type:"text",maxlength:"64",placeholder:"Enter title..."},null,512),[[v,e.editTitle]]),t[22]||(t[22]=a("label",{for:"gallery-image-desc"},[a("span",{class:"label__title"},"Description")],-1)),a("div",re,[b(a("textarea",{id:"gallery-image-desc","onUpdate:modelValue":t[2]||(t[2]=r=>e.editDescription=r),maxlength:"255",placeholder:"Enter description..."},null,512),[[v,e.editDescription]])]),t[23]||(t[23]=a("label",{for:"gallery-image-ordering"},[a("span",{class:"label__title"},"Order Index")],-1)),b(a("input",{id:"gallery-image-ordering","onUpdate:modelValue":t[3]||(t[3]=r=>e.editOrder=r),type:"number",placeholder:"Enter order index..."},null,512),[[v,e.editOrder]]),t[24]||(t[24]=a("label",{for:"gallery-image-featured"},[a("span",{class:"label__title"},"Featured"),a("span",{class:"label__description"}," A featured gallery image shows up in search and your project card. Only one gallery image can be featured. ")],-1)),e.editFeatured?(d(),s("button",{key:1,id:"gallery-image-featured",class:"iconified-button",onClick:t[5]||(t[5]=r=>e.editFeatured=!1)},[n(l(j),{fill:"currentColor","aria-hidden":"true"}),t[17]||(t[17]=u(" Unfeature image "))])):(d(),s("button",{key:0,id:"gallery-image-featured",class:"iconified-button",onClick:t[4]||(t[4]=r=>e.editFeatured=!0)},[n(l(j),{"aria-hidden":"true"}),t[16]||(t[16]=u(" Feature image "))])),a("div",le,[a("button",{class:"iconified-button",onClick:t[6]||(t[6]=r=>e.$refs.modal_edit_item.hide())},[n(l($),{"aria-hidden":"true"}),t[18]||(t[18]=u(" Cancel "))]),e.editIndex===-1?(d(),s("button",{key:0,class:"iconified-button brand-button",disabled:e.shouldPreventActions,onClick:t[7]||(t[7]=(...r)=>e.createGalleryItem&&e.createGalleryItem(...r))},[n(l(U),{"aria-hidden":"true"}),t[19]||(t[19]=u(" Add gallery image "))],8,de)):(d(),s("button",{key:1,class:"iconified-button brand-button",disabled:e.shouldPreventActions,onClick:t[8]||(t[8]=(...r)=>e.editGalleryItem&&e.editGalleryItem(...r))},[n(l(R),{"aria-hidden":"true"}),t[20]||(t[20]=u(" Save changes "))],8,ne))])])]),_:1},8,["header"])):o("",!0),i.currentMember?(d(),h(l(K),{key:1,ref:"modal_confirm",title:"Are you sure you want to delete this gallery image?",description:"This will remove this gallery image forever (like really forever).","has-to-type":!1,"proceed-label":"Delete",onProceed:e.deleteGalleryImage},null,8,["onProceed"])):o("",!0),e.expandedGalleryItem!=null?(d(),s("div",{key:2,class:"expanded-image-modal",onClick:t[15]||(t[15]=r=>e.expandedGalleryItem=null)},[a("div",se,[a("img",{class:A(["image",{"zoomed-in":e.zoomedIn}]),src:e.expandedGalleryItem.raw_url?e.expandedGalleryItem.raw_url:"https://cdn.modrinth.com/placeholder-banner.svg",alt:e.expandedGalleryItem.title?e.expandedGalleryItem.title:"gallery-image",onClick:t[9]||(t[9]=F(()=>{},["stop"]))},null,10,oe),a("div",{class:"floating",onClick:t[14]||(t[14]=F(()=>{},["stop"]))},[a("div",ue,[e.expandedGalleryItem.title?(d(),s("h2",pe,m(e.expandedGalleryItem.title),1)):o("",!0),e.expandedGalleryItem.description?(d(),s("p",me,m(e.expandedGalleryItem.description),1)):o("",!0)]),a("div",he,[a("div",ce,[a("button",{class:"close circle-button",onClick:t[10]||(t[10]=r=>e.expandedGalleryItem=null)},[n(l($),{"aria-hidden":"true"})]),a("a",{class:"open circle-button",target:"_blank",href:e.expandedGalleryItem.raw_url?e.expandedGalleryItem.raw_url:"https://cdn.modrinth.com/placeholder-banner.svg"},[n(l(z),{"aria-hidden":"true"})],8,ge),a("button",{class:"circle-button",onClick:t[11]||(t[11]=r=>e.zoomedIn=!e.zoomedIn)},[e.zoomedIn?(d(),h(l(V),{key:1,"aria-hidden":"true"})):(d(),h(l(L),{key:0,"aria-hidden":"true"}))]),i.project.gallery.length>1?(d(),s("button",{key:0,class:"previous circle-button",onClick:t[12]||(t[12]=r=>e.previousImage())},[n(l(S),{"aria-hidden":"true"})])):o("",!0),i.project.gallery.length>1?(d(),s("button",{key:1,class:"next circle-button",onClick:t[13]||(t[13]=r=>e.nextImage())},[n(l(B),{"aria-hidden":"true"})])):o("",!0)])])])])])):o("",!0),i.currentMember?(d(),s("div",ye,[n(l(T),{"max-size":5242880,accept:e.acceptFileTypes,prompt:"Upload an image","aria-label":"Upload an image",class:"iconified-button brand-button",disabled:!l(P)((C=i.currentMember)==null?void 0:C.permissions,4),onChange:e.handleFiles},{default:g(()=>[n(l(Y),{"aria-hidden":"true"})]),_:1},8,["accept","disabled","onChange"]),a("span",fe,[n(l(X),{"aria-hidden":"true"}),t[25]||(t[25]=u(" Click to choose an image or drag one onto this page "))]),n(l(J),{accept:e.acceptFileTypes,disabled:!l(P)((G=i.currentMember)==null?void 0:G.permissions,4),onChange:e.handleFiles},null,8,["accept","disabled","onChange"])])):o("",!0),a("div",Ie,[(d(!0),s(E,null,M(i.project.gallery,(r,c)=>(d(),s("div",{key:c,class:"card gallery-item"},[a("a",{class:"gallery-thumbnail",onClick:Ee=>e.expandImage(r,c)},[a("img",{src:r.url?r.url:"https://cdn.modrinth.com/placeholder-banner.svg",alt:r.title?r.title:"gallery-image"},null,8,ve)],8,be),a("div",ke,[a("div",we,[r.title?(d(),s("h2",Ce,m(r.title),1)):o("",!0),r.description?(d(),s("p",Ge,m(r.description),1)):o("",!0)])]),a("div",Fe,[a("div",je,[n(l(q),{"aria-hidden":"true","aria-label":"Date created"}),u(" "+m(e.$dayjs(r.created).format("MMMM D, YYYY")),1)]),i.currentMember?(d(),s("div",$e,[a("button",{class:"iconified-button",onClick:()=>{e.resetEdit(),e.editIndex=c,e.editTitle=r.title,e.editDescription=r.description,e.editFeatured=r.featured,e.editOrder=r.ordering,e.$refs.modal_edit_item.show()}},[n(l(H),{"aria-hidden":"true"}),t[26]||(t[26]=u(" Edit "))],8,Te),a("button",{class:"iconified-button",onClick:()=>{e.deleteIndex=c,e.$refs.modal_confirm.show()}},[n(l(Z),{"aria-hidden":"true"}),t[27]||(t[27]=u(" Remove "))],8,Pe)])):o("",!0)])]))),128))])])}}}),Be=D(Ae,[["__scopeId","data-v-fd831c4c"]]);export{Be as default};