import{C as c,V as _,g as v,a as x,b as V}from"./index-Dpj4ddZx.chunk.mjs";import{a as o,g as H,e as p}from"./index-DqIuD5e7.chunk.mjs";import{c as u,i as A}from"./index-DaEUtA7I.chunk.mjs";import{a as b,d as C,g as N}from"./index-C1xmmKTZ-Dc_rYBq-.chunk.mjs";import{P as E}from"./folder-29HuacU_-CQFyGatl.chunk.mjs";import{d as S,e as $,l as I}from"./index-BgmsSgl5.chunk.mjs";import{t as n,g as y,a as f}from"./translation-DoG5ZELJ-DFt3Gk_P.chunk.mjs";import{g as D,i as L}from"./createElementId-DhjFt1I9-Cdw8hg_s.chunk.mjs";import{g as M,a as T,b as k,r as F,d as B}from"./dav-D0I04_zO.chunk.mjs";import{f as U}from"./index-CClfw3S6.chunk.mjs";import{h as P}from"./runtime-dom.esm-bundler-CnPoR0UW.chunk.mjs";import{N as O}from"./NcUserBubble-BE6yD-R0-DrckumvI.chunk.mjs";import"./index-sH3U_332.chunk.mjs";import"./NcNoteCard-CWiO3Dse-DuB9YE1o.chunk.mjs";import"./logger-D3RVzcfQ-v2acROFG.chunk.mjs";import"./index-BSiFSirb.chunk.mjs";import"./mdi-DEKCY6bD.chunk.mjs";import"./NcAvatar-ruClKRzS-Cqk13H0d.chunk.mjs";import"./colors-BfjxNgsx-gOcC3EUE.chunk.mjs";import"./NcUserStatusIcon-JWiuiAXe-B0urAc7r.chunk.mjs";import"./PencilOutline-DC4h4i4m.chunk.mjs";import"./NcActionRouter-CvDVCQiQ-D1TdSJsa.chunk.mjs";const R='<svg xmlns="http://www.w3.org/2000/svg" id="mdi-history" viewBox="0 0 24 24"><path d="M13.5,8H12V13L16.28,15.54L17,14.33L13.5,12.25V8M13,3A9,9 0 0,0 4,12H1L4.96,16.03L9,12H6A7,7 0 0,1 13,5A7,7 0 0,1 20,12A7,7 0 0,1 13,19C11.07,19 9.32,18.21 8.06,16.94L6.64,18.36C8.27,20 10.5,21 13,21A9,9 0 0,0 22,12A9,9 0 0,0 13,3" /></svg>',q='<svg xmlns="http://www.w3.org/2000/svg" id="mdi-trash-can-outline" viewBox="0 0 24 24"><path d="M9,3V4H4V6H5V19A2,2 0 0,0 7,21H17A2,2 0 0,0 19,19V6H20V4H15V3H9M7,6H17V19H7V6M9,8V17H11V8H9M13,8V17H15V8H13Z" /></svg>',g=`/trashbin/${o()?.uid}/trash`,z=M(),K=`<?xml version="1.0"?>
<d:propfind ${T()}>
	<d:prop>
		<nc:trashbin-deletion-time />
		<nc:trashbin-original-location />
		<nc:trashbin-title />
		<nc:trashbin-deleted-by-id />
		<nc:trashbin-deleted-by-display-name />
		${k()}
	</d:prop>
</d:propfind>`;function Y(i){const e=F(i,g);return e.attributes.previewUrl=D("/apps/files_trashbin/preview?fileId={fileid}&x=32&y=32",{fileid:e.fileid}),e}async function Z(i="/"){const e=(await z.getDirectoryContents(`${g}${i}`,{details:!0,data:K,includeSelf:!0})).data.map(Y),[t]=e.splice(e.findIndex(r=>r.path===i),1);return{folder:t,contents:e}}const j=new c({id:"files_trashbin--original-location",title:n("files_trashbin","Original location"),render(i){const e=l(i),t=document.createElement("span");return t.title=e,t.textContent=e,t},sort(i,e){const t=l(i),r=l(e);return t.localeCompare(r,[y(),f()],{numeric:!0,usage:"sort"})}}),G=new c({id:"files_trashbin--deleted-by",title:n("files_trashbin","Deleted by"),render(i){const{userId:e,displayName:t,label:r}=d(i);if(r){const a=document.createElement("span");return a.textContent=r,a}const s=document.createElement("div");return P(O,{size:32,user:e??void 0,displayName:t??e}).mount(s),s},sort(i,e){const t=d(i),r=t.label??t.displayName??t.userId,s=d(e),a=s.label??s.displayName??s.userId;return r.localeCompare(a,[y(),f()],{numeric:!0,usage:"sort"})}}),J=new c({id:"files_trashbin--deleted",title:n("files_trashbin","Deleted"),render(i){const e=i.attributes?.["trashbin-deletion-time"]||(i?.mtime?.getTime()??0)/1e3,t=document.createElement("span");if(e){const r=Intl.DateTimeFormat([f()],{dateStyle:"long",timeStyle:"short"}),s=new Date(e*1e3);return t.title=r.format(s),t.textContent=U(s,{ignoreSeconds:n("files","few seconds ago")}),t}return t.textContent=n("files_trashbin","A long time ago"),t},sort(i,e){const t=i.attributes?.["trashbin-deletion-time"]||(i?.mtime?.getTime()??0)/1e3;return(e.attributes?.["trashbin-deletion-time"]||(e?.mtime?.getTime()??0)/1e3)-t}});function l(i){const e=m(i.attributes?.["trashbin-original-location"]);if(!e)return n("files_trashbin","Unknown");const t=S(e);return t==="/"||t==="."?n("files_trashbin","All files"):t.replace(/^\//,"")}function d(i){const e=m(i.attributes?.["trashbin-deleted-by-id"]),t=m(i.attributes?.["trashbin-deleted-by-display-name"]);let r;const s=o()?.uid;return e===s&&(r=n("files_trashbin","You")),!e&&!t&&(r=n("files_trashbin","Unknown")),{userId:e,displayName:t,label:r}}function m(i){return i?String(i):null}const h="trashbin",Q=new _({id:h,name:n("files_trashbin","Deleted files"),caption:n("files_trashbin","List of files that have been deleted."),emptyTitle:n("files_trashbin","No deleted files"),emptyCaption:n("files_trashbin","Files and folders you have deleted will show up here"),icon:q,order:50,sticky:!0,defaultSortKey:"deleted",columns:[j,G,J],getContents:Z}),w=H().setApp("files_trashbin").detectUser().build(),W={id:"restore",displayName(){return n("files_trashbin","Restore")},iconSvgInline:()=>R,enabled({nodes:i,view:e}){return e.id!==h?!1:i.length>0&&i.map(t=>t.permissions).every(t=>!!(t&E.READ))},async exec({nodes:i}){const e=i[0];try{const t=L($(`dav/trashbin/${o().uid}/restore/${e.basename}`));return await u.request({method:"MOVE",url:e.encodedSource,headers:{destination:t}}),p("files:node:deleted",e),!0}catch(t){return A(t)&&t.response?.status===507&&b(n("files_trashbin","Not enough free space to restore the file/folder")),w.error("Failed to restore node",{error:t,node:e}),!1}},async execBatch({nodes:i,view:e,folder:t,contents:r}){return Promise.all(i.map(s=>this.exec({nodes:[s],view:e,folder:t,contents:r})))},order:1,inline:()=>!0};async function X(){try{return await u.delete(`${B}/trashbin/${o().uid}/trash`),C(n("files_trashbin","All files have been permanently deleted")),!0}catch(i){return b(n("files_trashbin","Failed to empty deleted files")),w.error("Failed to empty deleted files",{error:i}),!1}}const ee={id:"empty-trash",displayName:()=>n("files_trashbin","Empty deleted files"),order:0,enabled({view:i,folder:e,contents:t}){return i.id!==h||!I("files_trashbin","config").allow_delete?!1:t.length>0&&e.path==="/"},async exec({contents:i}){return await new Promise(e=>{N(n("files_trashbin","Confirm permanent deletion")).setSeverity("warning").setText(n("files_trashbin","Are you sure you want to permanently delete all files and folders in the trash? This cannot be undone.")).setButtons([{label:n("files_trashbin","Cancel"),variant:"secondary",callback:()=>e(!1)},{label:n("files_trashbin","Empty deleted files"),variant:"error",callback:()=>e(!0)}]).build().show().then(()=>{e(!1)})})===!0&&await X()&&i.forEach(e=>p("files:node:deleted",e)),null}},te=v();te.register(Q),x(ee),V(W);
//# sourceMappingURL=files_trashbin-init.mjs.map
