import{b as E,e as U,f as A}from"./primevue-CfIk0_DY.js";import{u as I,b as k,s as u,n as P,L as B}from"./index-BxIwIJfy.js";import{o as N,b as D,c as R,d as o,v as l,l as M,a as g,_ as b,y as v,E as z}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const L={class:"max-w-3xl mx-auto space-y-6"},F={class:"bg-white rounded-xl shadow-sm p-6"},T={class:"grid grid-cols-1 sm:grid-cols-2 gap-4"},G={class:"bg-white rounded-xl shadow-sm p-6"},S={class:"grid grid-cols-1 sm:grid-cols-2 gap-4"},q={style:{"margin-top":"20px"}},O={class:"flex flex-col gap-3",style:{"padding-top":"8px"}},Y={__name:"PortailClientProfil",setup(j){const{showSuccess:V,showError:r}=I(),x=v(()=>u.state.portailClientDb),y=v(()=>u.state.portailClientClient?.code_client),C=v(()=>u.state.portailClientToken),d=v(()=>u.state.portailClientContact),t=g({}),c=g(!1),m=g(!1),a=z({ancien:"",nouveau:"",confirmation:""}),s=n=>b("div",{class:n.class},[b("div",{class:"text-xs text-gray-500",style:"margin-bottom: 2px"},n.label),b("div",{class:"text-gray-800 font-medium"},n.value||"—")]);s.props=["label","value","class"];const h=async()=>{if(!(!x.value||!y.value))try{const n=await k.get(`${u.lienApi}/portail-client/profil/${x.value}/${encodeURIComponent(y.value)}`,{headers:{Authorization:`Bearer ${C.value}`}});t.value=n.data||{}}catch{t.value={}}},w=()=>{c.value=!1,a.ancien="",a.nouveau="",a.confirmation=""},_=async()=>{if(!a.ancien||!a.nouveau){r("Tous les champs sont obligatoires.");return}const n=P(a.nouveau,{mail:d.value?.email});if(n.niveau==="critique"||n.niveau==="faible"){r(n.raisons[0]||`Choisissez un mot de passe d'au moins ${B} caracteres melant lettres et chiffres.`);return}if(a.nouveau!==a.confirmation){r("La confirmation ne correspond pas.");return}m.value=!0;try{await k.post(`${u.lienApi}/portail-client/change-password`,{ancienMdp:a.ancien,nouveauMdp:a.nouveau},{headers:{Authorization:`Bearer ${C.value}`}}),V("Mot de passe modifie."),w()}catch(e){r(e?.response?.data?.message||"Erreur lors de la modification.")}finally{m.value=!1}};return N(h),(n,e)=>{const p=E,f=U,$=A;return D(),R("div",L,[o("div",F,[e[5]||(e[5]=o("h2",{class:"text-lg font-bold text-gray-800",style:{"margin-bottom":"4px"}},"Informations de mon entreprise",-1)),e[6]||(e[6]=o("p",{class:"text-gray-500",style:{"margin-bottom":"20px"}}," Lecture seule. Pour modifier ces informations, contactez votre fournisseur. ",-1)),o("div",T,[l(s,{label:"Code client",value:t.value.code_client},null,8,["value"]),l(s,{label:"Raison sociale",value:t.value.nom},null,8,["value"]),l(s,{label:"ICE",value:t.value.Ice},null,8,["value"]),l(s,{label:"RC",value:t.value.RC},null,8,["value"]),l(s,{label:"Telephone",value:t.value.tel},null,8,["value"]),l(s,{label:"GSM",value:t.value.gsm},null,8,["value"]),l(s,{label:"Fax",value:t.value.fax},null,8,["value"]),l(s,{label:"Email",value:t.value.mail},null,8,["value"]),l(s,{label:"Ville",value:t.value.ville},null,8,["value"]),l(s,{label:"Pays",value:t.value.pays},null,8,["value"]),l(s,{label:"Adresse",value:t.value.adresse,class:"sm:col-span-2"},null,8,["value"])])]),o("div",G,[e[7]||(e[7]=o("h2",{class:"text-lg font-bold text-gray-800",style:{"margin-bottom":"4px"}},"Mon compte portail",-1)),e[8]||(e[8]=o("p",{class:"text-gray-500",style:{"margin-bottom":"20px"}}," Vos informations d'acces au portail. ",-1)),o("div",S,[l(s,{label:"Nom",value:d.value?.nom_contact},null,8,["value"]),l(s,{label:"Fonction",value:d.value?.fonction},null,8,["value"]),l(s,{label:"Email",value:d.value?.email,class:"sm:col-span-2"},null,8,["value"])]),o("div",q,[l(p,{label:"Changer mon mot de passe",icon:"pi pi-key",onClick:e[0]||(e[0]=i=>c.value=!0)})])]),l($,{visible:c.value,"onUpdate:visible":e[4]||(e[4]=i=>c.value=i),modal:"",style:{width:"450px"},header:"Changer mon mot de passe"},{footer:M(()=>[l(p,{label:"Annuler",text:"",onClick:w}),l(p,{label:"Modifier",icon:"pi pi-check",onClick:_,loading:m.value},null,8,["loading"])]),default:M(()=>[o("div",O,[o("div",null,[e[9]||(e[9]=o("label",{class:"block",style:{"margin-bottom":"4px"}},"Ancien mot de passe",-1)),l(f,{modelValue:a.ancien,"onUpdate:modelValue":e[1]||(e[1]=i=>a.ancien=i),feedback:!1,toggleMask:"",class:"w-full",inputClass:"w-full"},null,8,["modelValue"])]),o("div",null,[e[10]||(e[10]=o("label",{class:"block",style:{"margin-bottom":"4px"}},"Nouveau mot de passe",-1)),l(f,{modelValue:a.nouveau,"onUpdate:modelValue":e[2]||(e[2]=i=>a.nouveau=i),toggleMask:"",class:"w-full",inputClass:"w-full"},null,8,["modelValue"])]),o("div",null,[e[11]||(e[11]=o("label",{class:"block",style:{"margin-bottom":"4px"}},"Confirmer",-1)),l(f,{modelValue:a.confirmation,"onUpdate:modelValue":e[3]||(e[3]=i=>a.confirmation=i),feedback:!1,toggleMask:"",class:"w-full",inputClass:"w-full"},null,8,["modelValue"])])])]),_:1},8,["visible"])])}}};export{Y as default};
