import{c as M,j as e,u as C,d as b,b1 as z,e as E,r,aC as V,o as O,T,bo as P,aH as g,bp as B,$ as R,F as _,bq as $,br as A,aY as L,bs as U,bt as W,bu as q,bv as N,bw as J,bx as Y,by as Z,bz as G,S as K,bA as Q,aZ as X,B as ee,aT as f,aU as se}from"./main-DCe66WO2.js";import{T as ae,a as oe,b as te,c as y,d as l,e as ne}from"./index-B11DWR9S.js";const ie=M(e.jsx("path",{d:"M5 20h14v-2H5v2zM19 9h-4V3H9v6H5l7 7 7-7z"}),"Download"),re=M(e.jsx("path",{d:"M13 3c-4.97 0-9 4.03-9 9H1l3.89 3.89.07.14L9 12H6c0-3.87 3.13-7 7-7s7 3.13 7 7-3.13 7-7 7c-1.93 0-3.68-.79-4.94-2.06l-1.42 1.42C8.27 19.99 10.51 21 13 21c4.97 0 9-4.03 9-9s-4.03-9-9-9zm-1 5v5l4.28 2.54.72-1.21-3.5-2.08V8H12z"}),"Restore"),xe=({entity:a,onClose:d})=>{const c=C(),u=b(z),{t:i}=E(),[m,x]=r.useState([]),[o,I]=r.useState([]),[w,p]=r.useState(!1),[me,j]=r.useState(a.FileId),[F,H]=r.useState(!0),v=async()=>{p(!0);try{const s=await A(a.Id),t=await L(s.map(n=>n.OwnerId));x(s==null?void 0:s.map(n=>{var h;return{...n,Email:((h=t==null?void 0:t.find(k=>k.Id===n.OwnerId))==null?void 0:h.Email)||""}})),I(Object.fromEntries([...new Set(t.map(n=>[n.Id,`${n.FirstName} ${n.Surname}`]))]))}finally{p(!1)}},S=async(s,t)=>{await B(s,t),j(t),v(),c(R())},D=(s,t)=>{const n=window.open(`/api/v1/Documents/Download?id=${s}&FileId=${t}&download=true`,"_blank");n.window.onload=()=>{n.window.document.contentType==="application/json"&&(JSON.parse(n.window.document.body.innerText).ErrorCode===410&&c(_({type:"error",message:i("modals.versionHistoryModal.notification.documentMissing",{fileId:t})})),n.window.close())}};return r.useEffect(()=>{let s;const t=()=>(a==null?void 0:a.closedTimestamp)&&Date.now()-a.closedTimestamp<12e3,n=()=>{s=setTimeout(async()=>{if(t())n();else{const h=await c($({id:a.Id})).unwrap();j(h.FileId),H(!1),clearTimeout(s),v()}},500)};return n(),()=>clearTimeout(s)},[a.Id]),e.jsx(V,{title:i("modals.versionHistoryModal.title"),loading:w||F,onClose:d,actions:e.jsx(O,{onClick:d,children:i("buttons.close")}),children:m!=null&&m.length?e.jsx(ae,{children:e.jsxs(oe,{children:[e.jsx(te,{children:e.jsxs(y,{children:[e.jsx(l,{children:i("modals.versionHistoryModal.table.header.number")}),e.jsx(l,{children:i("modals.versionHistoryModal.table.header.date")}),e.jsx(l,{children:i("modals.versionHistoryModal.table.header.user")}),e.jsx(l,{children:i("modals.versionHistoryModal.table.header.version")}),e.jsx(l,{children:i("modals.versionHistoryModal.table.header.action")})]})}),e.jsx(ne,{children:m.map((s,t)=>e.jsxs(y,{sx:t!==m.length-1?null:{"& td":{borderBottom:"none"}},children:[e.jsx(l,{children:t+1}),e.jsx(l,{children:new Date(s.Date).toLocaleString("ru")}),e.jsx(l,{children:e.jsx(P,{email:s==null?void 0:s.Email,hoverCardProps:{zIndex:2e3},children:e.jsx("span",{children:s.OwnerId===u.Id?i("modals.versionHistoryModal.table.mySelf"):o[s.OwnerId]})})}),e.jsx(l,{children:s.FileId}),e.jsx(l,{children:s.IsCurrent?e.jsx("span",{children:i("modals.versionHistoryModal.table.currentVersion")}):e.jsxs(e.Fragment,{children:[e.jsx(g,{title:i("modals.versionHistoryModal.rollBackTitle"),onClick:()=>S(s.Id,s.FileId),children:e.jsx(re,{})}),e.jsx(g,{title:i("modals.versionHistoryModal.downloadVersion"),onClick:()=>D(s.Id,s.FileId),children:e.jsx(ie,{})})]})})]},t))})]})}):e.jsx(T,{children:i("modals.versionHistoryModal.noData")})})},be=()=>{const a=C(),d=b(U),c=b(W),u=r.useCallback(o=>a(q(o.uid)),[a]),i=r.useCallback(o=>a(N(o.uid)),[a]),m=r.useCallback(o=>a(J(o)),[a]),x=r.useCallback(o=>a(Y(o)),[a]);return e.jsxs(e.Fragment,{children:[d.map(o=>e.jsx(Z,{card:o,onFocus:m,onMinimize:u,onRemove:i,onDragEnd:x},o.uid)),!!c.length&&e.jsx(G,{elevation:8,sx:{position:"fixed",zIndex:999999,bottom:20,left:20,borderRadius:1,py:.5,px:1},children:e.jsxs(K,{direction:"row",alignItems:"center",spacing:.5,children:[e.jsx(Q,{sx:{fontSize:28}}),c.map(o=>e.jsxs(r.Fragment,{children:[e.jsx(X,{flexItem:!0,orientation:"vertical"}),e.jsx(ee,{sx:{cursor:"pointer","&:hover":{color:"#ff6a6a"}},onClick:()=>u(o),children:e.jsx(T,{noWrap:!0,sx:{maxWidth:100},variant:"body2",children:o.title})})]},o.uid))]})})]})},de=({EntityIds:a,Type:d})=>f("v1/Favorites/Add",{method:"POST",body:{EntityIds:a,Type:d}}),le=({EntityIds:a,Type:d})=>f("v1/Favorites/Delete",{method:"POST",body:{EntityIds:a,Type:d}}),ce=Object.freeze(Object.defineProperty({__proto__:null,addFavorite:de,deleteFavorite:le},Symbol.toStringTag,{value:"Module"})),pe=se("favofites/toggleFavorite",async({isFavorite:a,EntityIds:d,Type:c="Document"})=>{await ce[a?"deleteFavorite":"addFavorite"]({EntityIds:d,Type:c})});export{xe as D,be as M,pe as t};
