import{z as M,A as R,g as r,b as s,t as v,i as c,F as A,r as X,p as m,o as n,n as b,q as E}from"./app-BJF24m-a.js";const H={class:"relative notification-dropdown"},N={key:0,class:"absolute -top-1 -right-1 bg-red-500 text-white text-xs font-bold rounded-full w-5 h-5 flex items-center justify-center animate-pulse"},D={key:0,class:"absolute right-0 mt-2 w-80 bg-white rounded-xl shadow-2xl border border-slate-200 z-50 max-h-96 overflow-hidden"},L={class:"p-4 border-b border-slate-100 bg-gradient-to-r from-blue-50 to-slate-50"},q={class:"flex items-center justify-between"},B={class:"overflow-y-auto max-h-80"},T={key:0,class:"p-8 text-center text-slate-400"},O=["onClick"],S={class:"flex items-start gap-3"},V={class:"flex-1 min-w-0"},F={class:"text-sm text-slate-700 font-medium truncate"},$={class:"text-xs text-slate-400 mt-1"},z={key:0,class:"w-2 h-2 bg-blue-500 rounded-full flex-shrink-0 mt-2"},W={__name:"NotificationBell",props:{ajustador:Object},setup(I){const i=m([]),a=m(0),l=m(!1);let u=null;const h=async()=>{try{const e=await fetch("/ajustador/api/notifications",{headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"}});if(e.status===401||e.status===403)return;const t=await e.json();i.value=t.notifications,a.value=t.unread_count}catch(e){console.error("Error fetching notifications:",e)}},p=()=>{const e=document.cookie.match(/(?:^|;\s*)XSRF-TOKEN=([^;]*)/);return e?decodeURIComponent(e[1]):""},w=async e=>{try{if(!(await fetch(`/ajustador/api/notifications/${e.id}/read`,{method:"POST",headers:{"X-Requested-With":"XMLHttpRequest","X-XSRF-TOKEN":p(),Accept:"application/json"}})).ok)return;e.leida=!0,a.value=Math.max(0,a.value-1)}catch(t){console.error("Error marking notification as read:",t)}},g=async()=>{try{if(!(await fetch("/ajustador/api/notifications/read-all",{method:"POST",headers:{"X-Requested-With":"XMLHttpRequest","X-XSRF-TOKEN":p(),Accept:"application/json"}})).ok)return;i.value.forEach(t=>t.leida=!0),a.value=0}catch(e){console.error("Error marking all as read:",e)}},_=e=>{w(e),E.visit(route("ajustador.casos.show",e.caso_id)),l.value=!1},y=()=>{l.value=!l.value,l.value&&i.value.length===0&&h()},x=e=>{e.target.closest(".notification-dropdown")||(l.value=!1)};M(()=>{h(),u=setInterval(h,3e4),document.addEventListener("click",x)}),R(()=>{u&&clearInterval(u),document.removeEventListener("click",x)});const j=e=>{const t=new Date,o=new Date(e),d=t-o,f=Math.floor(d/6e4),k=Math.floor(d/36e5),C=Math.floor(d/864e5);return f<1?"Ahora":f<60?`Hace ${f} min`:k<24?`Hace ${k}h`:`Hace ${C}d`};return(e,t)=>(n(),r("div",H,[s("button",{onClick:y,class:"relative p-2 text-slate-500 hover:text-blue-600 hover:bg-slate-100 rounded-full transition-colors"},[t[0]||(t[0]=s("svg",{class:"w-6 h-6",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[s("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"})],-1)),a.value>0?(n(),r("span",N,v(a.value>9?"9+":a.value),1)):c("",!0)]),l.value?(n(),r("div",D,[s("div",L,[s("div",q,[t[1]||(t[1]=s("h3",{class:"font-bold text-slate-800"},"Notificaciones",-1)),a.value>0?(n(),r("button",{key:0,onClick:g,class:"text-xs text-blue-600 hover:text-blue-700 font-medium"}," Marcar todas como leídas ")):c("",!0)])]),s("div",B,[i.value.length===0?(n(),r("div",T,[...t[2]||(t[2]=[s("svg",{class:"w-12 h-12 mx-auto mb-3 opacity-50",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[s("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1.5",d:"M15 17h5l-1.405-1.405A2.032 2.032 0 0118 14.158V11a6.002 6.002 0 00-4-5.659V5a2 2 0 10-4 0v.341C7.67 6.165 6 8.388 6 11v3.159c0 .538-.214 1.055-.595 1.436L4 17h5m6 0v1a3 3 0 11-6 0v-1m6 0H9"})],-1),s("p",{class:"text-sm"},"No tienes notificaciones",-1)])])):c("",!0),(n(!0),r(A,null,X(i.value,o=>(n(),r("div",{key:o.id,onClick:d=>_(o),class:b(["p-4 border-b border-slate-50 hover:bg-slate-50 cursor-pointer transition-colors",{"bg-blue-50/50":!o.leida}])},[s("div",S,[s("div",{class:b(["w-8 h-8 rounded-full flex items-center justify-center flex-shrink-0",o.leida?"bg-slate-100 text-slate-400":"bg-blue-100 text-blue-600"])},[...t[3]||(t[3]=[s("svg",{class:"w-4 h-4",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24"},[s("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})],-1)])],2),s("div",V,[s("p",F,v(o.mensaje),1),s("p",$,v(j(o.created_at)),1)]),o.leida?c("",!0):(n(),r("span",z))])],10,O))),128))])])):c("",!0)]))}};export{W as default};
