1import{r as u}from"./rolldown-runtime-CXHxssQy.js";import{f as p,l as x,t as m}from"./vendor-core-DLV7unHF.js";import{b as h,n as v}from"./vendor-data-gP-SiX90.js";import{n as j}from"./queryClient-CbhGi5gS.js";import{Rt as f,Xr as l,bn as b,wt as g}from"./vendor-ui-HbZeGnVr.js";import{t as d}from"./button-BpBAlEZu.js";import{t as y}from"./use-toast-PQNKAu0e.js";import{n as N}from"./slugify-COPcHoH5.js";import{a as A,i as w,n as k,r as _,t as C}from"./card-C09EQudm.js";import{t as D}from"./AccountAsyncState-Dl6GOR7T.js";import{t as E}from"./useAccountQuery-BEz5BNGO.js";import{t as S}from"./badge-Ckh5MnAv.js";import{t as q}from"./ConfirmDialog-DSde3hIV.js";var P=u(p(),1);function T(a){return a!==null&&a.isPublished}var e=x();function G(){const a=h(),{toast:s}=y(),i=E("/api/account/alerts"),[n,o]=(0,P.useState)(null),c=v({mutationFn:async r=>(await j("DELETE",`/api/account/alerts/${r}`)).json(),onSuccess:()=>{a.invalidateQueries({queryKey:["/api/account/alerts"]}),a.invalidateQueries({queryKey:["/api/account/dashboard"]}),s({title:"Alerta desactivada"})},onError:()=>{s({title:"No se pudo desactivar la alerta",description:"Inténtalo de nuevo.",variant:"destructive"}),a.invalidateQueries({queryKey:["/api/account/alerts"]})}});return(0,e.jsxs)("div",{className:"space-y-6","data-testid":"alerts-tab",children:[(0,e.jsxs)(C,{children:[(0,e.jsxs)(w,{children:[(0,e.jsxs)(A,{className:"flex items-center gap-2 text-[#E85A8B]",children:[(0,e.jsx)(l,{className:"w-5 h-5"})," Mis alertas"]}),(0,e.jsx)(_,{children:"Avisos cuando un producto vuelve al stock o baja de precio. Se envÃan por email + notificaciones push si las tienes activas."})]}),(0,e.jsx)(k,{children:(0,e.jsx)(D,{query:i,label:"tus alertas",isEmpty:r=>r.alerts.length===0,empty:(0,e.jsxs)("div",{className:"text-center py-10",children:[(0,e.jsx)(l,{className:"w-10 h-10 text-pink-200 mx-auto mb-3"}),(0,e.jsx)("p",{className:"text-sm text-gray-600 mb-3",children:"No tienes alertas activas."}),(0,e.jsx)("p",{className:"text-xs text-gray-500 mb-4",children:'En la ficha de un producto, pulsa "AvÃsame" cuando esté agotado o sube su precio.'}),(0,e.jsx)(m,{href:"/",children:(0,e.jsx)(d,{variant:"outline",children:"Explorar productos"})})]}),children:({alerts:r})=>(0,e.jsx)("ul",{className:"space-y-2",children:r.map(t=>(0,e.jsxs)("li",{className:"flex items-center justify-between gap-3 p-3 rounded-lg bg-gray-50","data-testid":`alert-${t.id}`,children:[(0,e.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[t.type==="back_in_stock"?(0,e.jsx)(b,{className:"w-5 h-5 text-[#E85A8B] shrink-0"}):(0,e.jsx)(f,{className:"w-5 h-5 text-emerald-600 shrink-0"}),(0,e.jsxs)("div",{className:"min-w-0",children:[(0,e.jsx)("p",{className:"text-sm font-medium",children:t.type==="back_in_stock"?"AvÃsame cuando vuelva al stock":"AvÃsame si baja de precio"}),(0,e.jsx)(Q,{alert:t})]})]}),(0,e.jsx)(d,{variant:"ghost",size:"sm",className:"text-gray-400 hover:text-red-600 hover:bg-red-50",onClick:()=>o(t.id),disabled:c.isPending&&c.variables===t.id,"aria-label":"Desactivar alerta","data-testid":`remove-alert-${t.id}`,children:(0,e.jsx)(g,{className:"w-4 h-4"})})]},t.id))})})})]}),(0,e.jsx)(q,{open:n!==null,onOpenChange:r=>!r&&o(null),title:"¿Desactivar esta alerta?",description:"Dejarás de recibir el aviso de este producto. Podrás volver a crearla desde su ficha.",confirmLabel:"Desactivar",onConfirm:()=>n!==null&&c.mutate(n)})]})}function Q({alert:a}){const{product:s}=a,i=`Activa desde ${new Date(a.createdAt).toLocaleDateString("es-ES")}`;return T(s)?(0,e.jsxs)("div",{className:"flex items-center gap-2 text-xs text-gray-500",children:[s.image&&(0,e.jsx)("img",{src:s.image,alt:"",width:32,height:32,loading:"lazy",className:"w-8 h-8 rounded object-cover"}),(0,e.jsx)(m,{href:N(a.productId,s.name),className:"underline truncate",children:s.name}),(0,e.jsx)(S,{variant:"outline",className:"text-xs",children:s.stock>0?"Disponible":"Agotado"}),(0,e.jsxs)("span",{children:[`${s.price}â¬`,a.priceAtSubscribe&&` · Precio guardado: ${a.priceAtSubscribe}â¬`]}),(0,e.jsxs)("span",{className:"hidden sm:inline",children:["· ",i]})]}):(0,e.jsxs)("p",{className:"text-xs text-gray-500",children:["Producto retirado · ",i]})}export{G as AlertsTab};
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.