import{b as C}from"./primevue-CfIk0_DY.js";import{$ as k,o as S,h as $,b as A,c as D,d as m,v as l,a7 as f,p as N,E,a as p}from"./vue-core-Di3IuVqe.js";import{u as M,b as u,S as j}from"./index-BxIwIJfy.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const F={key:0},G={class:"flex flex-wrap gap-2 mb-4 justify-between"},J={class:"flex flex-wrap gap-2"},z={__name:"Jumia",setup(T){const t=k(),{showSuccess:h,showError:i,showWarn:g,confirmAction:v}=M(),o=E({lecture:!1,ajout:!1,modif:!1,supp:!1}),d=p([]),n=p(!1),b=()=>j("Jumia"),_=async()=>{try{const s=(await u.post(`${t.lienApi}/verifierDroit/${t.state.dbCommun6}`,{id_utilisateur:t.userId,id_page:412,mail:t.state.userCloud.mail})).data;s&&Object.keys(s).length>0&&(o.lecture=s.lecture,o.ajout=s.ajout,o.modif=s.modif,o.supp=s.supp),o.lecture||g("Vous n'avez pas le droit, veuillez consulter l'administrateur")}catch{i("Erreur lors de la vérification des droits")}},y={sortable:!0,filter:!0,resizable:!0,flex:1,minWidth:80,suppressHeaderMenuButton:!0},w=[{headerName:"Date",field:"date_sync",width:170,flex:0,sort:"desc",valueFormatter:e=>e.value?new Date(e.value).toLocaleString("fr-FR"):""},{headerName:"Type",field:"type_sync",width:110,flex:0,cellRenderer:e=>`<i class="pi ${{produits:"pi-box",commandes:"pi-shopping-cart",stock:"pi-warehouse"}[e.value]||"pi-sync"} mr-1"></i> ${e.value||""}`},{headerName:"Direction",field:"direction",width:120,flex:0,cellRenderer:e=>e.value==="OMAG_JUMIA"?'<span style="color:#3b82f6">OMAG → Jumia</span>':e.value==="JUMIA_OMAG"?'<span style="color:#8b5cf6">Jumia → OMAG</span>':e.value||""},{headerName:"Éléments",field:"nb_elements",width:90,flex:0,cellClass:"ag-right-aligned-cell"},{headerName:"Succès",field:"nb_succes",width:80,flex:0,cellClass:"ag-right-aligned-cell"},{headerName:"Erreurs",field:"nb_erreurs",width:80,flex:0,cellClass:"ag-right-aligned-cell",cellStyle:e=>e.value>0?{color:"#ef4444",fontWeight:"bold"}:{}},{headerName:"Statut",field:"statut",width:100,flex:0,cellRenderer:e=>`<span style="color:${{succes:"#22c55e",partiel:"#f59e0b",erreur:"#ef4444"}[e.value]||"#6b7280"};font-weight:bold">${e.value||""}</span>`},{headerName:"Durée",field:"duree_ms",width:90,flex:0,valueFormatter:e=>e.value?(e.value/1e3).toFixed(1)+"s":""},{headerName:"Détails",field:"details",minWidth:300,tooltipField:"details"}],c=async()=>{try{const e=await u.post(`${t.lienApi}/jumia/sync-log/${t.db}`);d.value=e.data}catch{i("Erreur lors du chargement des logs")}},x=async()=>{if(await v("Lancer une synchronisation complète (produits + stock + commandes) ?")){n.value=!0;try{const a=(await u.post(`${t.lienApi}/jumia/sync-tout/${t.db}`,{dbCommun6:t.state.dbCommun6,id_societe:t.id_societe})).data.resultats;let r=`Synchronisation complète terminée :
`;a.produits&&(r+=`• Produits : ${a.produits.nbSucces||0} succès
`),a.stock&&(r+=`• Stock : ${a.stock.nbSucces||0} succès
`),a.commandes&&(r+=`• Commandes : ${a.commandes.nbSucces||0} importée(s)`),h(r),c()}catch{i("Erreur lors de la synchronisation complète")}finally{n.value=!1}}};return S(async()=>{await _(),o.lecture&&c()}),(e,s)=>{const a=C,r=$("ag-grid-vue");return o.lecture?(A(),D("div",F,[m("div",G,[m("div",J,[l(a,{label:"Actualiser",icon:"pi pi-refresh",text:"",onClick:c}),l(a,{label:"Synchronisation complète",icon:"pi pi-sync",text:"",severity:"warn",onClick:x,loading:n.value,disabled:!o.modif},null,8,["loading","disabled"])]),l(a,{icon:"pi pi-times",label:"Fermer",onClick:b,text:""})]),l(r,{style:{height:"70vh",width:"100%"},theme:f(t).state.agGridTheme,columnDefs:w,rowData:d.value,defaultColDef:y,localeText:f(t).state.agGridLocale},null,8,["theme","rowData","localeText"])])):N("",!0)}}};export{z as default};
