import{r as n,cD as T,b as a,j as u,ck as j,be as B,bf as N,bg as E,Q as p,B as x,W as M,cj as R,cm as I,M as O,G as L,an as G,s as k,e as U,a7 as W}from"./index-BiWH3VAt.js";import{d as F}from"./Inventory2-C3fFxNFR.js";import{r as q}from"./renderStatusBox-CjZzX4Nb.js";const H=({onFilterChange:l})=>{const[s,d]=n.useState("all"),[h,i]=n.useState("all"),[f,D]=n.useState(null),[y,o]=n.useState(null),{data:c,isLoading:b}=T({}),C=(()=>{var t,m;return c?(t=c.userProfileDTO)!=null&&t.branchDetailsDTO?c.userProfileDTO.branchDetailsDTO:(m=c.userProfileDTO)!=null&&m.branches?c.userProfileDTO.branches:c.branchDetails?c.branchDetails:[]:[]})(),S=t=>{if(i(t),t==="all")D(null),o(null);else{const m=Number(t);D(I().subtract(m-1,"day")),o(I())}};return n.useEffect(()=>{l&&l({branchId:s==="all"?void 0:Number(s),fromDate:f,toDate:y})},[s,f,y,l]),a(R,{dateAdapter:j,children:u(M,{elevation:0,sx:{p:2,mb:3,borderRadius:3,display:"flex",justifyContent:"space-between",alignItems:"center"},children:[u(B,{size:"small",sx:{minWidth:150},children:[a(N,{id:"branch-select-label",children:"Branch"}),u(E,{labelId:"branch-select-label",label:"Branch",value:s,onChange:t=>d(t.target.value),children:[a(p,{value:"all",children:"All Branches"}),!b&&C.map(t=>a(p,{value:String(t.id??t.branchId),children:t.name??t.branchName??"Unknown"},t.id??t.branchId))]})]}),a(x,{display:"flex",alignItems:"center",gap:2,children:u(B,{size:"small",sx:{minWidth:150},children:[a(N,{children:"Date Range"}),u(E,{label:"Date Range",value:h,onChange:t=>S(t.target.value),children:[a(p,{value:"all",children:"All Dates"}),a(p,{value:"7",children:"Last 7 Days"}),a(p,{value:"30",children:"Last 30 Days"}),a(p,{value:"90",children:"Last 90 Days"})]})]})})]})})},Q=O.injectEndpoints({endpoints:l=>({searchPackingListByUserId:l.mutation({query:({page:s,size:d,searchValue:h,branchId:i})=>({url:"packing-list/search-by-criteria-userId",method:"POST",params:{page:s,size:d},body:{searchValue:h},headers:i!==void 0&&i!==""?{"Branch-Id":String(i)}:void 0})}),getPackingListByBranch:l.mutation({query:({branchId:s})=>({url:"packing-list/by-branch",method:"POST",body:{branchId:s},headers:{"Branch-Id":String(s)}})})}),overrideExisting:!1}),{useSearchPackingListByUserIdMutation:V,useGetPackingListByBranchMutation:K}=Q;function X({branchId:l}){const[s]=V(),[d,h]=n.useState([]),[i,f]=n.useState(0),[D,y]=n.useState(!1),[o,c]=n.useState({page:0,pageSize:10}),[b,v]=n.useState(l),[C,S]=n.useState(null),m=[{label:"Total Records",value:n.useMemo(()=>i>0?i:d.length>0?d.length:0,[d,i]),icon:a(F,{}),description:"Count of all items in your list"}],A=[{field:"packingNumber",headerName:"Packing No",flex:1},{field:"clientName",headerName:"Client Name",flex:1},{field:"phoneNumber",headerName:"Phone Number",flex:1},{field:"experience",headerName:"Experience",flex:1},{field:"status",headerName:"Status",flex:1,renderCell:e=>q(e.value||"")},{field:"createdDate",headerName:"Date",flex:1,valueGetter:e=>{var r;return(r=e.row.createdDate)==null?void 0:r.slice(0,10)}}],P=n.useCallback(async()=>{y(!0),S(null);try{const e=await s({page:o.page,size:o.pageSize,searchValue:"",branchId:b||void 0}).unwrap();let r=[],g=0;e&&(e.data!==void 0?Array.isArray(e.data)?(r=e.data,g=e.totalCount||e.totalElements||r.length):e.data&&typeof e.data=="object"&&(r=e.data.data||e.data.content||e.data.items||[],g=e.data.totalCount||e.data.totalElements||e.totalCount||e.totalElements||r.length):Array.isArray(e)?(r=e,g=e.length):e.content?(r=Array.isArray(e.content)?e.content:[],g=e.totalCount||e.totalElements||r.length):(r=[],g=e.totalCount||e.totalElements||0)),h(r),f(g)}catch(e){S(e),console.error("Error fetching packing list:",e),h([]),f(0)}finally{y(!1)}},[s,o.page,o.pageSize,b]);n.useEffect(()=>{P()},[P]),n.useEffect(()=>{l!==b&&v(l)},[l]);const z=n.useCallback(e=>{v(e.branchId),c({page:0,pageSize:o.pageSize})},[o.pageSize]),w=n.useCallback(e=>{c(e)},[]);return a(W,{error:C,children:u(x,{sx:{p:2,width:"100%"},children:[a(H,{onFilterChange:z}),a(L,{container:!0,spacing:2,mt:3,children:m.map((e,r)=>a(L,{item:!0,xs:12,sm:6,md:3,children:u(G,{sx:{p:2,textAlign:"center",height:"100%",display:"flex",flexDirection:"column",justifyContent:"space-between",transition:"transform 0.2s, box-shadow 0.2s","&:hover":{transform:"translateY(-4px)",boxShadow:4}},children:[a(x,{sx:{color:"primary.main",mb:1},children:e.icon}),a(k,{variant:"body2",color:"text.secondary",sx:{mb:1},children:e.label}),a(k,{variant:"h5",fontWeight:600,sx:{mb:.5},children:typeof e.value=="number"?e.value.toLocaleString():e.value}),a(k,{variant:"caption",color:"text.secondary",sx:{mt:1,fontSize:"0.7rem"},children:e.description})]})},r))}),a(x,{mt:4,children:a(U,{columns:A,rows:d,checkboxSelection:!1,rowCount:i,paginationModel:o,handlePaginationChange:w,loading:D,enableManageColumns:!0,defaultHiddenColumns:["id"],getRowId:e=>e.id||e.packingNumber,initialState:{pagination:{paginationModel:{pageSize:10,page:0}}}})})]})})}export{X as default};
