PageSourceSearch

https://repuestos-d6c3d.firebaseapp.com/_nuxt/5MERy-2y.js

js repuestos-d6c3d.firebaseapp.com collected 2026-10-03 08:14:23 UTC 13,001 bytes, 1 lines download raw bytes

1import{_ as A}from"./BsqTxom4.js";import{u as F,s as I,r as u,l as H,q as O,c as p,b as e,e as L,f as n,v as y,m as l,y as E,z as V,F as G,x as W,d as J,w as Q,g as K,j,o as c,t as i,p as X,n as Y}from"#entry";const Z={class:"mb-8"},ee={class:"flex justify-between items-center"},te={class:"bg-white rounded-xl shadow-lg p-6 mb-8"},se={class:"grid grid-cols-1 md:grid-cols-4 gap-4"},oe={class:"bg-white rounded-xl shadow-lg overflow-hidden"},re={class:"overflow-x-auto"},le={class:"w-full"},ae={class:"divide-y divide-gray-200"},ne={class:"py-4 px-6"},ie={class:"flex items-center space-x-3"},de={class:"w-10 h-10 bg-gradient-to-br from-blue-500 to-blue-600 rounded-full flex items-center justify-center"},ue={class:"text-sm font-bold text-white"},pe={class:"font-medium text-gray-900"},ce={class:"text-sm text-gray-500"},me={class:"py-4 px-6"},be={class:"text-sm text-gray-900"},xe={class:"py-4 px-6"},ge={class:"py-4 px-6 text-sm text-gray-500"},fe={class:"py-4 px-6 text-sm text-gray-500"},ve={class:"py-4 px-6"},ye={class:"text-sm text-gray-900"},we={class:"py-4 px-6"},he={class:"flex items-center space-x-2"},ke=["onClick"],Ce=["onClick"],_e=["onClick"],Ne={key:0,class:"text-center py-12"},Ue={key:0,class:"fixed inset-0 bg-black bg-opacity-60 flex items-center justify-center z-50 p-4 backdrop-blur-sm"},Ae={class:"bg-white rounded-2xl max-w-2xl w-full max-h-[95vh] overflow-hidden shadow-2xl"},Ee={class:"bg-gradient-to-r from-blue-600 to-blue-700 px-8 py-6"},Ve={class:"flex items-center justify-between"},De={class:"p-8"},Me={class:"grid grid-cols-1 md:grid-cols-2 gap-6"},Pe={class:"flex items-center"},Le={class:"flex justify-end space-x-3 pt-4 border-t"},je=["disabled"],Re={key:0},Te={key:1},Se={__name:"usuarios",setup(Be){F({title:"Gestión de Usuarios - AutoVentas360",meta:[{name:"robots",content:"noindex, nofollow"}]}),I();const C=u([]),m=u(!1),w=u(!1),b=u(""),x=u(""),h=u(""),r=u({displayName:"",email:"",phone:"",role:"cliente",password:"",subscribeNewsletter:!1}),D=H(()=>{let o=C.value;if(b.value){const t=b.value.toLowerCase();o=o.filter(s=>s.displayName?.toLowerCase().includes(t)||s.email.toLowerCase().includes(t))}return x.value&&(o=o.filter(t=>t.role===x.value)),o.sort((t,s)=>new Date(s.createdAt)-new Date(t.createdAt))}),M=o=>o?new Intl.DateTimeFormat("es-CL",{year:"numeric",month:"short",day:"numeric"}).format(new Date(o)):"Nunca",R=o=>({admin:"bg-red-100 text-red-800",vendedor:"bg-green-100 text-green-800",cliente:"bg-blue-100 text-blue-800"})[o]||"bg-gray-100 text-gray-800",T=o=>({admin:"Administrador",vendedor:"Vendedor",cliente:"Cliente"})[o]||o,B=()=>{b.value="",x.value="",h.value=""},$=o=>{Y(`/admin/usuarios/${o}`)},q=o=>{console.log("Editar usuario:",o.id)},S=o=>{console.log("Crear pedido para:",o.id)},z=async()=>{w.value=!0;try{const{$firebaseAuth:o,$firestore:t}=j(),{createUserWithEmailAndPassword:s,updateProfile:g}=await A(async()=>{const{createUserWithEmailAndPassword:a,updateProfile:f}=await import("#entry").then(v=>v.aD);return{createUserWithEmailAndPassword:a,updateProfile:f}},[],import.meta.url),{doc:_,setDoc:N,serverTimestamp:k}=await A(async()=>{const{doc:a,setDoc:f,serverTimestamp:v}=await import("#entry").then(U=>U.aC);return{doc:a,setDoc:f,serverTimestamp:v}},[],import.meta.url),d=await s(o,r.value.email,r.value.password);await g(d.user,{displayName:r.value.displayName}),await N(_(t,"users",d.user.uid),{email:r.value.email,displayName:r.value.displayName,phone:r.value.phone||"",role:r.value.role,subscribeNewsletter:r.value.subscribeNewsletter,createdAt:k(),lastLogin:k(),totalPedidos:0}),r.value={displayName:"",email:"",phone:"",role:"cliente",password:"",subscribeNewsletter:!1},m.value=!1,await P(),alert("Usuario creado exitosamente")}catch(o){console.error("Error creando usuario:",o),alert("Error al crear el usuario: "+o.message)}finally{w.value=!1}},P=async()=>{try{const{$firestore:o}=j(),{collection:t,getDocs:s,query:g,orderBy:_}=await A(async()=>{const{collection:d,getDocs:a,query:f,orderBy:v}=await import("#entry").then(U=>U.aC);return{collection:d,getDocs:a,query:f,orderBy:v}},[],import.meta.url),N=g(t(o,"users"),_("createdAt","desc")),k=await s(N);
1C.value=[],k.forEach(d=>{const a=d.data();C.value.push({id:d.id,email:a.email,displayName:a.displayName,phone:a.phone,role:a.role,subscribeNewsletter:a.subscribeNewsletter,createdAt:a.createdAt?.toDate()||new Date,lastLogin:a.lastLogin?.toDate()||null,totalPedidos:a.totalPedidos||0})})}catch(o){console.error("Error cargando usuarios:",o)}};return O(()=>{P()}),(o,t)=>(c(),p("div",null,[e("div",Z,[e("div",ee,[t[14]||(t[14]=e("div",null,[e("h1",{class:"text-3xl font-bold text-gray-900"},"Gestión de Usuarios"),e("p",{class:"text-gray-600 mt-2"},"Administra usuarios del sistema")],-1)),e("button",{onClick:t[0]||(t[0]=s=>m.value=!0),class:"px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors font-medium flex items-center space-x-2"},[...t[13]||(t[13]=[e("svg",{class:"w-5 h-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 6v6m0 0v6m0-6h6m-6 0H6"})],-1),e("span",null,"Crear Usuario",-1)])])])]),e("div",te,[e("div",se,[e("div",null,[t[15]||(t[15]=e("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Buscar",-1)),n(e("input",{"onUpdate:modelValue":t[1]||(t[1]=s=>E(b)?b.value=s:null),type:"text",placeholder:"Nombre, email...",class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},null,512),[[y,l(b)]])]),e("div",null,[t[17]||(t[17]=e("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Rol",-1)),n(e("select",{"onUpdate:modelValue":t[2]||(t[2]=s=>E(x)?x.value=s:null),class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},[...t[16]||(t[16]=[e("option",{value:""},"Todos los roles",-1),e("option",{value:"cliente"},"Cliente",-1),e("option",{value:"vendedor"},"Vendedor",-1),e("option",{value:"admin"},"Admin",-1)])],512),[[V,l(x)]])]),e("div",null,[t[19]||(t[19]=e("label",{class:"block text-sm font-medium text-gray-700 mb-2"},"Estado",-1)),n(e("select",{"onUpdate:modelValue":t[3]||(t[3]=s=>E(h)?h.value=s:null),class:"w-full px-4 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},[...t[18]||(t[18]=[e("option",{value:""},"Todos",-1),e("option",{value:"activo"},"Activo",-1),e("option",{value:"inactivo"},"Inactivo",-1)])],512),[[V,l(h)]])]),e("div",{class:"flex items-end"},[e("button",{onClick:B,class:"w-full px-4 py-2 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors"}," Limpiar Filtros ")])])]),e("div",oe,[e("div",re,[e("table",le,[t[20]||(t[20]=e("thead",{class:"bg-gray-50"},[e("tr",null,[e("th",{class:"text-left py-4 px-6 font-medium text-gray-700"},"Usuario"),e("th",{class:"text-left py-4 px-6 font-medium text-gray-700"},"Email"),e("th",{class:"text-left py-4 px-6 font-medium text-gray-700"},"Rol"),e("th",{class:"text-left py-4 px-6 font-medium text-gray-700"},"Registro"),e("th",{class:"text-left py-4 px-6 font-medium text-gray-700"},"Último Acceso"),e("th",{class:"text-left py-4 px-6 font-medium text-gray-700"},"Pedidos"),e("th",{class:"text-left py-4 px-6 font-medium text-gray-700"},"Acciones")])],-1)),e("tbody",ae,[(c(!0),p(G,null,W(l(D),s=>(c(),p("tr",{key:s.id,class:"hover:bg-gray-50"},[e("td",ne,[e("div",ie,[e("div",de,[e("span",ue,i(s.displayName?.charAt(0).toUpperCase()||"U"),1)]),e("div",null,[e("p",pe,i(s.displayName||"Sin nombre"),1),e("p",ce,i(s.phone||"Sin teléfono"),1)])])]),e("td",me,[e("p",be,i(s.email),1)]),e("td",xe,[e("span",{class:X(["inline-flex px-2 py-1 text-xs font-semibold rounded-full",R(s.role)])},i(T(s.role)),3)]),e("td",ge,i(M(s.createdAt)),1),e("td",fe,i(M(s.lastLogin)),1),e("td",ve,[e("span",ye,i(s.totalPedidos||0),1)]),e("td",we,[e("div",he,[e("button",{onClick:g=>$(s.id),class:"text-blue-600 hover:text-blue-700 text-sm font-medium"}," Ver ",8,ke),e("button",{onClick:g=>q(s),class:"text-green-600 hover:text-green-700 text-sm font-medium"}," Editar ",8,Ce),e("button",{onClick:g=>S(s),class:"text-purple-600 hover:text-purple-700 text-sm font-medium"}," Crear Pedido ",8,_e)])])]))),128))])])]),l(D).length===0?(c(),p("div",Ne,[t[21]||(t[21]=e("svg",{class:"w-16 h-16 text-gray-400 mx-auto mb-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197m13.5-9a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z"})],-1)),t[22]||(t[22]=e("h3",{class:"text-lg font-medium text-gray-900 mb-2"},"No hay usuarios",-1)),t[23]||(t[23]=e("p",{class:"text-gray-500 mb-4"},"Comienza creando el primer usuario",-1)),e("button",{onClick:t[4]||(t[4]=s=>m.value=!0),class:"px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors font-medium"}," Crear Usuario ")])):L("",!0)]),l(m)?(c(),p("div",Ue,[e("div",Ae,[e("div",Ee,[e("div",Ve,[t[25]||(t[25]=J('<div class="flex items-center space-x-4"><div class="w-12 h-12 bg-white bg-opacity-20 rounded-xl flex items-center justify-center"><svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path></svg></div><div><h2 class="text-2xl font-bold text-white">Crear Usuario</h2><p class="text-blue-100 mt-1">Registrar nuevo usuario en el sistema</p></div></div>',1)),e("button",{onClick:t[5]||(t[5]=s=>m.value=!1),class:"w-10 h-10 bg-white bg-opacity-20 hover:bg-opacity-30 rounded-xl flex items-center justify-center transition-all duration-200"},[...t[24]||(t[24]=[e("svg",{class:"w-6 h-6 text-white",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[e("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M6 18L18 6M6 6l12 12"})],-1)])])])]),e("div",De,[e("form",{onSubmit:Q(z,["prevent"]),class:"space-y-6"},[e("div",Me,[e("div",null,[t[26]||(t[26]=e("label",{class:"block text-sm font-medium text-gray-700 mb-2"}," Nombre completo * ",-1)),n(e("input",{"onUpdate:modelValue":t[6]||(t[6]=s=>l(r).displayName=s),type:"text",required:"",class:"w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"Juan Pérez"},null,512),[[y,l(r).displayName]])]),e("div",null,[t[27]||(t[27]=e("label",{class:"block text-sm font-medium text-gray-700 mb-2"}," Email * ",-1)),n(e("input",{"onUpdate:modelValue":t[7]||(t[7]=s=>l(r).email=s),type:"email",required:"",class:"w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"[email protected]"},null,512),[[y,l(r).email]])]),e("div",null,[t[28]||(t[28]=e("label",{class:"block text-sm font-medium text-gray-700 mb-2"}," Teléfono ",-1)),n(e("input",{"onUpdate:modelValue":t[8]||(t[8]=s=>l(r).phone=s),type:"tel",class:"w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"+56912345678"},null,512),[[y,l(r).phone]])]),e("div",null,[t[30]||(t[30]=e("label",{class:"block text-sm font-medium text-gray-700 mb-2"}," Rol * ",-1)),n(e("select",{"onUpdate:modelValue":t[9]||(t[9]=s=>l(r).role=s),required:"",class:"w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent"},[...t[29]||(t[29]=[e("option",{value:"cliente"},"Cliente",-1),e("option",{value:"vendedor"},"Vendedor",-1),e("option",{value:"admin"},"Administrador",-1)])],512),[[V,l(r).role]])])]),e("div",null,[t[31]||(t[31]=e("label",{class:"block text-sm font-medium text-gray-700 mb-2"}," Contraseña temporal * ",-1)),n(e("input",{"onUpdate:modelValue":t[10]||(t[10]=s=>l(r).password=s),type:"password",required:"",class:"w-full px-4 py-3 border border-gray-300 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-transparent",placeholder:"Mínimo 6 caracteres"},null,512),[[y,l(r).password]]),t[32]||(t[32]=e("p",{class:"text-xs text-gray-500 mt-1"},"El usuario podrá cambiar su contraseña después",-1))]),e("div",Pe,[n(e("input",{"onUpdate:modelValue":t[11]||(t[11]=s=>l(r).subscribeNewsletter=s),type:"checkbox",class:"w-4 h-4 text-blue-600 border-gray-300 rounded focus:ring-blue-500"},null,512),[[K,l(r).subscribeNewsletter]]),t[33]||(t[33]=e("label",{class:"ml-2 text-sm text-gray-700"}," Suscribir al newsletter ",-1))]),e("div",Le,[e("button",{type:"button",onClick:t[12]||(t[12]=s=>m.value=!1),class:"px-6 py-3 border border-gray-300 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors"}," Cancelar "),e("button",{type:"submit",disabled:l(w),class:"px-6 py-3 bg-blue-600 text-white rounded-lg hover:bg-blue-700 disabled:bg-gray-400 transition-colors"},[l(w)?(c(),p("span",Re,"Creando...")):(c(),p("span",Te,"Crear Usuario"))],8,je)])],32)])])])):L("",!0)]))}};export{Se 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.