import{u as R,m as k,s as E,r as d,R as T,j as e,L as D,C as $,f as p,i as I}from"./index-D0o5GN6H.js";import{u as J}from"./useDataTable-Kl0VByqj.js";import{F as U}from"./ArrowLeftIcon-BV5yYEjK.js";const K=()=>{var b,f;const m=R(),{year:a,month:n}=k(),{user:v}=E(),[N,u]=d.useState([]),[H,h]=d.useState(!0),o=(t=>["January","February","March","April","May","June","July","August","September","October","November","December"][parseInt(t)-1]||"Unknown")(n),j=`Customers Registered in ${o} ${a}`;d.useEffect(()=>{(async()=>{try{h(!0);const s=await I.get("/branches");console.log("Branches response:",s.data),u(s.data.data||[])}catch(s){console.error("Error fetching branches:",s),u([])}finally{h(!1)}})()},[v]);const{data:l,totalItems:i,currentPage:y,totalPages:C,isLoading:x,error:c,searchTerm:w,responseData:r,handlePageChange:S,handleSortChange:B,handleFilterChange:g,handleSearchChange:F}=J("/customers/individual",{initialPage:1,initialSort:{field:"createdAt",direction:"desc"},initialFilters:{year:a,month:n}},[a,n]),A=[{field:"firstName",label:"First Name",sortable:!0},{field:"lastName",label:"Last Name",sortable:!0},{field:"mailboxNumber",label:"Mailbox Number",sortable:!0},{field:"email",label:"Email",sortable:!0},{field:"phone",label:"Phone",sortable:!0},{field:"branch",label:"Branch",sortable:!0},{field:"status",label:"Status",sortable:!0},{field:"createdAt",label:"Registration Date",sortable:!0}],P=t=>{const s={active:"bg-green-100 text-green-800",inactive:"bg-red-100 text-red-800",suspended:"bg-yellow-100 text-yellow-800"};return e.jsx("span",{className:`px-2 inline-flex text-xs leading-5 font-semibold rounded-full ${s[t]||"bg-gray-100 text-gray-800"}`,children:t.charAt(0).toUpperCase()+t.slice(1)})},L=T.useMemo(()=>l?l.map(t=>{var s;return{...t,branch:((s=t.branch)==null?void 0:s.name)||"No Branch",status:P(t.status),createdAt:new Date(t.createdAt).toLocaleDateString("en-US",{year:"numeric",month:"long",day:"numeric",hour:"2-digit",minute:"2-digit"})}}):[],[l]),M=t=>{if(Object.keys(t).length===0)g({year:a,month:n});else{const s={...t,year:a,month:n};g(s)}},O=t=>{m(`/admin/customers/${t.id}`)};return c?e.jsx("div",{className:"text-red-600 p-4",children:c}):e.jsxs("div",{className:"container mx-auto px-4 sm:px-6 lg:px-8 py-8",children:[e.jsx(D,{position:"top-right",autoClose:3e3,hideProgressBar:!1,newestOnTop:!0,closeOnClick:!0,rtl:!1,pauseOnFocusLoss:!0,draggable:!0,pauseOnHover:!0,theme:"light"}),e.jsx("div",{className:"mb-8",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center space-x-4",children:[e.jsxs("button",{onClick:()=>m("/admin/dashboard"),className:"inline-flex items-center px-3 py-2 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 bg-white hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-[#ff6b00]",children:[e.jsx(U,{className:"h-4 w-4 mr-2"}),"Back to Dashboard"]}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold text-gray-900",children:j}),e.jsxs("p",{className:"mt-1 text-sm text-gray-600",children:["Showing ",i," customer",i!==1?"s":""," registered in ",o," ",a]})]})]}),e.jsxs("div",{className:"flex items-center space-x-6",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-[#61ce70]",children:i}),e.jsx("div",{className:"text-sm text-gray-600",children:"Total Customers"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-green-600",children:((b=r==null?void 0:r.statusCounts)==null?void 0:b.active)||0}),e.jsx("div",{className:"text-sm text-gray-600",children:"Active"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"text-2xl font-bold text-red-600",children:((f=r==null?void 0:r.statusCounts)==null?void 0:f.inactive)||0}),e.jsx("div",{className:"text-sm text-gray-600",children:"Inactive"})]})]})]})}),e.jsx($,{headers:A,data:L,actions:[{label:"View",icon:p,onClick:t=>O(t)}],pagination:{currentPage:y,totalPages:C,totalItems:i,onPageChange:S},sorting:{onSortChange:({field:t,direction:s})=>B(t,s)},onFilterChange:M,onSearchChange:F,searchTerm:w,isLoading:x,error:c,filterOptions:{status:[{label:"Active",value:"active"},{label:"Inactive",value:"inactive"},{label:"Suspended",value:"suspended"}],branch:[...N.map(t=>({label:t.name,value:t.name})),{label:"All Branches",value:""}]}}),!x&&l&&l.length===0&&e.jsxs("div",{className:"text-center py-12",children:[e.jsx(p,{className:"mx-auto h-12 w-12 text-gray-400"}),e.jsx("h3",{className:"mt-2 text-sm font-medium text-gray-900",children:"No customers found"}),e.jsxs("p",{className:"mt-1 text-sm text-gray-500",children:["No customers were registered in ",o," ",a,"."]})]})]})};export{K as default};
