import{r as o,i as c,j as e,k as u}from"./index-RapqkS1n.js";const N=({endpoint:i="/notifications/customer"})=>{const[r,n]=o.useState([]),[d,a]=o.useState(!0),[f,l]=o.useState(null);o.useEffect(()=>{m()},[i]);const m=async()=>{try{console.log("🔍 Fetching notifications from:",i);const s=await c.get(i);console.log("📋 Notifications response:",s.data),n(s.data.data||[]),a(!1)}catch(s){console.error("❌ Error fetching notifications:",s),l("Failed to fetch notifications"),a(!1)}},g=async s=>{try{let t=i;i.endsWith("/customer")?t=`/notifications/customer/${s}/dismiss`:i.endsWith("/courier")&&(t=`/notifications/courier/${s}/dismiss`),console.log("🗑️ Dismissing notification:",s,"via endpoint:",t),await c.post(t),console.log("✅ Notification dismissed successfully"),n(r.filter(h=>h.id!==s))}catch(t){console.error("❌ Error dismissing notification:",t),l("Failed to dismiss notification")}};return d||f||r.length===0?null:(console.log("📱 Rendering notifications:",r.length),e.jsx("div",{className:"fixed top-24 right-4 z-40",children:e.jsx("div",{className:"w-96",children:e.jsx("div",{className:"space-y-3",children:r.map(s=>e.jsx("div",{className:`w-full bg-white shadow-lg rounded-lg pointer-events-auto ring-1 ring-black ring-opacity-5 overflow-hidden ${s.priority==="high"?"border-l-4 border-red-500":s.priority==="normal"?"border-l-4 border-yellow-500":"border-l-4 border-gray-500"}`,children:e.jsx("div",{className:"p-4",children:e.jsxs("div",{className:"flex items-start",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm font-medium text-gray-900",children:s.title}),e.jsx("p",{className:"mt-1 text-sm text-gray-500",children:s.message})]}),e.jsx("div",{className:"ml-4 flex-shrink-0 flex",children:e.jsxs("button",{type:"button",className:"bg-white rounded-md inline-flex text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-[#ff6b00]",onClick:()=>g(s.id),children:[e.jsx("span",{className:"sr-only",children:"Close"}),e.jsx(u,{className:"h-5 w-5"})]})})]})})},s.id))})})}))};export{N};
