import{o as e}from"./chunk-jRWAZmH_.js";import{n as t,t as n}from"./jsx-runtime-CEixWuwE.js";import{fr as r,n as i,o as a,r as o}from"./axios-v6FV69Ne.js";import{t as s}from"./index.esm-DR3o6Tiw.js";import{t as c}from"./ctiAxios-BIVP6fGU.js";import{t as l}from"./button-C7b7AmGo.js";import{t as u}from"./DownloadOutlined-DZv3jbUo.js";import{t as d}from"./useMutation-Dw_VO9_w.js";import{t as f}from"./queryOptions-Cg9orY1Y.js";import{t as p}from"./UndoOutlined-2WspCEN7.js";import{F as m,I as h,L as g,N as _,Z as v,s as y,v as b}from"./index-BqyXv5bE.js";import{r as x,t as S}from"./path-CO9rz0FN.js";import{i as C}from"./importColumn-CrkJLBph.js";async function w(e){let t=new FormData;return t.append(`action`,`get`),(await c({method:`post`,url:r()+x(e),data:t,headers:{"Content-Type":`multipart/form-data`},responseType:`json`})).data}async function T({id:e,module:t}){if(t===`ssr`){await _.delete(`api/pmsissr/importsOvalide/${e}`);return}let n=new FormData;n.append(`action`,`delete`),n.append(`id`,e),await c({method:`post`,url:r()+x(t),data:n,headers:{"Content-Type":`multipart/form-data`},responseType:`json`})}async function E({file:e,typeEts:t,module:n}){let i=new FormData;return i.append(`action`,`post`),i.append(`fileName`,e.name),i.append(`fileData`,e),i.append(`typeEts`,t),(await c({method:`post`,url:r()+x(n),data:i,headers:{"Content-Type":`multipart/form-data`},responseType:`json`})).data}async function D(e,t){b((await c({method:`get`,url:`${r()}${S(t)}${e}`,responseType:`blob`,headers:{"Content-Type":`multipart/form-data`}})).data,`ovalide.zip`)}var O={all:[`ovalideImports`],list:e=>[...O.all,`list`,e]},k=e=>f({queryKey:O.list(e),queryFn:()=>w(e),enabled:!!e}),A=e=>o(k(e));function j(){let e=a();return d({mutationFn:T,meta:{successMessage:`Import supprimé`,errorMessage:`Erreur lors de la suppression de l'import`},onSettled:async(t,n,r)=>{await e.invalidateQueries({queryKey:O.list(r.module)})}})}function M(){let e=a();return d({mutationFn:E,meta:{successMessage:`Fichier importé`,errorMessage:`Erreur lors de l'import du fichier`},onSettled:async(t,n,r)=>{await e.invalidateQueries({queryKey:O.list(r.module)})}})}var N=e(t()),P=e(i()),F=n(),I=({module:e})=>{let t=h(),n=A(e),r=j(),i=M(),a=n.data??[],[o,c]=(0,N.useState)(null),d=(0,N.useRef)(),f=()=>{n.refetch()},_=e=>{c(a.find(t=>t.oid===e))},b=()=>{o&&r.mutate({id:o.oid,module:e},{onSuccess:()=>c(null)})},x=()=>{o&&D(o.oid,e)},S=()=>{d.current.click()},w=n=>{let r=n.target.files[0];if(r){let n=t.data?.environment?.TYPEETS;i.mutate({file:r,typeEts:n,module:e})}},T=r.isPending||i.isPending;return(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)(s,{children:(0,F.jsx)(`title`,{children:`iCTI | Gestion des imports`})}),(0,F.jsxs)(`div`,{className:`component-header`,children:[(0,F.jsx)(`div`,{className:`header-title`,children:`Import des fichiers MAT2A/OVALIDE`}),(0,F.jsxs)(`div`,{className:`header-actions`,children:[(0,F.jsx)(m,{title:`Actualiser`,children:(0,F.jsx)(l,{type:`link`,onClick:f,children:(0,F.jsx)(p,{})})}),(0,F.jsx)(m,{title:`Supprimer`,children:(0,F.jsx)(l,{type:`link`,onClick:b,disabled:!o||r.isPending,children:(0,F.jsx)(v,{})})}),(0,F.jsx)(m,{title:`Télécharger le fichier de l'import`,children:(0,F.jsx)(l,{type:`link`,onClick:x,disabled:!o||!o.oid,children:(0,F.jsx)(u,{})})}),(0,F.jsx)(l,{size:`default`,type:`primary`,icon:(0,F.jsx)(g,{}),onClick:S,loading:i.isPending,children:`Importer un fichier`}),(0,F.jsx)(`input`,{type:`file`,ref:d,onChange:w,style:{display:`none`}})]})]}),(0,F.jsx)(`div`,{className:`component-content`,children:(0,F.jsx)(`div`,{className:`ovalide-imports`,children:(0,F.jsx)(y,{rowKey:`oid`,columns:C(e),loading:n.isFetching||T,data:a,selectedRow:o,onRowSelect:_})})})]})};I.propTypes={module:P.default.string};export{I as default};