1import{_ as se}from"./BsqTxom4.js";import{u as oe,s as re,j as S,l as ae,r as v,q as ne,c as b,b as e,e as ie,t as a,m as d,p as I,a as D,h as N,d as P,F as de,x as le,_ as ce,o as w,i as ue,n as ge}from"#entry";const pe={class:"mb-8"},me={class:"mt-1 text-sm text-slate-600"},xe={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8"},he={class:"bg-white rounded-lg border border-slate-200/80 p-6"},fe={class:"flex items-center justify-between"},ve={class:"text-3xl font-bold text-gray-900 mt-1"},be={class:"text-xs text-blue-600 mt-1"},we={class:"bg-white rounded-lg border border-slate-200/80 p-6"},ye={class:"flex items-center justify-between"},_e={class:"text-3xl font-bold text-gray-900 mt-1"},ke={class:"text-xs text-orange-600 mt-1"},Me={class:"bg-white rounded-lg border border-slate-200/80 p-6"},Ae={class:"flex items-center justify-between"},Ce={class:"text-3xl font-bold text-gray-900 mt-1"},De={class:"text-xs text-green-600 mt-1"},Ne={class:"bg-white rounded-lg border border-slate-200/80 p-6"},Pe={class:"flex items-center justify-between"},je={class:"text-3xl font-bold text-gray-900 mt-1"},Ee={class:"grid grid-cols-1 md:grid-cols-3 gap-6 mb-8"},Be={key:0,class:"bg-white rounded-xl shadow-lg p-6 mb-8 border border-gray-100"},Ve={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},$e={class:"bg-white rounded-xl shadow-lg p-6"},Se={class:"flex justify-between items-center mb-6"},Ie={class:"overflow-x-auto"},Le={class:"w-full"},ze={class:"py-3 px-4"},Ue={class:"font-medium text-gray-900"},Te={class:"text-sm text-gray-500 truncate max-w-xs"},He={class:"py-3 px-4"},Re={class:"font-medium text-gray-900"},qe={class:"text-sm text-gray-500"},Ye={class:"py-3 px-4"},Ge={class:"py-3 px-4 text-sm text-gray-500"},Oe={class:"py-3 px-4"},Qe=["onClick"],Ze={__name:"index",setup(Je){oe({title:"Panel Admin - AutoVentas360",meta:[{name:"robots",content:"noindex, nofollow"}]}),re();const{$firebaseAuth:L}=S(),z=ae(()=>{const r=L?.currentUser;return r?.displayName||r?.email||"Admin"}),f=v(!1),U=v(!1),T=v(!1),l=v({totalUsuarios:0,usuariosNuevos:0,pedidosActivos:0,pendientesPago:0,pedidosCompletados:0,completadosMes:0,ingresosMes:0,crecimientoIngresos:0}),y=v([]),H=[{key:"solicitud_enviada",titulo:"Solicitud Enviada"},{key:"producto_encontrado",titulo:"Producto Encontrado"},{key:"pendiente_pago",titulo:"Pendiente de Pago"},{key:"producto_viajando",titulo:"Producto Viajando"},{key:"llegada_chile",titulo:"Llegada a Chile"},{key:"despachando",titulo:"Despachando"},{key:"entregado",titulo:"Entregado"}],R=r=>r?new Intl.DateTimeFormat("es-CL",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(r)):"No disponible",q=r=>({solicitud_enviada:"bg-yellow-100 text-yellow-800",producto_encontrado:"bg-blue-100 text-blue-800",pendiente_pago:"bg-orange-100 text-orange-800",producto_viajando:"bg-purple-100 text-purple-800",llegada_chile:"bg-indigo-100 text-indigo-800",despachando:"bg-pink-100 text-pink-800",entregado:"bg-green-100 text-green-800"})[r]||"bg-gray-100 text-gray-800",Y=r=>{const t=H.find(c=>c.key===r);return t?t.titulo:r},G=r=>{ge(`/admin/pedidos/${r}`)},O=async()=>{try{const{$firestore:r}=S(),{collection:t,getDocs:c,query:n,orderBy:j,limit:Q,where:Ke}=await se(async()=>{const{collection:s,getDocs:o,query:i,orderBy:g,limit:h,where:ee}=await import("#entry").then(te=>te.aC);return{collection:s,getDocs:o,query:i,orderBy:g,limit:h,where:ee}},[],import.meta.url),J=n(t(r,"pedidos"),j("createdAt","desc"),Q(5)),K=await c(J);
1y.value=[],K.forEach(s=>{const o=s.data();y.value.push({id:s.id,numero:o.numero,descripcion:o.descripcion,userName:o.userName,userEmail:o.userEmail,estado:o.estado,createdAt:o.createdAt?.toDate()||new Date})});const E=await c(t(r,"users")),B=E.size,p=new Date,V=new Date(p.getFullYear(),p.getMonth(),1);let _=0;E.forEach(s=>{const o=s.data();let i=null;o.createdAt&&(o.createdAt.toDate?i=o.createdAt.toDate():o.createdAt instanceof Date?i=o.createdAt:typeof o.createdAt=="string"?i=new Date(o.createdAt):o.createdAt.seconds&&(i=new Date(o.createdAt.seconds*1e3))),i&&!isNaN(i.getTime())&&i>=V&&_++});const $=await c(t(r,"pedidos"));let k=0,M=0,A=0,C=0,m=0,u=0;const W=new Date(p.getFullYear(),p.getMonth()-1,1),X=new Date(p.getFullYear(),p.getMonth(),0),Z=s=>s?s.toDate?s.toDate():s instanceof Date?s:typeof s=="string"?new Date(s):s.seconds?new Date(s.seconds*1e3):null:null,F=s=>typeof s=="number"&&!isNaN(s)&&s>0?s:0;$.forEach(s=>{const o=s.data(),i=o.estado||o.status||"",g=Z(o.createdAt),h=F(o.price);i!=="entregado"&&i!=="cancelado"&&k++,i==="pendiente_pago"&&M++,i==="entregado"&&(A++,g&&!isNaN(g.getTime())&&(g>=V&&(C++,h>0&&(m+=h)),g>=W&&g<=X&&h>0&&(u+=h)))});let x=0;u>0?x=Math.round((m-u)/u*100):m>0&&u===0?x=100:m===0&&u>0&&(x=-100),l.value={totalUsuarios:B,usuariosNuevos:_,pedidosActivos:k,pendientesPago:M,pedidosCompletados:A,completadosMes:C,ingresosMes:m,crecimientoIngresos:x},console.log("ð EstadÃsticas cargadas desde Firestore:",{totalUsuarios:B,usuariosNuevos:_,pedidosActivos:k,pendientesPago:M,pedidosCompletados:A,completadosMes:C,ingresosMes:`$${m.toLocaleString()}`,ingresosMesAnterior:`$${u.toLocaleString()}`,crecimientoIngresos:`${x>=0?"+":""}${x}%`,totalPedidos:$.size})}catch(r){console.error("Error cargando estadÃsticas:",r),l.value={totalUsuarios:0,usuariosNuevos:0,pedidosActivos:0,pendientesPago:0,pedidosCompletados:0,completadosMes:0,ingresosMes:0,crecimientoIngresos:0}}};return ne(()=>{O()}),(r,t)=>{const c=ce;return w(),b("div",null,[e("header",pe,[t[3]||(t[3]=e("p",{class:"text-[11px] font-semibold uppercase tracking-[0.2em] text-slate-500 mb-2"},"Admin",-1)),t[4]||(t[4]=e("h2",{class:"text-2xl font-semibold text-slate-900 tracking-tight"},"Panel de administración",-1)),e("p",me,"Bienvenido, "+a(d(z)),1)]),e("div",xe,[e("div",he,[e("div",fe,[e("div",null,[t[5]||(t[5]=e("p",{class:"text-sm font-medium text-gray-600"},"Total Usuarios",-1)),e("p",ve,a(d(l).totalUsuarios),1),e("p",be,a(d(l).usuariosNuevos)+" nuevos este mes",1)]),t[6]||(t[6]=e("div",{class:"p-3 bg-gradient-to-br from-blue-500 to-blue-600 rounded-xl shadow-lg"},[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:"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))])]),e("div",we,[e("div",ye,[e("div",null,[t[7]||(t[7]=e("p",{class:"text-sm font-medium text-gray-600"},"Pedidos Activos",-1)),e("p",_e,a(d(l).pedidosActivos),1),e("p",ke,a(d(l).pendientesPago)+" pendientes de pago",1)]),t[8]||(t[8]=e("div",{class:"p-3 bg-gradient-to-br from-orange-500 to-orange-600 rounded-xl shadow-lg"},[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:"M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})])],-1))])]),e("div",Me,[e("div",Ae,[e("div",null,[t[9]||(t[9]=e("p",{class:"text-sm font-medium text-gray-600"},"Pedidos Completados",-1)),e("p",Ce,a(d(l).pedidosCompletados),1),e("p",De,a(d(l).completadosMes)+" este mes",1)]),t[10]||(t[10]=e("div",{class:"p-3 bg-gradient-to-br from-green-500 to-green-600 rounded-xl shadow-lg"},[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:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})])],-1))])]),e("div",Ne,[e("div",Pe,[e("div",null,[t[11]||(t[11]=e("p",{class:"text-sm font-medium text-gray-600"},"Ingresos del Mes",-1)),e("p",je,"$"+a(d(l).ingresosMes.toLocaleStr
1ing()),1),e("p",{class:I(["text-xs mt-1",d(l).crecimientoIngresos>=0?"text-green-600":"text-red-600"])},a(d(l).crecimientoIngresos>=0?"+":"")+a(d(l).crecimientoIngresos)+"% vs mes anterior ",3)]),t[12]||(t[12]=e("div",{class:"p-3 bg-gradient-to-br from-purple-500 to-purple-600 rounded-xl shadow-lg"},[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:"M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1"})])],-1))])])]),e("div",Ee,[D(c,{to:"/admin/usuarios",class:"bg-white rounded-xl shadow-lg hover:shadow-xl transition-all duration-300 p-6 border border-gray-100 group"},{default:N(()=>[...t[13]||(t[13]=[e("div",{class:"flex items-center space-x-4"},[e("div",{class:"p-3 bg-gradient-to-br from-blue-500 to-blue-600 rounded-xl shadow-lg"},[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:"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"})])]),e("div",null,[e("h3",{class:"text-lg font-semibold text-gray-900"},"Gestionar Usuarios"),e("p",{class:"text-sm text-gray-600"},"Crear usuarios y asignar roles")])],-1)])]),_:1}),D(c,{to:"/admin/pedidos",class:"bg-white rounded-xl shadow-lg hover:shadow-xl transition-all duration-300 p-6 border border-gray-100 group"},{default:N(()=>[...t[14]||(t[14]=[e("div",{class:"flex items-center space-x-4"},[e("div",{class:"p-3 bg-gradient-to-br from-green-500 to-green-600 rounded-xl shadow-lg"},[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:"M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"})])]),e("div",null,[e("h3",{class:"text-lg font-semibold text-gray-900"},"Gestionar Pedidos"),e("p",{class:"text-sm text-gray-600"},"Crear pedidos para usuarios")])],-1)])]),_:1}),e("button",{onClick:t[0]||(t[0]=n=>f.value=!d(f)),class:"bg-white rounded-xl shadow-lg hover:shadow-xl transition-all duration-300 p-6 border border-gray-100 group"},[...t[15]||(t[15]=[P('<div class="flex items-center space-x-4"><div class="p-3 bg-gradient-to-br from-purple-500 to-purple-600 rounded-xl shadow-lg"><svg class="w-6 h-6 text-white" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg></div><div><h3 class="text-lg font-semibold text-gray-900">Acciones Rápidas</h3><p class="text-sm text-gray-600">Crear usuario o pedido</p></div></div>',1)])])]),d(f)?(w(),b("div",Be,[t[18]||(t[18]=e("h3",{class:"text-lg font-semibold text-gray-900 mb-4"},"Acciones Rápidas",-1)),e("div",Ve,[e("button",{onClick:t[1]||(t[1]=n=>{U.value=!0,f.value=!1}),class:"flex items-center space-x-3 p-4 border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors"},[...t[16]||(t[16]=[P('<div class="w-10 h-10 bg-blue-100 rounded-lg flex items-center justify-center"><svg class="w-5 h-5 text-blue-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path></svg></div><div class="text-left"><h4 class="font-medium text-gray-900">Crear Usuario</h4><p class="text-sm text-gray-600">Registrar nuevo cliente o vendedor</p></div>',2)])]),e("button",{onClick:t[2]||(t[2]=n=>{T.value=!0,f.value=!1}),class:"flex items-center space-x-3 p-4 border border-gray-200 rounded-lg hover:bg-gray-50 transition-colors"},[...t[17]||(t[17]=[P('<div class="w-10 h-10 bg-green-100 rounded-lg flex items-center justify-center"><svg class="w-5 h-5 text-green-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path></svg></div><div class="text-left"><h4 class="font-medium text-gray-900">Crear Pedido</h4><p class="text-sm text-gray-600">Crear pedido para un usuario</p></div>',2)])])])])):ie("",!0),e("div",$e,[e("div",Se,[t[20]||(t[20]=e("h2",{class:"text-xl font-semibold text-gray-900"},"Pedidos Recientes",-1)),D(c,{to:"/admin/pedidos",class:"text-blue-600 hover:text-blue-700 text-sm font-medium"},{default:N(()=>[...t[19]||(t[19]=[ue(" Ver todos â ",-1)])]),_:1})]),e("div",Ie,[e("table",Le,[t[21]||(t[21]=e("thead",null,[e("tr",{class:"border-b border-gray-200"},[e("th",{class:"text-left py-3 px-4 font-medium text-gray-700"},"Pedido"),e("th",{class:"text-left py-3 px-4 font-medium text-gray-700"},"Cliente"),e("th",{class:"text-left py-3 px-4 font-medium text-gray-700"},"Estado"),e("th",{class:"text-left py-3 px-4 font-medium text-gray-700"},"Fecha"),e("th",{class:"text-left py-3 px-4 font-medium text-gray-700"},"Acciones")])],-1)),e("tbody",null,[(w(!0),b(de,null,le(d(y),n=>(w(),b("tr",{key:n.id,class:"border-b border-gray-100 hover:bg-gray-50"},[e("td",ze,[e("div",null,[e("p",Ue,a(n.numero),1),e("p",Te,a(n.descripcion),1)])]),e("td",He,[e("div",null,[e("p",Re,a(n.userName),1),e("p",qe,a(n.userEmail),1)])]),e("td",Ye,[e("span",{class:I(["inline-flex px-2 py-1 text-xs font-semibold rounded-full",q(n.estado)])},a(Y(n.estado)),3)]),e("td",Ge,a(R(n.createdAt)),1),e("td",Oe,[e("button",{onClick:j=>G(n.id),class:"text-blue-600 hover:text-blue-700 text-sm font-medium"}," Ver ",8,Qe)])]))),128))])])])])])}}};export{Ze 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.