import{d as m,M as p,_}from"./vue.runtime.esm-Ct3_M7aQ.chunk.mjs";import{N as S,aj as k}from"./index-BMeBqg0T.chunk.mjs";import{N as w}from"./NcDialog-CKgpZOiy-Yt0iPUKp.chunk.mjs";import{b as v,f as y}from"./index-XmYygNaN.chunk.mjs";import{n as d,t as a,l as o,i as r,a as h,b as C}from"./index-DdKmqUaK-BlSvvbCn.chunk.mjs";import{N as g}from"./NcCheckboxRadioSwitch-VeztTzpz-CXqdOpK4.chunk.mjs";import{N as b}from"./NcDateTime-DshRFtUU-DhtBMvqa.chunk.mjs";import"./preload-helper-Dh9HmuEY.chunk.mjs";import"./index-_ghYQSTa.chunk.mjs";import"./useHotKey-CXYH7Vg8.chunk.mjs";import"./NcActionButton-CuVNJJtW-78GF8FR5.chunk.mjs";import"./NcProgressBar-DegJ2JjE-FoyaEkrc.chunk.mjs";import"./index-VV9wNENq.chunk.mjs";import"./dialog-DMSB8C_5.chunk.mjs";import"./useModelMigration-EhAWvqDD-wVDp4GUR.chunk.mjs";const x={name:"ArrowRightIcon",emits:["click"],props:{title:{type:String},fillColor:{type:String,default:"currentColor"},size:{type:Number,default:24}}};var N=function(){var e=this,t=e._self._c;return t("span",e._b({staticClass:"material-design-icon arrow-right-icon",attrs:{"aria-hidden":e.title?null:"true","aria-label":e.title,role:"img"},on:{click:function(i){return e.$emit("click",i)}}},"span",e.$attrs,!1),[t("svg",{staticClass:"material-design-icon__svg",attrs:{fill:e.fillColor,width:e.size,height:e.size,viewBox:"0 0 24 24"}},[t("path",{attrs:{d:"M4,11V13H16L10.5,18.5L11.92,19.92L19.84,12L11.92,4.08L10.5,5.5L16,11H4Z"}},[e.title?t("title",[e._v(e._s(e.title))]):e._e()])])])},F=[],L=d(x,N,F,!1,null,null);const z=L.exports,A={name:"CloseIcon",emits:["click"],props:{title:{type:String},fillColor:{type:String,default:"currentColor"},size:{type:Number,default:24}}};var P=function(){var e=this,t=e._self._c;return t("span",e._b({staticClass:"material-design-icon close-icon",attrs:{"aria-hidden":e.title?null:"true","aria-label":e.title,role:"img"},on:{click:function(i){return e.$emit("click",i)}}},"span",e.$attrs,!1),[t("svg",{staticClass:"material-design-icon__svg",attrs:{fill:e.fillColor,width:e.size,height:e.size,viewBox:"0 0 24 24"}},[t("path",{attrs:{d:"M19,6.41L17.59,5L12,10.59L6.41,5L5,6.41L10.59,12L5,17.59L6.41,19L12,13.41L17.59,19L19,17.59L13.41,12L19,6.41Z"}},[e.title?t("title",[e._v(e._s(e.title))]):e._e()])])])},B=[],$=d(A,P,B,!1,null,null);const O=$.exports,I={name:"FileIcon",emits:["click"],props:{title:{type:String},fillColor:{type:String,default:"currentColor"},size:{type:Number,default:24}}};var M=function(){var e=this,t=e._self._c;return t("span",e._b({staticClass:"material-design-icon file-icon",attrs:{"aria-hidden":e.title?null:"true","aria-label":e.title,role:"img"},on:{click:function(i){return e.$emit("click",i)}}},"span",e.$attrs,!1),[t("svg",{staticClass:"material-design-icon__svg",attrs:{fill:e.fillColor,width:e.size,height:e.size,viewBox:"0 0 24 24"}},[t("path",{attrs:{d:"M13,9V3.5L18.5,9M6,2C4.89,2 4,2.89 4,4V20A2,2 0 0,0 6,22H18A2,2 0 0,0 20,20V8L14,2H6Z"}},[e.title?t("title",[e._v(e._s(e.title))]):e._e()])])])},U=[],E=d(I,M,U,!1,null,null);const R=E.exports,V={name:"FolderIcon",emits:["click"],props:{title:{type:String},fillColor:{type:String,default:"currentColor"},size:{type:Number,default:24}}};var q=function(){var e=this,t=e._self._c;return t("span",e._b({staticClass:"material-design-icon folder-icon",attrs:{"aria-hidden":e.title?null:"true","aria-label":e.title,role:"img"},on:{click:function(i){return e.$emit("click",i)}}},"span",e.$attrs,!1),[t("svg",{staticClass:"material-design-icon__svg",attrs:{fill:e.fillColor,width:e.size,height:e.size,viewBox:"0 0 24 24"}},[t("path",{attrs:{d:"M10,4H4C2.89,4 2,4.89 2,6V18A2,2 0 0,0 4,20H20A2,2 0 0,0 22,18V8C22,6.89 21.1,6 20,6H12L10,4Z"}},[e.title?t("title",[e._v(e._s(e.title))]):e._e()])])])},D=[],H=d(V,q,D,!1,null,null);const T=H.exports,f=64,j=m({name:"NodesPicker",components:{FileSvg:R,FolderSvg:T,NcCheckboxRadioSwitch:g,NcDateTime:b},props:{incoming:{type:[File,Object],required:!0},existing:{type:Object,required:!0},newSelected:{type:Array,required:!0},oldSelected:{type:Array,required:!0}},data(){return{asyncPreview:null,incomingFile:null}},computed:{isEnoughSelected(){return this.isChecked(this.incoming,this.newSelected)||this.isChecked(this.existing,this.oldSelected)},incomingPreview(){return this.incomingFile?this.previewUrl(this.incomingFile)??this.asyncPreview:null},incomingLastModified(){return this.incomingFile?this.lastModified(this.incomingFile):null},incomingSize(){return this.incomingFile?this.size(this.incomingFile):a("Unknown size")},existingPreview(){return this.previewUrl(this.existing)},existingLastModified(){return this.lastModified(this.existing)}},watch:{incoming:{immediate:!0,async handler(){this.incoming instanceof File?this.incomingFile=this.incoming:C(this.incoming)?this.incomingFile=await new Promise((e,t)=>this.incoming.file(e,t)):this.incomingFile=null}}},methods:{lastModified(e){return(e instanceof File?new Date(e.lastModified):e.mtime)??null},size(e){return e.size?y(e.size,!0):a("Unknown size")},previewUrl(e){if(e instanceof File)return this.previewImage(e).then(t=>{this.asyncPreview=t}),null;if(e.type===p.Folder)return null;try{const t=e.attributes.previewUrl||_("/core/preview?fileId={fileid}",{fileid:e.fileid}),i=new URL(window.location.origin+t);i.searchParams.set("x",f.toString()),i.searchParams.set("y",f.toString()),i.searchParams.set("mimeFallback","true");const l=e.attributes?.etag||"";return i.searchParams.set("v",l.slice(0,6)),i.href}catch{return null}},isFolder(e){return r(e)?e.isDirectory:(e=e,e.type===p.Folder||e.type==="httpd/unix-directory")},isChecked(e,t){return t.includes(e)},onUpdateIncomingChecked(e){e?this.$emit("update:newSelected",[this.incoming,...this.newSelected]):this.$emit("update:newSelected",this.newSelected.filter(t=>t!==this.incoming))},onUpdateExistingChecked(e){e?this.$emit("update:oldSelected",[this.existing,...this.oldSelected]):this.$emit("update:oldSelected",this.oldSelected.filter(t=>t!==this.existing))},async previewImage(e){return new Promise(t=>{if(e instanceof File&&e.type.startsWith("image/")){const i=new FileReader;i.onload=async l=>{const s=l?.target?.result;if(s instanceof ArrayBuffer){const n=new Blob([s],{type:e.type}),c=URL.createObjectURL(n);t(c);return}t(null)},i.readAsArrayBuffer(e)}else t(null)})},t:a}});var W=function(){var e=this,t=e._self._c;return e._self._setupProxy,t("fieldset",{staticClass:"node-picker__wrapper",attrs:{"data-cy-conflict-picker-fieldset":e.existing.basename}},[t("legend",[e._v(e._s(e.existing.basename))]),t("NcCheckboxRadioSwitch",{attrs:{checked:e.isChecked(e.incoming,e.newSelected),required:!e.isEnoughSelected,"data-cy-conflict-picker-input-incoming":e.existing.basename},on:{"update:checked":e.onUpdateIncomingChecked}},[t("span",{staticClass:"node-picker node-picker--incoming"},[e.incomingPreview?t("img",{staticClass:"node-picker__preview",attrs:{src:e.incomingPreview,alt:e.t("Preview image"),loading:"lazy"}}):[e.isFolder(e.incoming)?t("FolderSvg",{staticClass:"node-picker__icon",attrs:{size:48}}):t("FileSvg",{staticClass:"node-picker__icon",attrs:{size:48}})],t("span",{staticClass:"node-picker__desc"},[t("span",{staticClass:"node-picker__name"},[e._v(e._s(e.t("New version")))]),e.incomingLastModified?t("NcDateTime",{staticClass:"node-picker__mtime",attrs:{timestamp:e.incomingLastModified,"relative-time":!1,format:{timeStyle:"short",dateStyle:"medium"}}}):t("span",{staticClass:"node-picker__mtime"},[e._v(" "+e._s(e.t("Last modified date unknown"))+" ")]),t("span",{staticClass:"node-picker__size"},[e._v(e._s(e.incomingSize))])],1)],2)]),t("NcCheckboxRadioSwitch",{attrs:{checked:e.isChecked(e.existing,e.oldSelected),required:!e.isEnoughSelected,"data-cy-conflict-picker-input-existing":e.existing.basename},on:{"update:checked":e.onUpdateExistingChecked}},[t("span",{staticClass:"node-picker node-picker--existing"},[e.existingPreview?t("img",{staticClass:"node-picker__preview",attrs:{src:e.existingPreview,alt:e.t("Preview image"),loading:"lazy"}}):[e.isFolder(e.existing)?t("FolderSvg",{staticClass:"node-picker__icon",attrs:{size:48}}):t("FileSvg",{staticClass:"node-picker__icon",attrs:{size:48}})],t("span",{staticClass:"node-picker__desc"},[t("span",{staticClass:"node-picker__name"},[e._v(e._s(e.t("Existing version")))]),e.existingLastModified?t("NcDateTime",{staticClass:"node-picker__mtime",attrs:{timestamp:e.existingLastModified,"relative-time":!1,format:{timeStyle:"short",dateStyle:"medium"}}}):t("span",{staticClass:"node-picker__mtime"},[e._v(" "+e._s(e.t("Last modified date unknown"))+" ")]),t("span",{staticClass:"node-picker__size"},[e._v(e._s(e.size(e.existing)))])],1)],2)])],1)},Z=[],Y=d(j,W,Z,!1,null,"a1eb0469");const G=Y.exports,J=m({name:"ConflictPicker",components:{ArrowRight:z,Close:O,NcButton:S,NcCheckboxRadioSwitch:g,NcDialog:w,NodesPicker:G},props:{dirname:{type:String,default:""},content:{type:Array,required:!0},conflicts:{type:Array,required:!0},recursiveUpload:{type:Boolean,default:!1}},emits:["cancel","submit"],setup(){return{blockedTitle:a("You need to select at least one version of each file to continue.")}},data(){return{files:[],opened:!0,newSelected:[],oldSelected:[]}},computed:{name(){return this?.dirname?.trim?.()!==""?h("{count} file conflict in {dirname}","{count} file conflicts in {dirname}",this.conflicts.length,{count:this.conflicts.length,dirname:this.dirname}):h("{count} file conflict","{count} files conflict",this.conflicts.length,{count:this.conflicts.length})},skipButtonLabel(){return this.conflicts.length===1?a("Skip this file"):h("Skip {count} file","Skip {count} files",this.conflicts.length,{count:this.conflicts.length})},selectAllNewBind(){const e=this.isNoneNewSelected||this.isSomeNewSelected?this.t("Select all"):this.t("Unselect all");return{"aria-label":e,checked:this.isAllNewSelected,indeterminate:this.isSomeNewSelected,title:e}},isAllNewSelected(){return this.newSelected.length===this.conflicts.length},isNoneNewSelected(){return this.newSelected.length===0},isSomeNewSelected(){return!this.isAllNewSelected&&!this.isNoneNewSelected},selectAllOldBind(){const e=this.isNoneOldSelected||this.isSomeOldSelected?this.t("Select all"):this.t("Unselect all");return{"aria-label":e,checked:this.isAllOldSelected,indeterminate:this.isSomeOldSelected,title:e}},isAllOldSelected(){return this.oldSelected.length===this.files.length},isNoneOldSelected(){return this.oldSelected.length===0},isSomeOldSelected(){return!this.isAllOldSelected&&!this.isNoneOldSelected},isEnoughSelected(){return this.isAllOldSelected||this.isAllNewSelected?!0:this.$refs?.nodesPicker?.every?.(e=>e.isEnoughSelected)}},mounted(){if(this.files=this.conflicts.map(e=>{const t=e instanceof File||r(e)?e.name:e.basename;return this.content.find(i=>i.basename===t)}).filter(Boolean),this.conflicts.length===0||this.files.length===0){const e=new Error("ConflictPicker: files and conflicts must not be empty");throw this.onCancel(e),e}if(this.conflicts.length!==this.files.length){const e=new Error("ConflictPicker: files and conflicts must have the same length. Make sure you filter out non conflicting files from the conflicts array.");throw this.onCancel(e),e}o.debug("ConflictPicker initialised",{files:this.files,conflicts:this.conflicts,content:this.content})},methods:{onCancel(e){this.opened=!1,this.$emit("cancel",e)},onSkip(){o.debug("Conflict skipped. Ignoring all conflicting files"),this.opened=!1,this.$emit("submit",{selected:[],renamed:[]})},onSubmit(){if(!this.isEnoughSelected){this.scrollValidityInputIntoView(),this.$refs.form.reportValidity(),k(this.blockedTitle);return}const e=this.oldSelected.map(n=>n.basename),t=this.content.map(n=>n.basename),i=[],l=this.newSelected.filter(n=>{const c=n instanceof File||r(n)?n.name:n.basename;return e.includes(c)});l.length>0&&l.forEach(n=>{const c=n instanceof File||r(n)?n.name:n.basename,u=v(c,t);if(n instanceof File||r(n)){Object.defineProperty(n,"name",{value:u}),i.push(n);return}n.rename(u),i.push(n)});const s=this.newSelected.filter(n=>{const c=n instanceof File||r(n)?n.name:n.basename;return!e.includes(c)&&!l.includes(n)});o.debug("Conflict resolved",{selected:s,renamed:i}),this.opened=!1,this.$emit("submit",{selected:s,renamed:i})},scrollValidityInputIntoView(){const e='.checkbox-radio-switch input[type="checkbox"]';Array.from(this.$el.querySelectorAll(e)).forEach(i=>i?.setCustomValidity?.(""));const t=this.$el.querySelector(e+":invalid");t&&(t.setCustomValidity(this.blockedTitle),t.scrollIntoView({behavior:"instant",block:"center"}))},onSelectAllNew(e){e?(o.debug("Selected all new files"),this.newSelected=this.conflicts):(o.debug("Cleared new selection"),this.newSelected=[])},onSelectAllOld(e){e?(o.debug("Selected all existing files"),this.oldSelected=this.files):(o.debug("Cleared old selection"),this.oldSelected=[])},t:a}});var K=function(){var e=this,t=e._self._c;return e._self._setupProxy,t("NcDialog",{staticClass:"conflict-picker",attrs:{"can-close":"","data-cy-conflict-picker":"","close-on-click-outside":!1,show:e.opened,name:e.name,size:"large"},on:{closing:e.onCancel},scopedSlots:e._u([{key:"actions",fn:function(){return[t("NcButton",{attrs:{"aria-label":e.t("Cancel"),title:e.t("Cancel the entire operation"),"data-cy-conflict-picker-cancel":"",type:"tertiary"},on:{click:e.onCancel},scopedSlots:e._u([{key:"icon",fn:function(){return[t("Close",{attrs:{size:20}})]},proxy:!0}])},[e._v(" "+e._s(e.t("Cancel"))+" ")]),t("span",{staticClass:"dialog__actions-separator"}),t("NcButton",{attrs:{"aria-label":e.skipButtonLabel,"data-cy-conflict-picker-skip":""},on:{click:e.onSkip},scopedSlots:e._u([{key:"icon",fn:function(){return[t("Close",{attrs:{size:20}})]},proxy:!0}])},[e._v(" "+e._s(e.skipButtonLabel)+" ")]),t("NcButton",{class:{"button-vue--disabled":!e.isEnoughSelected},attrs:{"aria-label":e.t("Continue"),title:e.isEnoughSelected?"":e.blockedTitle,"data-cy-conflict-picker-submit":"","native-type":"submit",type:"primary"},on:{click:function(i){return i.stopPropagation(),i.preventDefault(),e.onSubmit.apply(null,arguments)}},scopedSlots:e._u([{key:"icon",fn:function(){return[t("ArrowRight",{attrs:{size:20}})]},proxy:!0}])},[e._v(" "+e._s(e.t("Continue"))+" ")])]},proxy:!0}])},[t("div",{staticClass:"conflict-picker__header"},[t("p",{staticClass:"conflict-picker__description",attrs:{id:"conflict-picker-description"}},[e._v(" "+e._s(e.t("Which files do you want to keep?"))),t("br"),e._v(" "+e._s(e.t("If you select both versions, the incoming file will have a number added to its name."))),t("br"),e.recursiveUpload?[e._v(" "+e._s(e.t("When an incoming folder is selected, the content is written into the existing folder and a recursive conflict resolution is performed."))+" ")]:[e._v(" "+e._s(e.t("When an incoming folder is selected, any conflicting files within it will also be overwritten."))+" ")]],2)]),t("form",{ref:"form",staticClass:"conflict-picker__form",attrs:{"aria-labelledby":"conflict-picker-description","data-cy-conflict-picker-form":""},on:{submit:function(i){return i.preventDefault(),i.stopPropagation(),e.onSubmit.apply(null,arguments)}}},[t("fieldset",{staticClass:"conflict-picker__all",attrs:{"data-cy-conflict-picker-fieldset":"all"}},[t("legend",{staticClass:"hidden-visually"},[e._v(" "+e._s(e.t("Select all checkboxes"))+" ")]),t("NcCheckboxRadioSwitch",e._b({attrs:{"data-cy-conflict-picker-input-incoming":"all"},on:{"update:checked":e.onSelectAllNew}},"NcCheckboxRadioSwitch",e.selectAllNewBind,!1),[e._v(" "+e._s(e.t("Select all new files"))+" ")]),t("NcCheckboxRadioSwitch",e._b({attrs:{"data-cy-conflict-picker-input-existing":"all"},on:{"update:checked":e.onSelectAllOld}},"NcCheckboxRadioSwitch",e.selectAllOldBind,!1),[e._v(" "+e._s(e.t("Select all existing files"))+" ")])],1),e._l(e.files,function(i,l){return t("NodesPicker",{key:i.fileid,ref:"nodesPicker",refInFor:!0,attrs:{incoming:e.conflicts[l],existing:e.files[l],"new-selected":e.newSelected,"old-selected":e.oldSelected},on:{"update:newSelected":function(s){e.newSelected=s},"update:new-selected":function(s){e.newSelected=s},"update:oldSelected":function(s){e.oldSelected=s},"update:old-selected":function(s){e.oldSelected=s}}})})],2)])},Q=[],X=d(J,K,Q,!1,null,"9464bcea");const me=X.exports;export{me as default}; //# sourceMappingURL=ConflictPicker-BvM7ZujP-B5ksUA-v.chunk.mjs.map