import{V as S,D as x}from"./datatables.net-vue3-B28JL-vi.js";import{_ as T}from"./DeleteDialog-GXib_x-K.js";import{p as c,c as A,_ as C,b as E,w as $,o as b,z as e,k as P,f as t,P as d,U as m,Z as v,e as w,h as y,V as M,N as B}from"./vue-CSzJdJby.js";import{$ as k}from"./jquery-BALIvAru.js";import{_ as D}from"./Error-BXO_ADNF.js";import{_ as O}from"./ModalDialog-BxAzqKGJ.js";import"./highlight.js-CWp04Ajj.js";import"./bootstrap.esm-BOBBXxos.js";const L={class:"modal-body p-3"},H={class:"row"},R={class:"col"},X={class:"row"},z={class:"mb-3 col-sm-6"},J={class:"form-label"},Z=["disabled"],q={class:"form-check form-switch"},F=["disabled"],G=e("label",{class:"form-check-label",for:"switchActive"},"Active",-1),I=e("br",null,null,-1),K={class:"form-check form-switch"},Q=["disabled"],W=e("label",{class:"form-check-label",for:"switchAdmin"},"Administrator",-1),Y=e("br",null,null,-1),ee={class:"mb-3 col-sm-6"},se={class:"form-label"},te=["disabled"],oe=["disabled"],ae={key:0,class:"form-text text-body-secondary"},le=e("small",null,"*: leave this field blank to keep it unchanged.",-1),ie=[le],ne={class:"mb-3 col-sm-6"},de={class:"form-label"},re=["disabled"],ce=e("span",{class:"form-text text-body-secondary small"},"Leave blank to prevent user from receiving notifications by email.",-1),me={class:"mb-3 col-sm-6"},ue={class:"form-label"},_e=["disabled"],pe=e("span",{class:"form-text text-body-secondary small"},"Leave blank to prevent user from receiving notifications by SMS.",-1),be={class:"modal-footer"},fe=e("button",{type:"button",class:"btn btn-outline-secondary","data-bs-dismiss":"modal"},"Cancel",-1),he=["disabled"],ve={key:0,class:"fa fa-spinner fa-spin loader"},we={__name:"EditUserDialog",setup(ye,{expose:U}){const f=c(null),u=c(null),n=c(!0),_=c(!1),i=A(()=>n.value||_.value),r=c("");let p="/json/users",h={name:"",email:"",phone:"",password:"",password2:"",is_active:!0,is_admin:!1};const s=C({...h});function g(a){r.value=a,p=`/json/users/${a}`,f.value.show()}U({edit:g});function V(){if(!r.value){n.value=!1;return}k.ajax({url:p,error:a=>{u.value.fromXHR(a),_.value=!0},success:a=>{s.name=a.name,s.email=a.email,s.phone=a.phone,s.is_active=a.active,s.is_admin=a.admin}}).always(()=>{n.value=!1})}function N(){({new_username:s.name,...s},n.value=!0),_.value=!1,k.ajax({url:p,method:r.value?"PUT":"POST",async:!0,contentType:"application/json",dataType:"json",data:JSON.stringify(s),error:a=>{n.value=!1,u.value.fromXHR(a)},success:()=>{window.location.reload()}})}function j(){p="/json/users",r.value="",u.value.clear(),n.value=!0,_.value=!1,Object.assign(s,h)}return(a,o)=>(b(),E(O,{ref_key:"root",ref:f,id:"modalEditUser",title:`${r.value?"Update":"Create"} User`,onOpening:V,onClosed:j},{default:$(()=>[e("form",{onSubmit:M(N,["prevent"])},[e("div",L,[e("div",H,[e("div",R,[P(D,{ref_key:"error",ref:u},null,512)])]),t(),e("div",X,[e("div",z,[e("label",J,[t("Username"),d(e("input",{type:"text",class:"form-control",placeholder:"Username","onUpdate:modelValue":o[0]||(o[0]=l=>s.name=l),disabled:i.value},null,8,Z),[[m,s.name]])]),t(),e("div",q,[d(e("input",{type:"checkbox",class:"form-check-input",role:"switch",id:"switchActive","onUpdate:modelValue":o[1]||(o[1]=l=>s.is_active=l),disabled:i.value},null,8,F),[[v,s.is_active]]),t(),G,I]),t(),e("div",K,[d(e("input",{type:"checkbox",class:"form-check-input",role:"switch",id:"switchAdmin","onUpdate:modelValue":o[2]||(o[2]=l=>s.is_admin=l),disabled:i.value},null,8,Q),[[v,s.is_admin]]),t(),W,Y])]),t(),e("div",ee,[e("label",se,[t(`Password*

              `),d(e("input",{type:"password",class:"form-control",placeholder:"Password","onUpdate:modelValue":o[3]||(o[3]=l=>s.password=l),disabled:i.value},null,8,te),[[m,s.password]]),t(),d(e("input",{type:"password",class:"form-control",placeholder:"Confirm password","onUpdate:modelValue":o[4]||(o[4]=l=>s.password2=l),disabled:i.value},null,8,oe),[[m,s.password2]])]),t(),r.value?(b(),w("p",ae,ie)):y("",!0)]),t(),e("div",ne,[e("label",de,[t("Email"),d(e("input",{type:"email",class:"form-control",placeholder:"Email","onUpdate:modelValue":o[5]||(o[5]=l=>s.email=l),disabled:i.value},null,8,re),[[m,s.email]])]),t(),ce]),t(),e("div",me,[e("label",ue,[t(`Phone
              `),d(e("input",{type:"text",class:"form-control",placeholder:"+33...","onUpdate:modelValue":o[6]||(o[6]=l=>s.phone=l),disabled:i.value},null,8,_e),[[m,s.phone]])]),t(),pe])])]),t(),e("div",be,[fe,t(),e("button",{type:"submit",class:"btn btn-success ms-auto",disabled:i.value},[t(`
          Save
          `),n.value?(b(),w("i",ve)):y("",!0)],8,he)])],32)]),_:1},8,["title"]))}};S.use(x);B({components:{edituserdialog:we,deletedialog:T},created(){this.$nextTick(()=>{new x("#tableUsers",{pageLength:50,stateSave:!0,columns:[{width:"auto"},{width:"auto"},{width:"12rem"},{width:"6rem"},{width:"6rem"},{width:"auto"},{width:"6rem",orderable:!1}],layout:{topStart:"search",topEnd:{buttons:[{text:"New user",className:"btn btn-sm btn-success",attr:{id:"buttonNewUser","data-bs-toggle":"modal","data-bs-target":"#modalEditUser"}}]}}})})}}).mount("#vueapp");
