import{m,v as p,I as d,a as i}from"./index-BCevi9E9.chunk.mjs";import{t as s,C,k as f,q as y,r as k,U as g}from"./preload-helper-DadE4qT2.chunk.mjs";import{j as b,l as r,s as n,v,Q as N,x as L,u as c}from"./index-Dgdobvu3.chunk.mjs";import{N as F}from"./NcTextField-CfZknuqx-CsSvGxmN.chunk.mjs";import{E as _,p as S,q as w,e as $,n as h,j as A,r as x,M}from"./icons-CFZwNZD8.chunk.mjs";import{P,a as B,f as V}from"./PhotosFiltersInput-B33sPvuK.chunk.mjs";import{S as l}from"./index-x9vhq81Z.chunk.mjs";import{N as E}from"./NcSelectUsers-RyUVUaWQ-CTrr_2Z8.chunk.mjs";import{F as O}from"./FetchCollectionContentMixin-NK9nekKH.chunk.mjs";const u="data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20id='mdi-account-group-outline'%20viewBox='0%200%2024%2024'%3e%3cpath%20d='M12,5A3.5,3.5%200%200,0%208.5,8.5A3.5,3.5%200%200,0%2012,12A3.5,3.5%200%200,0%2015.5,8.5A3.5,3.5%200%200,0%2012,5M12,7A1.5,1.5%200%200,1%2013.5,8.5A1.5,1.5%200%200,1%2012,10A1.5,1.5%200%200,1%2010.5,8.5A1.5,1.5%200%200,1%2012,7M5.5,8A2.5,2.5%200%200,0%203,10.5C3,11.44%203.53,12.25%204.29,12.68C4.65,12.88%205.06,13%205.5,13C5.94,13%206.35,12.88%206.71,12.68C7.08,12.47%207.39,12.17%207.62,11.81C6.89,10.86%206.5,9.7%206.5,8.5C6.5,8.41%206.5,8.31%206.5,8.22C6.2,8.08%205.86,8%205.5,8M18.5,8C18.14,8%2017.8,8.08%2017.5,8.22C17.5,8.31%2017.5,8.41%2017.5,8.5C17.5,9.7%2017.11,10.86%2016.38,11.81C16.5,12%2016.63,12.15%2016.78,12.3C16.94,12.45%2017.1,12.58%2017.29,12.68C17.65,12.88%2018.06,13%2018.5,13C18.94,13%2019.35,12.88%2019.71,12.68C20.47,12.25%2021,11.44%2021,10.5A2.5,2.5%200%200,0%2018.5,8M12,14C9.66,14%205,15.17%205,17.5V19H19V17.5C19,15.17%2014.34,14%2012,14M4.71,14.55C2.78,14.78%200,15.76%200,17.5V19H3V17.07C3,16.06%203.69,15.22%204.71,14.55M19.29,14.55C20.31,15.22%2021,16.06%2021,17.07V19H24V17.5C24,15.76%2021.22,14.78%2019.29,14.55M12,16C13.53,16%2015.24,16.5%2016.23,17H7.77C8.76,16.5%2010.47,16%2012,16Z'%20/%3e%3c/svg%3e",I={name:"CollaboratorsSelectionForm",components:{Close:$,ContentCopy:w,Check:S,Earth:_,NcButton:b,NcSelectUsers:E},mixins:[O],props:{albumName:{type:String,required:!0},collaborators:{type:Array,default:()=>[]},allowPublicLink:{type:Boolean,default:!0}},data(){return{availableCollaborators:{},selectedCollaboratorsKeys:[],currentSearchResults:[],loadingCollaborators:!1,randomId:Math.random().toString().substring(2,10),publicLinkCopied:!1,collaboratorTypes:l,config:{minSearchStringLength:parseInt(OC.config["sharing.minSearchStringLength"],10)||0}}},computed:{searchResults(){return this.currentSearchResults.filter(({id:t})=>t!==y()?.uid).map(t=>({key:`${t.type}:${t.id}`,id:t.id,user:t.id,displayName:t.label,type:t.type===l.User?"user":"group",iconSvg:t.type===l.Group?u:void 0})).filter(({key:t})=>!this.selectedCollaboratorsKeys.includes(t))},selectedCollaborators(){return this.selectedCollaboratorsKeys.map(t=>this.availableCollaborators[t])},selectedUsers:{get(){return this.selectedCollaborators.filter(({type:t})=>t!==l.Link).map(t=>({key:`${t.type}:${t.id}`,id:t.id,user:t.id,displayName:t.label,type:t.type===l.User?"user":"group",iconSvg:t.type===l.Group?u:void 0}))},set(t){this.selectedCollaboratorsKeys=t.map(({key:e})=>e)}},isPublicLinkSelected(){return this.selectedCollaboratorsKeys.includes(`${l.Link}`)},publicLink(){return this.availableCollaborators[l.Link]},publicLinkURL(){return`${window.location.protocol}//${window.location.host}${f(`apps/photos/public/${this.publicLink.id}`)}`},albumFileName(){return this.$store.getters.getAlbumName(this.albumName)}},watch:{collaborators(t){this.populateCollaborators(t)}},mounted(){this.populateCollaborators(this.collaborators)},methods:{async searchCollaborators(t){if(t!==void 0&&(t=t.trim(),!(t.length{switch(a.source){case"users":return{id:a.id,label:a.label,type:l.User};case"groups":return{id:a.id,label:a.label,type:l.Group};default:throw new Error(`Invalid collaborator source ${a.source}`)}}),this.availableCollaborators={...this.availableCollaborators,...this.currentSearchResults.reduce(this.indexCollaborators,{})}}catch(e){this.errorFetchingCollaborators=e,r.error(this.t("photos","Failed to fetch collaborators list."),{error:e}),n(this.t("photos","Failed to fetch collaborators list."))}finally{this.loadingCollaborators=!1}},populateCollaborators(t){const e=t.reduce(this.indexCollaborators,{});this.selectedCollaboratorsKeys=Object.keys(e),this.availableCollaborators={3:{id:"",label:this.t("photos","Public link"),type:l.Link},...this.availableCollaborators,...e}},indexCollaborators(t,e){return{...t,[`${e.type}${e.type===l.Link?"":":"}${e.type===l.Link?"":e.id}`]:e}},async createPublicLinkForAlbum(){this.selectEntity(`${l.Link}`),await this.updateAlbumCollaborators(),await this.fetchCollection(this.albumFileName,v)},async deletePublicLink(){this.unselectEntity(`${l.Link}`),this.availableCollaborators[3]={id:"",label:this.t("photos","Public link"),type:l.Link},this.publicLinkCopied=!1,await this.updateAlbumCollaborators()},async updateAlbumCollaborators(){try{await this.$store.dispatch("updateCollection",{collectionFileName:this.albumFileName,properties:{collaborators:this.selectedCollaborators}})}catch(t){r.error("[PublicAlbumContent] Error updating album",{error:t}),n(this.t("photos","Failed to update album."))}},async copyPublicLink(){await navigator.clipboard.writeText(this.publicLinkURL),this.publicLinkCopied=!0,setTimeout(()=>{this.publicLinkCopied=!1},1e4)},selectEntity(t){this.selectedCollaboratorsKeys.includes(t)||this.selectedCollaboratorsKeys.push(t)},unselectEntity(t){const e=this.selectedCollaboratorsKeys.indexOf(t);e!==-1&&this.selectedCollaboratorsKeys.splice(e,1)},t:s}};var U=function(){var t=this,e=t._self._c;return e("div",{staticClass:"manage-collaborators"},[e("h2",{staticClass:"manage-collaborators__title"},[t._v(" "+t._s(t.t("photos","Add collaborators"))+" ")]),e("form",{staticClass:"manage-collaborators__form",on:{submit:function(a){a.preventDefault()}}},[e("NcSelectUsers",{attrs:{"input-id":"sharing-search-input","input-label":t.t("photos","Add people or groups who can edit your album"),loading:t.loadingCollaborators,label:"label",filterable:!1,placeholder:t.t("photos","Search people or groups"),"clear-search-on-blur":()=>!1,multiple:!0,"append-to-body":!1,options:t.searchResults},on:{search:t.searchCollaborators,"option:selected":({key:a})=>t.selectEntity(a)},model:{value:t.selectedUsers,callback:function(a){t.selectedUsers=a},expression:"selectedUsers"}},[t._v(" "+t._s(t.t("photos","No recommendations. Start typing."))+" ")])],1),e("div",{staticClass:"actions"},[t.allowPublicLink?e("div",{staticClass:"actions__public-link"},[t.isPublicLinkSelected&&t.publicLink.id!==""?[e("NcButton",{staticClass:"manage-collaborators__public-link-button",attrs:{"aria-label":t.t("photos","Copy the public link"),title:t.publicLinkURL},on:{click:t.copyPublicLink},scopedSlots:t._u([{key:"icon",fn:function(){return[t.publicLinkCopied?e("Check"):e("ContentCopy")]},proxy:!0}],null,!1,845538853)},[t.publicLinkCopied?[t._v(" "+t._s(t.t("photos","Public link copied!"))+" ")]:[t._v(" "+t._s(t.t("photos","Copy public link"))+" ")]],2),e("NcButton",{attrs:{variant:"tertiary","aria-label":t.t("photos","Delete the public link")},on:{click:t.deletePublicLink}},[e("Close",{attrs:{slot:"icon"},slot:"icon"})],1)]:e("NcButton",{staticClass:"manage-collaborators__public-link-button",attrs:{disabled:t.isPublicLinkSelected&&t.publicLink.id==="","aria-label":t.t("photos","Create public link share")},on:{click:t.createPublicLinkForAlbum}},[e("Earth",{attrs:{slot:"icon"},slot:"icon"}),t._v(" "+t._s(t.t("photos","Share via public link"))+" ")],1)],2):t._e(),e("div",{staticClass:"actions__slot"},[t._t("default",null,{collaborators:t.selectedCollaborators})],2)])])},T=[],K=h(I,U,T,!1,null,"e411f323");const R=K.exports,z={name:"AlbumForm",components:{MapMarkerOutline:M,AccountMultiplePlusOutline:x,SendOutline:A,NcButton:b,NcLoadingIcon:L,NcTextField:F,CollaboratorsSelectionForm:R,PhotosFiltersInput:B,PhotosFiltersDisplay:P},props:{album:{type:Object,default:null},filtersValue:{type:Object,default:()=>({})},displayBackButton:{type:Boolean,default:!1}},data(){return{showCollaboratorView:!1,albumName:"",albumLocation:"",albumFilters:V.reduce((t,e)=>({...t,[e.id]:[]}),{}),loading:!1}},computed:{editMode(){return this.album!==null},sharingEnabled(){return OC.Share!==void 0},albumFileName(){return this.$store.getters.getAlbumName(this.albumName)},albumNameValidationError(){const t=this.$store.getters.albums[this.albumFileName];if(t!==void 0&&this.album!==t&&!this.loading)return s("files","This name is already in use.");try{p(this.albumName)}catch(e){if(!(e instanceof d))throw e;switch(e.reason){case i.Character:return s("files",'"{char}" is not allowed inside a filename.',{char:e.segment});case i.ReservedName:return;case i.Extension:return;default:return s("files","Invalid filename.")}}},canSubmit(){return this.albumName!==""&&this.albumNameValidationError===void 0&&!this.loading}},mounted(){this.editMode?(this.albumName=this.album?.basename,this.albumLocation=this.album?.attributes.location??"",this.albumFilters={...this.albumFilters,...structuredClone(this.album?.attributes.filters??{})}):this.albumFilters={...this.albumFilters,...structuredClone(this.filtersValue)},this.$nextTick(()=>{this.$refs.nameInput.$el.getElementsByTagName("input")[0].focus()})},methods:{submit(t=[]){this.canSubmit&&(this.editMode?this.handleUpdateAlbum():this.handleCreateAlbum(t))},async handleCreateAlbum(t=[]){try{this.loading=!0;const e=k({basename:this.albumName,filename:c+"/"+this.albumName,lastmod:"",size:0,type:"directory",etag:null,props:{displayname:this.albumName,resourcetype:{},nbItems:0,location:this.albumLocation,"last-photo":-1,date:m().format("MMMM YYYY"),collaborators:t,filters:this.filtersValue,source:g(`dav/${this.albumFileName}`)}},c);let a=await this.$store.dispatch("createCollection",{collection:e});if(a===void 0)return;const o={};this.albumLocation!==""&&(o.location=this.albumLocation),(this.albumLocation!==""||t.length!==0)&&(o.collaborators=t),Object.keys(this.filtersValue).length>0&&(o.filters=this.filtersValue),a=await this.$store.dispatch("updateCollection",{collectionFileName:this.albumFileName,properties:o}),this.$emit("done",{album:a})}finally{this.loading=!1}},async handleUpdateAlbum(){try{this.loading=!0;let t=this.album?.clone();const e=[];if(this.album!==null&&this.album.basename!==this.albumName&&(e.push("name"),t=await this.$store.dispatch("renameCollection",{collectionFileName:this.album.root+this.album.path,newBaseName:this.albumName}),t===this.album))return;this.album!==null&&this.album.attributes.location!==this.albumLocation&&(e.push("location"),t=await this.$store.dispatch("updateCollection",{collectionFileName:t.root+t.path,properties:{location:this.albumLocation}})),this.album!==null&&JSON.stringify(this.album.attributes.filters)!==JSON.stringify(this.albumFilters)&&(e.push("filters"),t=await this.$store.dispatch("updateCollection",{collectionFileName:t.root+t.path,properties:{filters:this.albumFilters}})),this.$emit("done",{album:t,changes:e})}finally{this.loading=!1}},selectFilter(t){this.albumFilters[t.filterId].push(t.value)},deselectFilter(t){const e=this.albumFilters[t.filterId].indexOf(t.value);e!==-1&&this.albumFilters[t.filterId].splice(e,1)},back(){this.$emit("back")},t:s}};var j=function(){var t=this,e=t._self._c;return t.showCollaboratorView?e("CollaboratorsSelectionForm",{attrs:{"album-name":t.albumName,"allow-public-link":!1},scopedSlots:t._u([{key:"default",fn:function({collaborators:a}){return[e("span",{staticClass:"left-buttons"},[e("NcButton",{attrs:{variant:"tertiary"},on:{click:function(o){t.showCollaboratorView=!1}}},[t._v(" "+t._s(t.t("photos","Back"))+" ")])],1),e("span",{staticClass:"right-buttons"},[e("NcButton",{attrs:{variant:"primary",disabled:!t.canSubmit},on:{click:function(o){return t.submit(a)}},scopedSlots:t._u([{key:"icon",fn:function(){return[t.loading?e("NcLoadingIcon",{attrs:{size:20}}):e("SendOutline",{attrs:{size:20}})]},proxy:!0}],null,!0)},[t._v(" "+t._s(t.editMode?t.t("photos","Save"):t.t("photos","Create album"))+" ")])],1)]}}])}):e("form",{staticClass:"album-form",on:{submit:function(a){return a.preventDefault(),t.submit()}}},[e("div",{staticClass:"form-inputs"},[e("NcTextField",{ref:"nameInput",attrs:{type:"text",name:"name","helper-text":t.albumNameValidationError,error:t.albumNameValidationError!==void 0,required:!0,label:t.t("photos","Name of the album")},model:{value:t.albumName,callback:function(a){t.albumName=typeof a=="string"?a.trim():a},expression:"albumName"}}),e("NcTextField",{attrs:{value:t.albumLocation,name:"location",type:"text",label:t.t("photos","Location of the album")},on:{"update:value":function(a){t.albumLocation=a}},scopedSlots:t._u([{key:"default",fn:function(){return[e("MapMarkerOutline",{attrs:{size:20}})]},proxy:!0}],null,!1,3863723734)})],1),e("PhotosFiltersInput",{attrs:{"selected-filters":t.albumFilters},on:{"select-filter":t.selectFilter}}),e("PhotosFiltersDisplay",{attrs:{"selected-filters":t.albumFilters},on:{"deselect-filter":t.deselectFilter}}),e("div",{staticClass:"form-buttons"},[e("span",{staticClass:"left-buttons"},[t.displayBackButton?e("NcButton",{attrs:{variant:"tertiary"},on:{click:t.back}},[t._v(" "+t._s(t.t("photos","Back"))+" ")]):t._e()],1),e("span",{staticClass:"right-buttons"},[t.sharingEnabled&&!t.editMode?e("NcButton",{attrs:{variant:"secondary",disabled:!t.canSubmit},on:{click:function(a){t.showCollaboratorView=!0}},scopedSlots:t._u([{key:"icon",fn:function(){return[e("AccountMultiplePlusOutline",{attrs:{size:20}})]},proxy:!0}],null,!1,1381680579)},[t._v(" "+t._s(t.t("photos","Add collaborators"))+" ")]):t._e(),e("NcButton",{attrs:{variant:"primary",disabled:!t.canSubmit},on:{click:function(a){return t.submit()}},scopedSlots:t._u([{key:"icon",fn:function(){return[t.loading?e("NcLoadingIcon",{attrs:{size:20}}):e("SendOutline",{attrs:{size:20}})]},proxy:!0}],null,!1,2348760288)},[t._v(" "+t._s(t.editMode?t.t("photos","Save"):t.t("photos","Create album"))+" ")])],1)])],1)},D=[],G=h(z,j,D,!1,null,"8461dd7d");const et=G.exports;export{et as A,R as C}; //# sourceMappingURL=AlbumForm-RjiiBLP7.chunk.mjs.map