import{c as y,j as e,u as C,d as x,bl as z,e as E,r as d,aC as O,o as V,T,b8 as P,aH as g,b1 as R,a0 as B,F as _,bJ as L,bd as $,be as A,bK as N,bL as U,bM as W,bN as J,bO as q,bP as K,bQ as Q,bR as G,S as X,bS as Y,b0 as Z,B as ee,aT as f,aU as se}from"./main-vLEt7Bxq.js";import{T as ae,a as oe,b as te,c as M,d as l,e as ne}from"./index-CKXP_gdg.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=C(),u=x(z),{t:i}=E(),[m,b]=d.useState([]),[o,I]=d.useState([]),[w,j]=d.useState(!1),[me,p]=d.useState(a.FileId),[F,H]=d.useState(!0),v=async()=>{j(!0);try{const s=await $(a.Id),t=await A(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)}},S=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(L({id:a.Id})).unwrap();p(h.FileId),H(!1),clearTimeout(s),v()}},500)};return n(),()=>clearTimeout(s)},[a.Id]),e.jsx(O,{title:i("modals.versionHistoryModal.title"),loading:w||F,onClose:r,actions:e.jsx(V,{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:()=>S(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(T,{children:i("modals.versionHistoryModal.noData")})})},xe=()=>{const a=C(),r=x(N),c=x(U),u=d.useCallback(o=>a(W(o.uid)),[a]),i=d.useCallback(o=>a(J(o.uid)),[a]),m=d.useCallback(o=>a(q(o)),[a]),b=d.useCallback(o=>a(K(o)),[a]);return e.jsxs(e.Fragment,{children:[r.map(o=>e.jsx(Q,{card:o,onFocus:m,onMinimize:u,onRemove:i,onDragEnd:b},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(X,{direction:"row",alignItems:"center",spacing:.5,children:[e.jsx(Y,{sx:{fontSize:28}}),c.map(o=>e.jsxs(d.Fragment,{children:[e.jsx(Z,{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))]})})]})},re=({EntityIds:a,Type:r})=>f("v1/Favorites/Add",{method:"POST",body:{EntityIds:a,Type:r}}),le=({EntityIds:a,Type:r})=>f("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};
