1import{_ as g}from"./BsqTxom4.js";import{_ as V}from"./DOH6MfcC.js";import{r as v,u as F,c as h,a as y,b as s,d as _,w as z,e as N,f as A,v as k,g as O,h as I,t as L,i as E,_ as M,j as x,n as b,o as w}from"#entry";import"./pAYh3yWb.js";import"./CaVVEZRR.js";import"./D-GNixRz.js";import"./GyODDOTC.js";import"./C0aY1EV-.js";const j={class:"pt-32 min-h-screen bg-gray-50"},S={class:"max-w-md mx-auto px-4 py-12"},q={class:"bg-white rounded-xl shadow-lg p-8"},B={class:"flex items-center justify-between"},T={class:"flex items-center"},G=["disabled"],U={key:0},$={key:1},W={key:0,class:"bg-red-50 border border-red-200 rounded-lg p-4"},H={class:"text-red-600 text-sm"},J=["disabled"],K={class:"mt-6 text-center"},Q={class:"text-gray-600"},re={__name:"login",setup(X){const f=v(""),u=v(""),C=v(!1),d=v(!1),r=v(""),D=async o=>{console.log("ð Iniciando redirección por rol..."),console.log("ð¤ User ID:",o);try{console.log("ð Obteniendo Firestore...");const{$firestore:e}=x();console.log("â
Firestore obtenido:",e?"SÃ":"NO");const{doc:i,getDoc:l}=await g(async()=>{const{doc:n,getDoc:t}=await import("#entry").then(c=>c.aC);return{doc:n,getDoc:t}},[],import.meta.url);console.log("ð Buscando documento de usuario...");const a=await l(i(e,"users",o));if(console.log("ð Documento existe:",a.exists()),a.exists()){const n=a.data();console.log("ð¤ Datos del usuario completos:",n),console.log("ð Campos disponibles:",Object.keys(n));const t=n.role||n.userRole||n.role_type||"cliente";console.log("ð Rol detectado:",t),console.log("ð Verificación de rol admin:",t==="admin"),console.log("â° Actualizando último login...");const{setDoc:c}=await g(async()=>{const{setDoc:m}=await import("#entry").then(p=>p.aC);return{setDoc:m}},[],import.meta.url);await c(i(e,"users",o),{...n,lastLogin:new Date},{merge:!0}),console.log("â
Ãltimo login actualizado"),console.log("ð¯ Redirigiendo según rol:",t),console.log("ð Comparación de roles:"),console.log(' - role === "admin":',t==="admin"),console.log(' - role === "superadmin":',t==="superadmin"),console.log(" - typeof role:",typeof t),console.log(" - role.trim():",t.trim()),t==="admin"||t==="superadmin"?(console.log("ð Redirigiendo a admin..."),await b("/admin")):t==="vendedor"?(console.log("ð¼ Redirigiendo a vendedor..."),await b("/vendedor")):(console.log("ð¤ Redirigiendo a cliente (rol no reconocido):",t),await b("/cliente"))}else{console.log("ð Documento de usuario no existe, creando...");const{setDoc:n}=await g(async()=>{const{setDoc:m}=await import("#entry").then(p=>p.aC);return{setDoc:m}},[],import.meta.url),{$firebaseAuth:t}=x(),c=t?.currentUser;await n(i(e,"users",o),{email:c?.email,displayName:c?.displayName,role:"cliente",createdAt:new Date,lastLogin:new Date}),console.log("â
Documento de usuario creado"),console.log("ð¤ Redirigiendo a cliente (nuevo usuario)..."),await b("/cliente")}}catch(e){console.error("â Error verificando rol de usuario:",e),console.error("ð Código de error:",e.code),console.error("ð Mensaje de error:",e.message),console.log("ð Redirigiendo a cliente por defecto (error)..."),await b("/cliente")}},R=async()=>{console.log("ð Iniciando proceso de login..."),console.log("ð§ Email ingresado:",f.value),console.log("ð Contraseña ingresada:",u.value?"***"+u.value.slice(-2):"VACÃA"),d.value=!0,r.value="";try{console.log("ð Obteniendo Firebase Auth...");const{$firebaseAuth:o,$ensureFirebaseAuth:e}=x(),i=o||(typeof e=="function"?await e():null);if(!i)throw new Error("Firebase Auth no disponible");const{signInWithEmailAndPassword:l}=await g(async()=>{const{signInWithEmailAndPassword:n}=await import("#entry").then(t=>t.aD);return{signInWithEmailAndPassword:n}},[],import.meta.url);console.log("â
Firebase Auth obtenido:",i?"SÃ":"NO"),console.log("ð Firebase Auth object:",i),console.log("ð¡ Intentando autenticación con Firebase..."),console.log("ð URL de autenticación: https://identitytoolkit.googleapis.com/v1/accounts:signInWithPassword");const a=await l(i,f.value,u.value);console.log("â
Autenticación exitosa!"),console.log("ð¤ Usuario autenticado:",a.user.uid),console.log("ð§ Email del usuario:",a.user.email),console.log("ð Redirigiendo según rol..."),await D(a.user.uid)}catch(o){switch(console.error("â Error en login:",o),console.error("ð Código de error:",o.code),console.error("ð Mensaje de error:",o.message),console.error("ð Error stack:",o.stack),o.code==="auth/network-request-failed"&&(console.error("ð Error de red detectado!"),console.error("ð Posibles causas:"),console.error(" - Conexión a internet interrumpida"),console.error(" - Firebase API no dis
1ponible"),console.error(" - Configuración incorrecta de Firebase"),console.error(" - CORS o polÃticas de seguridad")),o.code){case"auth/user-not-found":r.value="No existe una cuenta con este correo electrónico.";break;case"auth/wrong-password":r.value="La contraseña es incorrecta.";break;case"auth/invalid-email":r.value="El correo electrónico no es válido.";break;case"auth/too-many-requests":r.value="Demasiados intentos fallidos. Intenta más tarde.";break;case"auth/network-request-failed":r.value="Error de conexión. Verifica tu conexión a internet e intenta nuevamente.";break;default:r.value="Error al iniciar sesión. Intenta nuevamente."}}finally{console.log("ð Finalizando proceso de login..."),d.value=!1}},P=async()=>{d.value=!0,r.value="";try{const{$firebaseAuth:o,$ensureFirebaseAuth:e}=x(),i=o||(typeof e=="function"?await e():null);if(!i)throw new Error("Firebase Auth no disponible");const{signInWithPopup:l,GoogleAuthProvider:a}=await g(async()=>{const{signInWithPopup:c,GoogleAuthProvider:m}=await import("#entry").then(p=>p.aD);return{signInWithPopup:c,GoogleAuthProvider:m}},[],import.meta.url),n=new a;n.setCustomParameters({prompt:"select_account"});const t=await l(i,n);await D(t.user.uid)}catch(o){console.error("Error en login con Google:",o);const e=o?.code;e==="auth/popup-closed-by-user"||e==="auth/cancelled-popup-request"?r.value="Cerraste la ventana de Google. Intenta nuevamente.":e==="auth/popup-blocked"?r.value="El navegador bloqueó la ventana emergente. Permite popups para este sitio.":e==="auth/unauthorized-domain"?r.value="Este dominio no está autorizado en Firebase Auth. Revisa Authorized domains.":r.value="Error al iniciar sesión con Google. Intenta nuevamente."}finally{d.value=!1}};return F({title:"Iniciar Sesión - Autopiezas360",meta:[{name:"description",content:"Inicia sesión en tu cuenta de Autopiezas360 para acceder a repuestos originales y ofertas exclusivas."}]}),(o,e)=>{const i=V,l=M;return w(),h("div",null,[y(i),s("main",j,[s("div",S,[s("div",q,[e[10]||(e[10]=_('<div class="text-center mb-8"><div class="w-16 h-16 bg-blue-600 rounded-xl flex items-center justify-center mx-auto mb-4"><span class="text-white font-bold text-2xl">A</span></div><h1 class="text-2xl font-bold text-gray-800">Iniciar Sesión</h1><p class="text-gray-600 mt-2">Accede a tu cuenta de Autopiezas360</p></div>',1)),s("form",{onSubmit:z(R,["prevent"]),class:"space-y-6"},[s("div",null,[e[3]||(e[3]=s("label",{for:"email",class:"block text-sm font-medium text-gray-700 mb-2"}," Correo electrónico ",-1)),A(s("input",{id:"email","onUpdate:modelValue":e[0]||(e[0]=a=>f.value=a),type:"email",required:"",class:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"[email protected]"},null,512),[[k,f.value]])]),s("div",null,[e[4]||(e[4]=s("label",{for:"password",class:"block text-sm font-medium text-gray-700 mb-2"}," Contraseña ",-1)),A(s("input",{id:"password","onUpdate:modelValue":e[1]||(e[1]=a=>u.value=a),type:"password",required:"",class:"w-full px-3 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-blue-500",placeholder:"â¢â¢â¢â¢â¢â¢â¢â¢"},null,512),[[k,u.value]])]),s("div",B,[s("label",T,[A(s("input",{"onUpdate:modelValue":e[2]||(e[2]=a=>C.value=a),type:"checkbox",class:"rounded border-gray-300 text-blue-600 focus:ring-blue-500"},null,512),[[O,C.value]]),e[5]||(e[5]=s("span",{class:"ml-2 text-sm text-gray-600"},"Recordar sesión",-1))]),y(l,{to:"/contacto",class:"text-sm text-blue-600 hover:text-blue-700"},{default:I(()=>[...e[6]||(e[6]=[E(" ¿Olvidaste tu contraseña? ",-1)])]),_:1})]),s("button",{type:"submit",disabled:d.value,class:"w-full bg-blue-600 text-white py-3 px-4 rounded-lg hover:bg-blue-700 disabled:bg-gray-400 disabled:cursor-not-allowed transition-colors font-medium"},[d.value?(w(),h("span",U,"Iniciando sesión...")):(w(),h("span",$,"Iniciar Sesión"))],8,G),r.value?(w(),h("div",W,[s("p",H,L(r.value),1)])):N("",!0)],32),e[11]||(e[11]=_('<div class="my-6"><div class="relative"><div class="absolute inset-0 flex items-center"><div class="w-full border-t border-gray-300"></div></div><div class="relative flex justify-center text-sm"><span class="px-2 bg-white text-gray-500">O continúa con</span></div></div></div>',1)),s("button",{onClick:P,disabled:d.value,class:"w-full bg-white border border-gray-300 text-gray-700 py-3 px-4 roun
1ded-lg hover:bg-gray-50 disabled:bg-gray-100 disabled:cursor-not-allowed transition-colors font-medium flex items-center justify-center space-x-2"},[...e[7]||(e[7]=[_('<svg class="w-5 h-5" viewBox="0 0 24 24"><path fill="#4285F4" d="M22.56 12.25c0-.78-.07-1.53-.2-2.25H12v4.26h5.92c-.26 1.37-1.04 2.53-2.21 3.31v2.77h3.57c2.08-1.92 3.28-4.74 3.28-8.09z"></path><path fill="#34A853" d="M12 23c2.97 0 5.46-.98 7.28-2.66l-3.57-2.77c-.98.66-2.23 1.06-3.71 1.06-2.86 0-5.29-1.93-6.16-4.53H2.18v2.84C3.99 20.53 7.7 23 12 23z"></path><path fill="#FBBC05" d="M5.84 14.09c-.22-.66-.35-1.36-.35-2.09s.13-1.43.35-2.09V7.07H2.18C1.43 8.55 1 10.22 1 12s.43 3.45 1.18 4.93l2.85-2.22.81-.62z"></path><path fill="#EA4335" d="M12 5.38c1.62 0 3.06.56 4.21 1.64l3.15-3.15C17.45 2.09 14.97 1 12 1 7.7 1 3.99 3.47 2.18 7.07l3.66 2.84c.87-2.6 3.3-4.53 6.16-4.53z"></path></svg><span>Continuar con Google</span>',2)])],8,J),s("div",K,[s("p",Q,[e[9]||(e[9]=E(" ¿No tienes cuenta? ",-1)),y(l,{to:"/registro",class:"text-blue-600 hover:text-blue-700 font-medium"},{default:I(()=>[...e[8]||(e[8]=[E(" RegÃstrate aquà ",-1)])]),_:1})])])])])])])}}};export{re 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.