import{j as s,S as n,h as l,H as h,s as b}from"./vendor-ClLR6ncd.js";import{d as v}from"./PlayArrow-C5BebwRO.js";import{d as L}from"./Stop-D8ZTRatE.js";import{b as I,I as M,h as d,J as R,L as D,i as m,f as p,aY as _}from"./index-OtVJl4GC.js";import"./lodash-ZyeDnt0e.js";import{E as w}from"./Messages-BRmQDxrZ.js";import{a as E}from"./ui-DKQGUVKw.js";import{c as P}from"./ui-DEn7LX9m.js";import{L as O}from"./Link-BLwKPJFF.js";import"./AccordionDetails-Bqc4B-Ut.js";import"./WarningMessage-4TK5GdCH.js";import"./Warning-DsmyDRzF.js";import"./Box-Co2WcNPC.js";function Q({disabled:u,changeStatusMutation:i,isStarted:r,style:t}){return s.jsx(h,{style:t,disabled:u||i.isLoading,color:r===!0?"error":void 0,variant:"contained",startIcon:r?s.jsx(L,{}):s.jsx(v,{}),onClick:i.mutate,children:r?"Close session":"New session"})}function A(){var k;const u=I(),{away:i,to:r}=M(),t=d(async(a,o)=>{const C=await m({url:p(o,"session"),method:"post"});r(_(C))}),c=d(async(a,o)=>{await m({url:p(o,"session/close"),method:"post"}),i()}),f=d((a,o)=>m({url:p(o,"commit"),method:"post"}),{invalidateRepoKeysOnSuccess:[]}),S=d((a,o)=>m({url:p(o,"rollback"),method:"post"}),{invalidateRepoKeysOnSuccess:[]}),e=R(),x=(k=e.data)==null?void 0:k.isSessionOpened,j=[e,c,t,f,S].some(a=>a.isLoading),g=e.isSuccess&&e.data.writable&&e.data.autoCommit===!1,y=s.jsx(O,{component:b,to:"/utils/sessions",children:"Sessions page"});return s.jsxs(n,{spacing:2,sx:{flexGrow:1},children:[s.jsxs(n,{direction:"row",justifyContent:"space-between",children:[s.jsx(l,{variant:"h4",children:"Session"}),s.jsx(n,{direction:"row",spacing:2,children:u.sessionId&&x===!1?s.jsx(h,{variant:"contained",onClick:()=>i(),children:"Fix URL"}):s.jsx(P,{Component:Q,componentProps:{disabled:j,changeStatusMutation:x?c:t,isStarted:x}})})]}),s.jsx(w,{error:t.error,resetError:t.reset}),s.jsx(w,{error:c.error,resetError:c.reset}),s.jsx(E,{title:`Session provides ACID compliance for the data in the store only. ${g?'To apply changes you need click on the "Commit" button or discard them by clicking on the "Rollback" or closing the session':""}`}),e.isIdle?s.jsxs(l,{children:['You must select a session running on this store or create a new one. Click on "New Session" in the top right corner to create a new session. Go to the ',y," and click on the Link of the session to select it. The ",y," also provides an advanced interface to create sessions."]}):e.isSuccess?g?s.jsxs(n,{spacing:2,children:[s.jsxs(n,{direction:"row",spacing:1,alignItems:"center",children:[s.jsx(h,{disabled:j,sx:{width:"100px",flexShrink:0},onClick:f.mutate,children:"Commit"}),s.jsx(l,{children:"Commit the current transaction"})]}),s.jsxs(n,{direction:"row",spacing:1,alignItems:"center",children:[s.jsx(h,{disabled:j,sx:{width:"100px",flexShrink:0},color:"error",onClick:S.mutate,children:"Rollback"}),s.jsx(l,{children:"Discards any local repository changes, then synchronize to the latest committed repository version on the server. Starts a new transaction."})]})]}):null:s.jsx(D,{})]})}export{A as default};
