import{_ as V,u as S,l as P,d as f,g as A,r as l,i as M,o,a as e,t as i,s as y,c as r,F as T,n as D,j as F,e as w,T as N,w as B,b,v as g,p as U,k as $}from"./index-bWZW5iIe.js";import{c as q,a as j}from"./modules-B2gpx2mZ.js";import{C as I}from"./ClientLayout-DaVfer7j.js";import{L as z}from"./LoadingSpinner-3L2VeslL.js";import{E as R}from"./ErrorMessage-Bb2MEm24.js";const G={class:"card profile-card"},H={class:"profile-avatar"},J={class:"profile-info"},K={class:"profile-name"},O={class:"profile-email"},Q={class:"card"},W={key:1,class:"no-photos"},X={key:2,class:"expediente-grid"},Y=["src","alt"],Z={class:"photo-info"},ss={key:0},es={class:"card"},ts={key:0,class:"modal-overlay"},as={class:"modal-card"},os={class:"input-group"},ns={class:"input-group"},rs={class:"input-group"},ls={key:1,class:"success-text"},is={class:"modal-actions"},ds=["disabled"],us={__name:"PerfilView",setup(ps){const C=M(),p=S(),d=l(!1),c=l(!1),m=l([]),_=l(!1),u=l(""),v=l(!1),a=$({current_password:"",new_password:"",confirm_password:""});P(x);async function x(){_.value=!0;try{const n=await q.getExpediente();m.value=n.data||[]}catch{m.value=[]}finally{_.value=!1}}function k(n){return n?new Date(n).toLocaleDateString("es-ES",{day:"2-digit",month:"short",year:"numeric"}):""}const h=U(()=>(p.user?.name||"").split(" ").map(s=>s[0]).join("").substring(0,2).toUpperCase()||"CL"),E=async()=>{await p.logout(),C.push("/login")},L=async()=>{if(u.value="",v.value=!1,a.new_password!==a.confirm_password){u.value="Las contraseñas no coinciden";return}c.value=!0;try{await j.changePassword(a.current_password,a.new_password),v.value=!0,setTimeout(()=>{d.value=!1,a.current_password="",a.new_password="",a.confirm_password="",v.value=!1},1500)}catch(n){u.value=n.response?.data?.message||"Error al cambiar contraseña"}finally{c.value=!1}};return(n,s)=>(o(),f(I,null,{default:A(()=>[s[13]||(s[13]=e("h2",{style:{margin:"0 0 5px 0","font-size":"22px"}},"Perfil",-1)),s[14]||(s[14]=e("p",{class:"title-sm",style:{"margin-top":"0"}},"Tu información",-1)),e("div",G,[e("div",H,i(h.value),1),e("div",J,[e("p",K,i(y(p).user?.name),1),e("p",O,i(y(p).user?.email),1)])]),e("div",Q,[s[6]||(s[6]=e("h3",{class:"title-sm",style:{"margin-top":"0"}},"Mi Expediente Visual",-1)),s[7]||(s[7]=e("p",{class:"expediente-desc"},"Fotos de tus cortes anteriores",-1)),_.value?(o(),f(z,{key:0})):m.value.length===0?(o(),r("div",W,"Aún no tenés fotos en tu expediente")):(o(),r("div",X,[(o(!0),r(T,null,D(m.value,t=>(o(),r("div",{key:t.id,class:"expediente-photo"},[e("img",{src:t.url,alt:`Foto ${t.id}`},null,8,Y),e("div",Z,[F(i(k(t.taken_at))+" ",1),t.appointment?.service?(o(),r("span",ss," • "+i(t.appointment.service.name),1)):w("",!0)])]))),128))]))]),e("div",es,[s[8]||(s[8]=e("h3",{class:"title-sm",style:{"margin-top":"0"}},"Acciones",-1)),e("button",{onClick:s[0]||(s[0]=t=>d.value=!0),class:"btn btn-outline",style:{"margin-bottom":"12px"}}," Cambiar Contraseña "),e("button",{onClick:E,class:"btn btn-outline",style:{background:"transparent","border-color":"var(--danger)",color:"var(--danger)"}}," Cerrar Sesión ")]),(o(),f(N,{to:"body"},[d.value?(o(),r("div",ts,[e("div",{class:"modal-backdrop",onClick:s[1]||(s[1]=t=>d.value=!1)}),e("div",as,[s[12]||(s[12]=e("h3",{class:"modal-title"},"Cambiar Contraseña",-1)),e("form",{onSubmit:B(L,["prevent"])},[e("div",os,[s[9]||(s[9]=e("label",null,"Contraseña Actual",-1)),b(e("input",{"onUpdate:modelValue":s[2]||(s[2]=t=>a.current_password=t),type:"password",class:"input-control",required:""},null,512),[[g,a.current_password]])]),e("div",ns,[s[10]||(s[10]=e("label",null,"Nueva Contraseña",-1)),b(e("input",{"onUpdate:modelValue":s[3]||(s[3]=t=>a.new_password=t),type:"password",class:"input-control",required:"",minlength:"6"},null,512),[[g,a.new_password]])]),e("div",rs,[s[11]||(s[11]=e("label",null,"Confirmar Nueva",-1)),b(e("input",{"onUpdate:modelValue":s[4]||(s[4]=t=>a.confirm_password=t),type:"password",class:"input-control",required:""},null,512),[[g,a.confirm_password]])]),u.value?(o(),f(R,{key:0,message:u.value},null,8,["message"])):w("",!0),v.value?(o(),r("p",ls,"Contraseña cambiada exitosamente")):w("",!0),e("div",is,[e("button",{type:"button",onClick:s[5]||(s[5]=t=>d.value=!1),class:"btn btn-outline btn-sm"},"Cancelar"),e("button",{type:"submit",disabled:c.value,class:"btn btn-gold btn-sm"},i(c.value?"Cambiando...":"Cambiar"),9,ds)])],32)])])):w("",!0)]))]),_:1}))}},_s=V(us,[["__scopeId","data-v-ae5c4e39"]]);export{_s as default};
