import{o as e}from"./chunk-jRWAZmH_.js";import{n as t,t as n}from"./jsx-runtime-CEixWuwE.js";import{nt as r}from"./axios-v6FV69Ne.js";import{c as i,u as a}from"./ctiAxios-BIVP6fGU.js";import{S as o}from"./notification-C7Dk1wtU.js";import{t as s}from"./button-C7b7AmGo.js";import{n as c}from"./chunk-4N6VE7H7-BV8msCgV.js";import{I as l,pt as u,s as d}from"./index-BqyXv5bE.js";import{n as f}from"./logs.queries-BiWc7Zaz.js";var p=e(t()),m=n(),h=async()=>{let e=await o.getItem(`REACT_QUERY_OFFLINE_CACHE`);return e?(i(e)?.clientState?.queries??[]).map(e=>({queryKey:e.queryKey,status:e.state?.status??`—`,dataUpdatedAt:e.state?.dataUpdatedAt?new Date(e.state.dataUpdatedAt).toLocaleString():`—`,data:e.state?.data})):[]},g=()=>{let e=f(),t=l(),n=e.data??[],i=t.data?.session,[o,g]=(0,p.useState)(`logs`),[_,v]=(0,p.useState)([]),y=(0,p.useRef)(null);(0,p.useEffect)(()=>{if(o!==`cache`)return;let e=async()=>{v(await h())};e();let t=a.getQueryCache().subscribe(()=>{clearTimeout(y.current),y.current=setTimeout(e,1500)});return()=>{t(),clearTimeout(y.current)}},[o]);let b=()=>{e.refetch()},x=[{title:`Id`,dataKey:`id`},{title:`Date`,dataKey:`createdAt`,width:150},{title:`Code`,dataKey:`code`,width:100},{title:`Count`,dataKey:`count`,width:100},{title:`Erreur`,dataKey:`error`,width:200},{title:`Texte`,dataKey:`text`,width:200},{title:`Message`,dataKey:`message`,width:200},{title:`Utilisateur`,dataKey:`user`,dataGetter:({rowData:e})=>e.extra.user,width:100},{title:`URL`,dataKey:`url`,dataGetter:({rowData:e})=>e.extra.url,width:300}].map(e=>({width:50,resizable:!0,key:e.dataKey,...e}));return i.CONNECTEDUSER===`cti`?(0,m.jsxs)(`div`,{className:`cti-page`,children:[(0,m.jsxs)(`div`,{className:`page-header`,children:[(0,m.jsx)(`div`,{className:`header-title`,children:`Logs`}),(0,m.jsxs)(`div`,{className:`header-actions`,children:[(0,m.jsx)(s,{type:o===`logs`?`primary`:`default`,onClick:()=>g(`logs`),children:`Logs serveur`}),(0,m.jsx)(s,{type:o===`cache`?`primary`:`default`,onClick:()=>g(`cache`),children:`Cache persistant`}),o===`logs`&&(0,m.jsx)(s,{onClick:b,children:`Reload`})]})]}),(0,m.jsxs)(`div`,{className:`page-content`,children:[o===`logs`&&(0,m.jsx)(`div`,{className:`logs-table`,children:(0,m.jsx)(d,{rowKey:`id`,columns:x,data:n,loading:e.isFetching,cellProps:({rowData:e,column:t})=>({onClick:n=>{n.preventDefault();var i=document.createElement(`textarea`);i.value=e[t.dataKey],document.body.appendChild(i),i.select(),document.execCommand(`copy`),document.body.removeChild(i),r.success(`Copié !`)}})})}),o===`cache`&&(0,m.jsx)(`div`,{className:`logs-cache-pre`,children:_===null||_.length===0?(0,m.jsx)(`p`,{children:`Aucun cache persistant trouvé.`}):(0,m.jsx)(u,{children:_.map((e,t)=>(0,m.jsx)(u.Panel,{header:(0,m.jsxs)(`span`,{children:[(0,m.jsx)(`strong`,{children:JSON.stringify(e.queryKey)}),` — `,e.status,` — `,e.dataUpdatedAt]}),children:(0,m.jsx)(`pre`,{style:{margin:0,fontSize:11,overflow:`auto`},children:JSON.stringify(e.data,null,2)})},t))})})]})]}):(0,m.jsx)(c,{to:`/accueil`,replace:!0})};g.propTypes={};export{g as default};