import{r as g,b as e,a as u}from"./app-DTeOhhdM.js";import{A as w,b as m,B as p}from"./AuthenticatedLayout-DNj-hWy1.js";import{D as v,C as r}from"./column.esm-CqBIx_TJ.js";import{T as _}from"./toast.esm-CLj0hUIX.js";import"./helper-Gzy5oJm-.js";import"./asyncToGenerator-BfWTt6ZC.js";import"./createLucideIcon-0QtVMxKe.js";import"./defualtLogo-C0dU5cUD.js";import"./inputtext.esm-DvYkLvTo.js";import"./index.esm-xhUioO7y.js";import"./index.esm-BlFJNgmX.js";import"./index.esm-CVWS0Xy2.js";const k=c=>{const s=new Date-new Date(c),i=Math.floor(s/(1e3*60)),a=Math.floor(s/(1e3*60*60)),o=Math.floor(s/(1e3*60*60*24));return i<1?"just now":i<60?`${i} minute${i>1?"s":""} ago`:a<24?`${a} hour${a>1?"s":""} ago`:`${o} day${o>1?"s":""} ago`},D=({auth:c,notifications:d})=>{const s=g.useRef(null),i=t=>{switch(t){case"requisition_created":return"pi pi-shopping-cart";case"requisition_shifted":return"pi pi-send";case"requisition_approved":return"pi pi-check";case"requisition_rejected":return"pi pi-times";default:return"pi pi-bell"}},a=t=>{switch(t){case"requisition_created":return"text-blue-500";case"requisition_shifted":return"text-green-500";case"requisition_approved":return"text-green-600";case"requisition_rejected":return"text-red-500";default:return"text-gray-500"}},o=async t=>{try{await u.put(route("notifications.markAsRead",t)),s.current.show({severity:"success",summary:"Success",detail:"Notification marked as read",life:3e3}),window.location.reload()}catch{s.current.show({severity:"error",summary:"Error",detail:"Failed to mark notification as read",life:3e3})}},x=async t=>{try{await u.delete(route("notifications.destroy",t)),s.current.show({severity:"success",summary:"Success",detail:"Notification deleted",life:3e3}),window.location.reload()}catch{s.current.show({severity:"error",summary:"Error",detail:"Failed to delete notification",life:3e3})}},f=t=>e.jsx("div",{className:`text-center ${a(t.type)}`,children:e.jsx("i",{className:`${i(t.type)} text-xl`})}),h=t=>{var n,l;return e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:((n=t.data)==null?void 0:n.title)||"Notification"}),e.jsx("div",{className:"text-sm text-gray-600 mt-1",children:((l=t.data)==null?void 0:l.message)||""})]})},y=t=>e.jsx("div",{className:"text-center",children:t.read_at?e.jsx(m,{value:"Read",severity:"success"}):e.jsx(m,{value:"Unread",severity:"info"})}),j=t=>e.jsx("div",{className:"text-sm",children:k(t.created_at)}),N=t=>e.jsxs("div",{className:"flex gap-2",children:[!t.read_at&&e.jsx(p,{icon:"pi pi-check",className:"p-button-rounded p-button-success p-button-sm",onClick:()=>o(t.id),tooltip:"Mark as read"}),e.jsx(p,{icon:"pi pi-trash",className:"p-button-rounded p-button-danger p-button-sm",onClick:()=>x(t.id),tooltip:"Delete notification"})]}),b=t=>t.read_at?"":"bg-blue-50";return e.jsxs(w,{user:c.user,header:e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"text-skin-header font-medium",children:"Notifications"}),e.jsx("p",{className:"text-skin-sub-header font-semibold text-xs",children:"Home - Notifications"})]}),headerButton:e.jsx(e.Fragment,{}),children:[e.jsx(_,{ref:s}),e.jsx("div",{className:"card",children:e.jsxs(v,{value:d.data,paginator:!0,rows:20,dataKey:"id",rowClassName:b,emptyMessage:"No notifications found.",className:"p-datatable-sm",children:[e.jsx(r,{body:f,header:"Type",style:{width:"80px"},className:"text-center"}),e.jsx(r,{body:h,header:"Notification",style:{width:"60%"}}),e.jsx(r,{body:y,header:"Status",style:{width:"100px"},className:"text-center"}),e.jsx(r,{body:j,header:"Time",style:{width:"150px"}}),e.jsx(r,{body:N,header:"Actions",style:{width:"120px"},className:"text-center"})]})})]})};export{D as default};
