import{b as G,B as N,x as Z}from"./primevue-CfIk0_DY.js";import{o as K,j as O,H as U,b as g,c as f,a7 as i,d as t,v as o,p as w,t as _,E as q,a as p}from"./vue-core-Di3IuVqe.js";import{u as F,S as k,b as A,s as r}from"./index-BxIwIJfy.js";import{C as H}from"./ComboDynamique-BzWI4ISP.js";import{u as R}from"./useZkAgent-BgTB3-rV.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const W={key:0,class:"p-3 mb-2 bg-orange-50 border border-orange-200 rounded flex items-center gap-3"},J={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},L={class:"btns flex items-center gap-2"},Q={class:"px-4"},X={class:"flex flex-wrap items-end gap-4"},Y={class:"w-64"},ee={class:"flex flex-col justify-end"},te={class:"flex items-end gap-2"},se={key:1,class:"px-4 mt-4"},ne={class:"bg-green-50 border border-green-200 rounded p-3"},ae={class:"flex items-center gap-2 mb-2"},oe={class:"font-semibold text-green-700"},ge={__name:"Gestionpointeuse",setup(le){const{confirmAction:D,showSuccess:b,showError:d,showWarn:x}=F(),u=q({lecture:!1,ajout:!1}),$=async()=>{try{const e=(await A.post(`${r.lienApi}/verifierDroit/${r.state.dbCommun6}`,{id_utilisateur:r.userId,id_page:3205,mail:r.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(u.lecture=e.lecture,u.ajout=e.ajout),u.lecture||(x("Vous n'avez pas le droit, veuillez consulter l'administrateur"),k("Gestionpointeuse"))}catch(n){d("Une erreur est survenue : "+(n.response?.data?.message||n.message))}},{agentConnecte:m,loading:S,verifierAgent:y,connecter:T,deconnecter:V,viderPointage:h}=R(),C=p(),v=p(null),s=p(null),a=p("Déconnecté"),j=async n=>{if(!n){s.value=null;return}try{const e=await A.post(`${r.lienApi}/unTerminal/${r.db}/${n}`);s.value={ip:e.data.IP,port:e.data.Port||4370}}catch{s.value=null}},z=async()=>{if(!s.value){x("Veuillez sélectionner un terminal");return}try{await T(s.value.ip,s.value.port),a.value="Connecté",b("Connexion au terminal établie")}catch(n){a.value="Déconnecté",d("Impossible de se connecter : "+(n.response?.data?.error||n.message))}},B=async()=>{if(s.value){try{await V(s.value.ip,s.value.port)}catch{}a.value="Déconnecté"}},I=n=>{switch(n){case"Connecté":return"success";case"Déconnecté":return"danger";default:return"info"}},M=[{label:"Supprimer tous les pointages",icon:"pi pi-trash",command:async()=>{if(!(!s.value||!await D({message:"Supprimer tous les pointages de la pointeuse ? Cette action est irréversible.",acceptClass:"p-button-danger"})))try{await h(s.value.ip,s.value.port),b("Pointages supprimés de la pointeuse")}catch(e){d("Erreur : "+(e.response?.data?.error||e.message))}}}];return K(async()=>{await $(),y()}),(n,e)=>{const c=G,P=N,E=Z;return O((g(),f("div",null,[i(m)?w("",!0):(g(),f("div",W,[e[5]||(e[5]=t("i",{class:"pi pi-exclamation-triangle text-orange-500 text-xl"},null,-1)),e[6]||(e[6]=t("div",null,[t("div",{class:"font-semibold text-orange-700"},"Agent ZK non détecté"),t("div",{class:"text-sm text-orange-600"},"Veuillez démarrer l'agent OMAG ZK sur un PC du réseau local des pointeuses.")],-1)),o(c,{label:"Réessayer",icon:"pi pi-refresh",size:"small",severity:"warning",onClick:e[0]||(e[0]=l=>i(y)()),class:"ml-auto"})])),t("div",J,[t("div",L,[o(c,{text:"",icon:"pi pi-cog",label:"Actions",onClick:e[1]||(e[1]=l=>C.value.toggle(l)),disabled:!i(m)||a.value!=="Connecté"},null,8,["disabled"]),o(P,{ref_key:"actionsMenu",ref:C,model:M,popup:!0},null,512),o(c,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=l=>i(k)("Gestionpointeuse"))})])]),t("div",Q,[t("div",X,[t("div",Y,[e[7]||(e[7]=t("label",{class:"block text-sm"},"Terminal",-1)),o(H,{modelValue:v.value,"onUpdate:modelValue":[e[3]||(e[3]=l=>v.value=l),j],table:"Terminal",class:"w-full",size:"small"},null,8,["modelValue"])]),t("div",ee,[e[8]||(e[8]=t("div",{class:"h-4"},null,-1)),o(c,{label:a.value==="Connecté"?"Déconnecter":"Connecter",icon:a.value==="Connecté"?"pi pi-times-circle":"pi pi-link",severity:a.value==="Connecté"?"danger":"primary",size:"small",onClick:e[4]||(e[4]=l=>a.value==="Connecté"?B():z()),disabled:!v.value||!i(m),loading:i(S)},null,8,["label","icon","severity","disabled","loading"])]),t("div",te,[e[9]||(e[9]=t("div",{class:"h-4"},null,-1)),e[10]||(e[10]=t("span",null,"État :",-1)),o(E,{value:a.value,severity:I(a.value)},null,8,["value","severity"])])])]),a.value==="Connecté"&&s.value?(g(),f("div",se,[t("div",ne,[t("div",ae,[e[11]||(e[11]=t("i",{class:"pi pi-check-circle text-green-600"},null,-1)),t("span",oe,"Terminal connecté : "+_(s.value.ip)+":"+_(s.value.port),1)])])])):w("",!0)],512)),[[U,u.lecture]])}}};export{ge as default};
