import{r as h,a as M,c as Q,j as e,v as R,I as $,i as U,aU as q}from"./index-7c7a558c.js";import{B as A}from"./Breadcrumb-0d748722.js";const J=()=>{var p,j,g,N,i,o,u,b,y,w,k,v,S,f,E,L,D,I;const[d,z]=h.useState(25),B=25,c=9,{data:s,isLoading:r,isError:C,isFetching:_,error:x,refetch:m}=M("getNotifications",()=>q({count:d})),n=Q();h.useEffect(()=>{const t=localStorage.getItem("token"),l=localStorage.getItem("user");t&&l||n("/login")},[n]),h.useEffect(()=>{m()},[d,m]);let a=null;return r&&(a=e.jsx("tr",{className:"section-bg border-b dark:text-white",children:e.jsx("td",{colSpan:c,className:"text-center text-white",children:e.jsx("div",{className:"text-center flex justify-center items-center my-6",children:e.jsx(U,{color:"white",size:"lg",variant:"dots"})})})})),!r&&C&&(a=e.jsx("tr",{className:"section-bg border-b dark:text-white",children:e.jsx("td",{colSpan:c,className:"text-center text-white py-6",children:`${x==null?void 0:x.error}`})})),!r&&((g=(j=(p=s==null?void 0:s.data)==null?void 0:p.data)==null?void 0:j.notifications)==null?void 0:g.length)===0&&(a=e.jsx("tr",{className:"section-bg border-b dark:text-white",children:e.jsx("td",{colSpan:c,className:"text-center text-white py-6",children:"Notifications Not Found!"})})),!r&&((o=(i=(N=s==null?void 0:s.data)==null?void 0:N.data)==null?void 0:i.notifications)==null?void 0:o.length)>0&&(a=(y=(b=(u=s==null?void 0:s.data)==null?void 0:u.data)==null?void 0:b.notifications)==null?void 0:y.map((t,l)=>{var F;return e.jsxs("tr",{className:"section-bg border-b dark:text-white",children:[e.jsx("td",{"data-label":"Serial",className:"px-6 py-4",children:l+1}),e.jsx("td",{"data-label":"Description",className:"px-6 py-4",children:t==null?void 0:t.text}),e.jsx("td",{"data-label":"Useful Link",className:"px-6 py-4",children:e.jsx("a",{href:t==null?void 0:t.target_url,children:"Click here"})}),e.jsx("td",{"data-label":"Sender Name",className:"px-6 py-4",children:(F=t==null?void 0:t.sender)==null?void 0:F.name}),e.jsx("td",{"data-label":"Date",className:"px-6 py-4",children:R(t==null?void 0:t.created_at)})]},l)})),e.jsxs(e.Fragment,{children:[e.jsx(A,{title:"Notifications"}),e.jsx("div",{className:"container mx-auto my-5 p-5",children:e.jsxs("div",{className:"relative overflow-x-auto shadow-md sm:rounded-lg bg-white dark:bg-gray-900 p-2 table-wrapper",children:[e.jsx($,{dataLength:(v=(k=(w=s==null?void 0:s.data)==null?void 0:w.data)==null?void 0:k.notifications)!=null&&v.length?(E=(f=(S=s==null?void 0:s.data)==null?void 0:S.data)==null?void 0:f.notifications)==null?void 0:E.length:0,next:()=>{z(t=>t+B)},hasMore:((I=(D=(L=s==null?void 0:s.data)==null?void 0:L.data)==null?void 0:D.notifications)==null?void 0:I.length)==d,children:e.jsxs("table",{className:"w-full text-sm text-left text-gray-500 dark:text-gray-400",children:[e.jsx("thead",{className:"text-xs text-gray-700 uppercase bg-white text-black",children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",className:"p-4",children:"Serial"}),e.jsx("th",{scope:"col",className:"p-4",children:"Description"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Useful Link"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Sender Name"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Date"})]})}),e.jsx("tbody",{children:a})]})}),_&&e.jsx("div",{className:"text-center flex justify-center items-center my-6",children:e.jsx(U,{color:"white",size:"lg",variant:"dots"})})]})})]})};export{J as default};
