1import{d as E,b as M,Y as C,ac as B,u as I,o as O,R as g,C as U,w as N,e as s,c as n,l as r,t as b,g as m,h as p,a4 as W,v as q,f as S,F as z,r as $,p as F,B as c,D as H,x as Q,i as Y,n as G,k as T,j as t,Q as J}from"./CO-mOBGH.js";import{V as K}from"./5_SeVuGY.js";import{u as X}from"./BSFV989u.js";const Z={key:0,class:"min-h-screen flex items-center justify-center bg-gray-50 p-4"},ee={class:"max-w-2xl w-full bg-white rounded-lg shadow-lg overflow-hidden"},se={class:"bg-[#1b2441] text-white p-6 text-center"},te=["src","alt"],oe=["src"],ae={key:2,class:"text-sm mt-2 opacity-90 font-bold"},re={class:"p-6"},ne={class:"absolute inset-y-0 right-0 flex items-center pr-4"},ie={key:0,class:"animate-spin rounded-full h-5 w-5 border-b-2 border-[#2EC07E]"},le={key:0,class:"mt-4 flex items-start gap-2 rounded-md border border-red-200 bg-red-50 p-3 text-sm text-red-700"},ce={key:1,class:"mt-4 text-gray-500"},ue={key:2,class:"mt-4 space-y-2"},de=["onClick"],he={class:"flex items-center gap-3"},me={class:"flex-shrink-0"},pe=["src","alt"],ve={key:1,class:"w-10 h-10 bg-gray-200 rounded-full flex items-center justify-center"},fe={class:"text-left"},_e={class:"font-medium text-gray-900"},be={key:0,class:"text-sm text-gray-500"},ye={class:"mt-6 flex items-start rounded-sm"},ge=["disabled"],we={key:0},xe={key:1},ke=E({__name:"switch-user",setup(Ce){M({title:"Changer de profil"});const v=Q(),A=C(),V=X(),P=B(),R=I(),w=c(!1),x=c(null);O(async()=>{if(P.roles.length===0)try{await g("/api/me/roles-permissions")}catch{}if(!await V.hasRoleAsync("ROLE_ALLOWED_TO_SWITCH")){R.push("/app");return}w.value=!0,await U(),x.value?.querySelector("input")?.focus()});const u=T(()=>A.getActiveClub),k=T(()=>!u.value||u.value.unique_name==="vpdive"),f=c(!1),y=c(!1),h=c(""),d=c(null),l=c(""),_=c([]);N(h,async o=>{if(l.value="",o.trim().length>=2){f.value=!0;try{const e=await g("/api/search/user",{method:"POST",data:{query:o,route:"switch_user"}});e&&(_.value=Array.isArray(e)?e:[])}catch(e){_.value=[],l.value="La recherche de membres a échoué. Merci de réessayer.",console.error("switch-user: /api/search/user",e)}finally{f.value=!1}}else _.value=[]});const j=o=>{l.value="",d.value=o},L=async()=>{y.value=!0,l.value="";try{if(d.value!==null){const o=await g("/api/switch_user",{method:"POST",data:{userSocket:d.value}});if(!o?.switched_to?.token){l.value="Le changement de profil a échoué : aucun jeton n'a été renvoyé.";return}const{getAuthToken:e,setAuthToken:i}=H(),a=e()||"";localStorage.setItem("old-token",a),i(o.switched_to.token),await C().load(),window.location.href=v.public.baseUrl+"app"}}catch(o){const e=o?.response?.status??o?.statusCode,i=o?.data?.error??o?.response?._data?.error;l.value=e===404?"Ce membre est introuvable côté serveur (jeton inconnu ou adhésion inactive). Merci de relancer la recherche.":i||"Le changement de profil a échoué. Merci de réessayer.",console.error("switch-user: /api/switch_user",e,i,o)}finally{y.value=!1}};return(o,e)=>{const i=q;return s(w)?(t(),n("div",Z,[r("div",ee,[r("div",se,[s(u)?.logo&&!s(k)?(t(),n("img",{key:0,src:s(v).public.vpdivePublic+s(u).logo,alt:s(u).name,class:"w-20 h-20 mx-auto mb-4 rounded-full"},null,8,te)):(t(),n("img",{key:1,src:s(v).public.baseUrl+"logo.png",alt:"VPDive",class:"w-20 h-20 mx-auto mb-4 object-contain"},null,8,oe)),e[3]||(e[3]=r("h1",{class:"text-2xl font-bold"},"Switcher de profil utilisateur",-1)),s(u)&&!s(k)?(t(),n("p",ae,b(s(u).name),1)):m("",!0)]),r("div",re,[e[6]||(e[6]=r("h2",{class:"text-md font-semibold mb-3"},"Saisir les premières lettres du nom du membre, puis selectionnez le dans la liste",-1)),r("div",{ref_key:"searchWrapper",ref:x,class:"relative"},[p(K,{modelValue:s(h),"onUpdate:modelValue":e[0]||(e[0]=a=>W(h)?h.value=a:null),placeholder:"Rechercher un utilisateur...",type:"text","hide-icon":!0},null,8,["modelValue"]),r("div",ne,[s(f)?(t(),n("div",ie)):s(h)?(t(),n("button",{key:1,onClick:e[1]||(e[1]=a=>h.value=""),class:"text-gray-500 hover:text-gray-700"},[p(i,{name:"heroicons:x-circle",class:"w-5 h-5"})])):(t(),S(i,{key:2,name:"heroicons:magnifying-glass",class:"w-5 h-5 text-gray-400"}))])],512),s(l)?(t(),n("div",le,[p(i,{name:"heroicons:exclamation-triangle",class:"w-5 h-5 flex-shrink-0"}),r("span",null,b(s(l)),1)])):m("",!0),s(f)?(t(),n("div",ce,"Recherche en cours...")):(t(),n("ul",ue,[(t(!0),n(z,null,$(s(_),a=>(t(),n("li",{key:a.id},[r("button",{onClick:D=>j(a.id),class:Y([{"bg-green-100 border-green-500":s(d)===a.id,"border-gray-300 hover:bg-gray-50":s(d)!==a.id},"w-full py-3 px-4 border-2 rounded-md transition-all duration-300 flex items-center justify-between"])},[r("div",he,[r("div",me,[a.profile_picture?(t(),n("img",{key:0,src:s(v).public.vpdivePublic+a.profile_picture,alt:a.value,class:"w-10 h-10 object-cover rounded-full"},null,8,pe)):(t(),n("div",ve,[p(i,{name:"heroicons:user",class:"w-6 h-6 text-gray-400"})]))]),r("div",fe,[r("div",_e,b(a.value),1),a.club?.name?(t(),n("div",be,b(a.club.name),1)):m("",!0)])]),s(d)===a.id?(t(),S(i,{key:0,name:"heroicons:check-circle",class:"w-6 h-6 text-green-600 flex-shrink-0"})):m("",!0)],10,de)]))),128))])),r("div",ye,[r("button",{onClick:e[2]||(e[2]=a=>("navigateTo"in o?o.navigateTo:s(G))("/auth/logout")),class:"w-full py-3 mr-4 text-[#1b2441] rounded-md transition-all duration-300",style:{backgroundColor:"white",border:"1px solid #1b2441"}},[...e[4]||(e[4]=[r("span",null,"Déconnexion",-1)])]),r("button",{onClick:L,class:"w-full py-3 text-white rounded-md transition-all duration-300",style:{backgroundColor:"#1b2441"},disabled:s(d)===null},[s(y)?(t(),n("span",we,[p(i,{name:"heroicons:arrow-path",class:"w-5 h-5 animate-spin inline-block mr-2"}),e[5]||(e[5]=F(" Chargement... ",-1))])):(t(),n("span",xe,"Continuer"))],8,ge)])])])])):m("",!0)}}}),Ve=J(ke,[["__scopeId","data-v-246ee1fc"]]);export{Ve as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.