import{c as y,j as e,u as T,d as x,bq as V,e as z,r as d,aJ as E,q as O,T as f,bd as P,n as g,b7 as R,a5 as B,H as _,bO as W,bi as $,bj as q,bP as A,bQ as L,bR as U,bS as J,bT as N,bU as Q,bV as X,bW as Z,S as G,bX as K,b6 as Y,B as ee,aZ as C,a_ as se}from"./main-FKuqf8qu.js";import{T as ae,a as oe,b as te,c as M,d as l,e as ne}from"./index-ChKalhXU.js";const ie=y(e.jsx("path",{d:"M5 20h14v-2H5v2zM19 9h-4V3H9v6H5l7 7 7-7z"}),"Download"),de=y(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"),be=({entity:a,onClose:r})=>{const c=T(),u=x(V),{t:i}=z(),[m,b]=d.useState([]),[o,I]=d.useState([]),[w,j]=d.useState(!1),[me,p]=d.useState(a.FileId),[H,S]=d.useState(!0),v=async()=>{j(!0);try{const s=await $(a.Id),t=await q(s.map(n=>n.OwnerId));b(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{j(!1)}},F=async(s,t)=>{await R(s,t),p(t),v(),c(B())},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 d.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(W({id:a.Id})).unwrap();p(h.FileId),S(!1),clearTimeout(s),v()}},500)};return n(),()=>clearTimeout(s)},[a.Id]),e.jsx(E,{title:i("modals.versionHistoryModal.title"),loading:w||H,onClose:r,actions:e.jsx(O,{onClick:r,children:i("buttons.close")}),children:m!=null&&m.length?e.jsx(ae,{children:e.jsxs(oe,{children:[e.jsx(te,{children:e.jsxs(M,{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(M,{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:()=>F(s.Id,s.FileId),children:e.jsx(de,{})}),e.jsx(g,{title:i("modals.versionHistoryModal.downloadVersion"),onClick:()=>D(s.Id,s.FileId),children:e.jsx(ie,{})})]})})]},t))})]})}):e.jsx(f,{children:i("modals.versionHistoryModal.noData")})})},xe=()=>{const a=T(),r=x(A),c=x(L),u=d.useCallback(o=>a(U(o.uid)),[a]),i=d.useCallback(o=>a(J(o.uid)),[a]),m=d.useCallback(o=>a(N(o)),[a]),b=d.useCallback(o=>a(Q(o)),[a]);return e.jsxs(e.Fragment,{children:[r.map(o=>e.jsx(X,{card:o,onFocus:m,onMinimize:u,onRemove:i,onDragEnd:b},o.uid)),!!c.length&&e.jsx(Z,{elevation:8,sx:{position:"fixed",zIndex:999999,bottom:20,left:20,borderRadius:1,py:.5,px:1},children:e.jsxs(G,{direction:"row",alignItems:"center",spacing:.5,children:[e.jsx(K,{sx:{fontSize:28}}),c.map(o=>e.jsxs(d.Fragment,{children:[e.jsx(Y,{flexItem:!0,orientation:"vertical"}),e.jsx(ee,{sx:{cursor:"pointer","&:hover":{color:"#ff6a6a"}},onClick:()=>u(o),children:e.jsx(f,{noWrap:!0,sx:{maxWidth:100},variant:"body2",children:o.title})})]},o.uid))]})})]})},re=({EntityIds:a,Type:r})=>C("v1/Favorites/Add",{method:"POST",body:{EntityIds:a,Type:r}}),le=({EntityIds:a,Type:r})=>C("v1/Favorites/Delete",{method:"POST",body:{EntityIds:a,Type:r}}),ce=Object.freeze(Object.defineProperty({__proto__:null,addFavorite:re,deleteFavorite:le},Symbol.toStringTag,{value:"Module"})),je=se("favofites/toggleFavorite",async({isFavorite:a,EntityIds:r,Type:c="Document"})=>{await ce[a?"deleteFavorite":"addFavorite"]({EntityIds:r,Type:c})});export{be as D,xe as M,je as t};
