import{e as C,r as l,j as n,i as $,k as U,l as R,m as H,n as W,o as D,p as q,q as B,u as G,d as F,t as _,v as J,w as K,x as V,y as Q,T,z as h,C as X,E as Y,F as M,S as Z,G as ee,H as te,B as se,I as ne,J as oe,K as S}from"./main-DCe66WO2.js";import{C as ie}from"./index-B11DWR9S.js";function re({title:e,label:r,placeholder:i,errorText:a,onClose:t,onSubmit:c,...x}){const{t:u}=C(),f=l.useRef(),y=()=>c(f.current.value);return n.jsxs($,{fullWidth:!0,onClose:t,...x,children:[n.jsx(U,{children:e??u("externalLinkModal.")}),n.jsx(R,{children:n.jsx("form",{onSubmit:p=>{p.preventDefault(),y()},children:n.jsx(H,{inputRef:f,label:r??u("labels.password"),placeholder:i??u("labels.enterPassword"),error:!!a,helperText:a,autoFocus:!0,fullWidth:!0,type:"pawssord",name:"password",sx:{mt:1}})})}),n.jsxs(W,{children:[n.jsx(D,{onClick:t,children:u("buttons.close")}),n.jsx(D,{variant:"contained",onClick:y,children:u("buttons.send")})]})]})}function me(){const e=q(),r=B(),i=G(),{t:a}=C(),t=F(_),c=F(J),{selectedItemId:x,setSelectedItemId:u}=K(),[f,y]=l.useState([]),[p,L]=l.useState(null),[v,b]=l.useState(""),[O,k]=l.useState(!1),g=l.useMemo(()=>{var s;switch((s=t==null?void 0:t.Link)==null?void 0:s.EntityType){case 2:return[{Name:t.Entity.Description,UserName:t.Entity.UserName??"",Date:t.Entity.Timestamp,MimeType:t.Entity.MimeType,Size:t.Entity.Size,Id:t.Entity.Id}];case 3:const o=(c==null?void 0:c.Documents)??[];return[...((c==null?void 0:c.Children)??[]).map(d=>({...d,IsFolder:!0})),...o];default:return[]}},[t,c]),E=ce(f),N=de(f),A=s=>({onDoubleClick:()=>j(s)}),j=async s=>{if(s.IsFolder&&r(`/Link/${e.uid}/${s.Id}`),!Object.values(S).find(d=>d.mimeType===s.MimeType))return;let m=p;window.location.protocol==="https:"&&await crypto.subtle.digest("SHA-1",new TextEncoder("utf-8").encode(m)).then(d=>{m=Array.prototype.map.call(new Uint8Array(d),z=>("00"+z.toString(16)).slice(-2).toUpperCase()).join("")}),window.open(`/doc.html?id=${s.Id}&uid=${t.Link.Uid}${p?"&password="+m:""}`,"_blank","",!0)},I=s=>Array.isArray(s)?s[0]:s,P=async({name:s,payload:o})=>{var m,d,w;switch(s){case h.open.name:j(I(o));break;case h.download.name:i(X({id:(m=I(o))==null?void 0:m.Id,fileName:(d=I(o))==null?void 0:d.Name,type:(w=I(o))==null?void 0:w.MimeType,uid:e.uid}));break}};return l.useEffect(()=>{(async()=>{b("");try{const o=await i(Y({uid:e.uid,password:p})).unwrap();o!=null&&o.Info||i(M({type:"error",message:a("directoryTable.link.accessError")})),k(!1)}catch(o){o.status===406?o.HasPassword&&(k(!0),p&&b(a("labels.incorrectPassword"))):i(M({type:"error",message:a("directoryTable.link.accessError")}))}})()},[i,p]),l.useEffect(()=>{var s;((s=t==null?void 0:t.Link)==null?void 0:s.EntityType)===V.Directory&&i(Q({id:(e==null?void 0:e.directoryId)??t.Entity.Id,uid:t.Link.Uid}))},[i,t,e==null?void 0:e.directoryId]),l.useEffect(()=>()=>{y([])},[g]),l.useEffect(()=>{const s=g.find(o=>o.Id===x);s&&(y([s]),u(null),document.querySelector(`[data-row-id="${s.Id}"]`).scrollIntoView({block:"end"}))},[x,g]),n.jsxs(n.Fragment,{children:[n.jsx(ie,{smartSelection:!0,columns:ae,rows:g,selection:f,contextMenuOptions:E,onSelectionChange:y,getRowProps:A,onActionClick:P,HeaderProps:{actionOptions:N,contextMenuOptions:E,heading:t&&n.jsx(T,{component:"div",sx:{fontSize:"1.125rem"},children:!t.Entity.FileId&&n.jsxs(n.Fragment,{children:[a("directoryTable.link.folder"),":"," ",n.jsx(T,{component:"span",sx:{fontWeight:"bold"},children:t.Entity.Name})]})})}}),n.jsx(re,{title:a("directoryTable.link.protected"),open:O,errorText:v,onClose:()=>k(!1),onSubmit:L})]})}const ae=[{title:"Название",locale:"name",width:500,render:({row:e,onActionClick:r})=>n.jsxs(Z,{direction:"row",alignItems:"center",spacing:1,children:[e.IsFolder?n.jsx(te,{style:{fill:"darkgrey"}}):ee(e.MimeType),n.jsx(se,{sx:{flexGrow:1,position:"relative",height:20},children:n.jsx(T,{noWrap:!0,sx:{cursor:"pointer",position:"absolute",left:0,width:"calc(100% - 8px)","&:hover":{textDecoration:"underline"}},onClick:()=>r({name:h.open.name,payload:e}),children:e.Name})}),e.IsFavorite&&n.jsx(ne,{sx:{color:"grey.600"}}),e.IsShared&&n.jsx(oe,{sx:{color:"grey.600"}})]})},{title:"Автор",locale:"author",render:({row:e})=>n.jsx(T,{sx:{color:"text.secondary"},children:e.UserName?e.UserName:e.OwnerId})},{title:"Изменен",locale:"changed",render:({row:e})=>new Date(e.IsFolder?e.Timestamp:e.Date).toLocaleString("ru-Ru")},{title:"Размер",locale:"size",render:({row:e,t:r})=>isNaN(+e.Size)?null:e.IsFolder?`${(+e.Size/1024).toFixed(2)} ${r("sizes.mb")}`:`${(+e.Size/1024/1024).toFixed(2)} ${r("sizes.mb")}`}],le=e=>[...Object.keys(S)].map(i=>S[i].mimeType).includes(e),ce=e=>{var i,a;return e.length>1?e.find(t=>t.IsFolder)?[]:[h.delete]:[...(i=e[0])!=null&&i.IsFolder||le((a=e[0])==null?void 0:a.MimeType)?[h.open]:[],h.download]},de=e=>e.length>1?[]:[h.download];export{me as default};
