import{r as n,a as C,c as D,j as e,v as E,i as I}from"./index-7c7a558c.js";import{B as F}from"./Breadcrumb-065f300e.js";import{i as L}from"./studentApi-6e4fac08.js";const R=()=>{var g,N,y,f,o,v;const[P,T]=n.useState(25),[c,m]=n.useState(1),d=10,i=8,{data:a,isLoading:w,isError:p,error:s,isFetching:A,refetch:h}=C("getStudentPassBook",()=>L({count:P})),u=D();n.useEffect(()=>{const t=localStorage.getItem("token"),r=localStorage.getItem("user");t&&r||u("/login")},[u]),n.useEffect(()=>{h()},[h]);const j=(c-1)*d,S=j+d,b=((y=(N=(g=a==null?void 0:a.data)==null?void 0:g.data)==null?void 0:N.transactions)==null?void 0:y.slice(j,S))||[];let l=null;w?l=e.jsx("tr",{className:"bg-second",children:e.jsx("td",{colSpan:i,className:"text-center text-white flex md:table-cell justify-center items-center",children:e.jsx("div",{className:"text-center flex justify-center items-center my-6",children:e.jsx(I,{color:"dark",size:"lg",variant:"dots"})})})}):p?l=e.jsx("tr",{className:"bg-second ",children:e.jsx("td",{colSpan:i,className:"text-center text-white py-6",children:`${s==null?void 0:s.error}`})}):b.length===0?l=e.jsx("tr",{className:"bg-second",children:e.jsx("td",{colSpan:i,className:"text-center text-white py-6",children:"No Transaction Found!"})}):l=b.map((t,r)=>e.jsxs("tr",{className:"bg-gradient-to-r from-main to-second text-white border-b hover:bg-gray-200 borderBg",children:[e.jsx("td",{"data-label":"SL",className:"w-4 p-4",children:r+1}),e.jsx("td",{"data-label":"Type",className:"px-6 py-4",children:(t==null?void 0:t.type)==1?"Credit":"Debit"}),e.jsx("td",{"data-label":"Credit",className:"px-6 py-4",children:(t==null?void 0:t.type)==1?t==null?void 0:t.amount:""}),e.jsx("td",{"data-label":"Debit",className:"px-6 py-4",children:(t==null?void 0:t.type)==2?t==null?void 0:t.amount:""}),e.jsxs("td",{"data-label":"Amount",className:"px-6 py-4",children:[(t==null?void 0:t.type)==1?"+":"-",t==null?void 0:t.amount]}),e.jsx("td",{"data-label":"Note",className:"px-6 py-4",children:t==null?void 0:t.narration}),e.jsx("td",{"data-label":"Date",className:"px-6 py-4",children:E(t==null?void 0:t.created_at)})]},r));const x=Math.ceil((((v=(o=(f=a==null?void 0:a.data)==null?void 0:f.data)==null?void 0:o.transactions)==null?void 0:v.length)||0)/d);return e.jsxs(e.Fragment,{children:[e.jsx(F,{title:"Passbook"}),e.jsxs("div",{className:"container mx-auto my-5 lg:p-5 min-h-screen",children:[e.jsx("div",{className:"relative overflow-x-auto shadow-md border-dashed border rounded-tr-xl rounded-bl-xl mb-40 md:mb-20",children:e.jsxs("table",{className:"w-full text-sm text-left text-gray-500 table-auto",children:[e.jsx("thead",{className:"text-xs uppercase bg-secondBg border-b text-white",children:e.jsxs("tr",{className:"",children:[e.jsx("th",{scope:"col",className:"p-4",children:"Serial"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Type"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Credit"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Debit"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Amount"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Note"}),e.jsx("th",{scope:"col",className:"px-6 py-3",children:"Date"})]})}),e.jsx("tbody",{children:l})]})}),e.jsxs("div",{className:"flex justify-center items-center mt-4",children:[e.jsx("button",{onClick:()=>{c>1&&m(t=>t-1)},disabled:c===1,className:"px-4 py-2 rounded-md bg-main text-white mr-2",children:"Previous"}),e.jsxs("span",{className:"text-gray-600",children:["Page ",c," of ",x]}),e.jsx("button",{onClick:()=>{c<x&&m(t=>t+1)},disabled:c>=x,className:"px-4 py-2 rounded-md bg-main text-white ml-2",children:"Next"})]})]})]})};export{R as default};
