import{o as e}from"./chunk-jRWAZmH_.js";import{n as t,t as n}from"./jsx-runtime-CEixWuwE.js";import{Cr as r,hr as i,n as a,o,r as s}from"./axios-v6FV69Ne.js";import{t as c}from"./index.esm-DR3o6Tiw.js";import{i as l}from"./ctiAxios-BIVP6fGU.js";import{a as u}from"./notification-C7Dk1wtU.js";import{t as d}from"./button-C7b7AmGo.js";import{t as f}from"./DownloadOutlined-DZv3jbUo.js";import{t as p}from"./useMutation-Dw_VO9_w.js";import{t as m}from"./UndoOutlined-2WspCEN7.js";import{F as h,L as g,s as _,wt as v}from"./index-BqyXv5bE.js";var y={all:[`simulations`],list:e=>[...y.all,e]},b=e=>{let t=e.getElementsByTagName(`HTTP_SERVICE`)[0];return r(i(t,`FILE`))},x=e=>{let t=e.getElementsByTagName(`HTTP_SERVICE`)[0];return r(i(t,`RETURN`))[0]},S=`modules/pmsi/php/PMSI_simulation.php`;async function C(e){let t=await l(S,{operation:`get_list`,FG_YEAR:e});return{simulations:b(t),message:x(t)}}async function w(e){await l(S,{operation:`send_file`,FG_YEAR:e})}async function T(e,t){let n=x(await l(S,{operation:`get_file`,FG_YEAR:e,file:t}));if(n.code!==`OK`)throw Error(n.message);return n}async function E(e,t){let n=x(await l(S,{operation:`trt_file`,FG_YEAR:e,file:t}));if(n.code!==`OK`)throw Error(n.message);return n}function D(e){return s({queryKey:y.list(e),queryFn:()=>C(e),enabled:!!e})}function O(){let e=o();return p({mutationFn:({year:e})=>w(e),meta:{successMessage:`Séjours non groupés envoyés`,errorMessage:`Erreur lors de l'envoi des séjours`},onSettled:async(t,n,r)=>{await e.invalidateQueries({queryKey:y.list(r.year)})}})}function k(){let e=o();return p({mutationFn:async({year:e,file:t})=>{await T(e,t),u({type:`info`,message:`Simulation`,description:`Séjours groupés téléchargés, lancement des traitements`}),await E(e,t)},meta:{successMessage:`Traitements terminés`,errorMessage:`Erreur lors du téléchargement des séjours groupés`},onSettled:async(t,n,r)=>{await e.invalidateQueries({queryKey:y.list(r.year)})}})}var A=e(t()),j=e(a()),M=[{title:`Séjour téléversés`,dataKey:`fg0_name`,key:`fg0_name`,width:300,resizable:!0,flexGrow:1},{title:`Date de téléversement`,dataKey:`fg0_remote_date`,key:`fg0_remote_date`,width:300,resizable:!0},{title:`Taille`,dataKey:`fg0_size`,key:`fg0_size`,cellRenderer:({cellData:e})=>`${e/1e3} Ko`,width:300,resizable:!0},{title:`Groupé par CTI`,dataKey:`fg1_remote_date`,key:`fg1_remote_date`,width:300,resizable:!0}],N=n(),P=({year:e})=>{let t=D(e),n=O(),r=k(),i=t.data?.simulations??[],a=t.data?.message??{},[o,s]=(0,A.useState)({}),l=()=>{t.refetch()},u=()=>{n.mutate({year:e})},p=e=>{s(i.find(t=>t.key===e))},y=()=>{o.fg1_ok===`OUI`&&r.mutate({year:e,file:o.fg1_name})},b=t.isFetching||n.isPending||r.isPending;return(0,N.jsxs)(N.Fragment,{children:[(0,N.jsx)(c,{children:(0,N.jsxs)(`title`,{children:[`iCTI | Regroupage `,e]})}),(0,N.jsxs)(`div`,{className:`component-header`,children:[(0,N.jsxs)(`div`,{className:`header-title`,children:[`Regroupage `,e]}),(0,N.jsxs)(`div`,{className:`header-actions`,children:[(0,N.jsx)(h,{title:`Téléverser les séjours vers Web CTI`,children:(0,N.jsxs)(d,{onClick:u,disabled:n.isPending,children:[(0,N.jsx)(g,{}),`Téléverser`]})}),(0,N.jsx)(h,{title:`Télécharger la simulation`,children:(0,N.jsxs)(d,{disabled:o.fg1_ok!==`OUI`||r.isPending,onClick:y,children:[(0,N.jsx)(f,{}),`Télécharger`]})}),(0,N.jsx)(h,{title:`Actualiser`,children:(0,N.jsx)(d,{type:`link`,onClick:l,children:(0,N.jsx)(m,{})})})]})]}),a.warning&&a.warning!==``?(0,N.jsx)(v,{message:a.warning,type:`warning`,showIcon:!0}):null,(0,N.jsx)(`div`,{className:`component-content`,children:(0,N.jsx)(_,{columns:M,data:i,loading:b,fixed:!1,onRowSelect:p,selectedRow:o})})]})};P.propTypes={year:j.default.string};export{P as default};