1import{a as s,j as e,I as ve,ad as Se,aL as Re,b9 as ie,ab as Ae,ac as Ye,a0 as rt,cG as lt,k as ye}from"./vendor-mui-B3bBnIQX.js";import{u as nt}from"./useTopbar-DdNCAeWW.js";import{F as z,L as V,ao as Y,fC as ot,M as ee,B as M,I as U,T as re,N as se,n as Ce,J as ae,W as it,K as ge,p as je}from"./index-K18uQlJT.js";import{u as Ge}from"./usePayrollPermissions-BAMgdllm.js";import{u as dt}from"./useDebouncedValue-Nb6xnVu9.js";import{u as ke}from"./useModuleTeamAccess-DopRzwP4.js";import{a as ct,u as We,b as Te,c as Ie,d as Ze,e as mt,f as pt,g as xt,h as Je,i as ut,j as ht,k as Ee,l as Ke,m as Qe,n as yt,o as gt,p as Xe,q as jt,r as bt,s as ft}from"./useRewards-CfKsQ5Yp.js";import{P as de}from"./Pagination-C01aUWwe.js";import{S as ce}from"./SortIcon-CeCBNJLO.js";import{f as Nt,i as De}from"./dateFormat-gOhHwZfI.js";import{A as Oe}from"./AppMenu-sbN_9oqO.js";import"./useGeneratePayroll-ps6R4y2i.js";import{N as Me}from"./NoHistoryResult-UZtoD070.js";import{h as Fe}from"./historyActorLabel-DEGYO2Iy.js";import{S as X}from"./SearchableSelect-bG3ORqDE.js";import{F}from"./FormField-DFqD4YvP.js";import{u as et}from"./useZodForm-0VxvzzsK.js";import{o as tt,s as L}from"./vendor-forms-BOKXSlZG.js";import{d as Le}from"./vendor-state-3ufgB8Gu.js";import{L as Pe}from"./Label-BBxSpPWg.js";import{A as st}
1from"./AppDatePicker-itKlj75y.js";import{F as at}from"./FilterMultiSelect-DmN76988.js";import{F as le}from"./FilterSectionLabel-kT9oe6wH.js";import{d as wt}from"./vendor-router-DjW2o810.js";const Be=t=>t?Nt(t):"-",me=({name:t,empNumber:a,dept:n,image:m})=>{const[p,i]=s.useState(!1),N=Array.isArray(m)?m[0]:m;return e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[N&&!p?e.jsx("img",{src:N,alt:t,className:"w-8 h-8 rounded-lg object-cover shrink-0",onError:()=>i(!0)}):e.jsx("div",{className:"w-8 h-8 rounded-lg bg-[var(--primary)] text-white text-[12px] font-semibold flex items-center justify-center shrink-0 uppercase",children:t?.[0]??"?"}),e.jsx(z,{title:t??"",placement:"top",children:e.jsxs("div",{className:"min-w-0 max-w-[160px]",children:[e.jsx("div",{className:"text-[13px] font-medium text-[var(--text)] truncate",children:t??"-"}),e.jsx("div",{className:"text-xs text-[var(--text-muted)] truncate",children:[a,n].filter(Boolean).join(" ⢠")})]})})]})},be=[{label:"Reward Category",key:"rewardName"},{label:"Referred By",key:"referredByName",align:"left"},{label:"Date",key:"createdOn"},{label:"Approved Amount",key:"approvedAmount"}];function vt(){const[t,a]=s.useState(1);s.useEffect(()=>{a(1)},[]);const[n,m]=s.useState("createdOn"),[p,i]=s.useState("DESC"),{data:N,isFetching:g}=ct({page:t,pageSize:Y,sortBy:n,sortOrder:p}),j=N?.records??[],u=N?.totalCount??0,b=r=>{n===r?i(h=>h==="ASC"?"DESC":"ASC"):(m(r),i("ASC")),a(1)};return e.jsxs(e.Fragment,{children:[g&&e.jsx(V,{}),e.jsx("div",{className:"bg-surface rounded-xl border border-border overflow-hidden",children:e.jsxs("table",{className:"w-full border-collapse text-sm",children:[e.jsx("thead",{children:e.jsx("tr",{className:"bg-surface-hover",children:be.map(({label:r,key:h,align:v},C)=>e.jsx("th",{className:`px-4 py-3 ${C===0||v==="left"?"text-left":"text-center"} text-xs font-semibold text-text-secondary whitespace-nowrap${C===be.length-1?" w-px":""}`,children:e.jsxs("span",{className:"inline-flex items-center gap-0.5",children:[r,e.jsx(ce,{column:h,sortBy:n,sortOrder:p,onSort:b})]})},r))})}),e.jsx("tbody",{children:j.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:be.length,className:"text-center py-12 text-text-secondary text-sm",children:"No records found"})}):j.map((r,h)=>e.jsxs("tr",{className:"hover:bg-surface-hover border-t border-border",children:[e.jsx("td",{className:"px-4 py-3 text-[13px] text-text-primary",children:r.rewardName??"-"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(me,{name:r.referredByName,image:r.image})}),e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary",children:Be(r.createdOn)}),e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary w-px whitespace-nowrap",children:r.approvedAmount??"-"})]},r.id??h))})]})}),e.jsx(de,{page:t,totalCount:u,pageSize:Y,onPageChange:a})]})}const te=({status:t})=>{const a=ot[t]??{bg:"#f3f4f6",color:"#6b7280"};return e.jsxs("span",{className:"inline-flex items-center gap-1 px-2.5 py-1 rounded-full text-xs font-medium whitespace-nowrap",style:{background:a.bg,color:a.color},children:[a.icon?e.jsx("img",{src:a.icon,alt:"",className:"w-3.5 h-3.5"}):e.jsx("span",{className:"w-3.5 h-3.5 rounded-full inline-block",style:{background:a.color}}),t??"-"]})},St=["Reward Request","History"],Rt=({item:t})=>e.jsxs("div",{className:"border border-border rounded-xl p-4 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[t.image?.[0]?e.jsx("img",{src:t.image[0],alt:t.updatedByName,className:"w-9 h-9 rounded-lg object-cover shrink-0"}):e.jsx("div",{className:"w-9 h-9 rounded-lg bg-primary text-white flex items-center justify-center text-sm font-semibold shrink-0 uppercase",children:t.updatedByName?.charAt(0)?.toUpperCase()??"?"}),e.jsx("span",{className:"text-sm font-medium text-text-primary",children:Fe(t)})]}),t.comment&&e.jsxs("div",{className:"flex flex-col gap-1 border-t border-border pt-3",children:[e.jsx("span",{className:"text-xs font-semibold text-primary",children:"Remarks"}),e.jsx("p",{className:"text-sm text-text-secondary leading-relaxed",children:t.comment})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border pt-3",children:[e.jsx("span",{className:"text-xs text-text-secondary",children:t.updatedAt?De(t.updatedAt):"â"}),e.jsx(te,{status:t.statusName})]})]}),_=({label:t,value:a})=>e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-text-secondary",children:t}),e.jsx("div",{className:"h-10 px-3 flex items-center rounded-lg bg-surface-hover text-sm text-text-secondary",children:a??""})]}),$e=({row:t,dataType:a,onClose:n})=>{const[m,p]=s.useState("Reward Request"),i=t?.nominatationId??t?.id;s.useEffect(()=>
1{i&&p("Reward Request")},[i]);const{data:N,isLoading:g}=We({nominatationId:i,dataType:a,enabled:!!t}),{data:j=[],isLoading:u}=Te(i),{data:b=[]}=Ie(),r=N??t;return e.jsxs(ee,{open:!!t,onClose:n,width:560,avatar:r?r.image?.[0]??r.profileImage?e.jsx("img",{src:r.image?.[0]??(Array.isArray(r.profileImage)?r.profileImage[0]:r.profileImage),alt:r.employeeName,className:"w-10 h-10 rounded-lg object-cover shrink-0"}):e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary text-white text-sm font-semibold flex items-center justify-center shrink-0 uppercase",children:r.employeeName?.[0]??"?"}):null,title:r?`${r.employeeName??"â"}${r.employeeNumber||t?.employeeNumber?` (${r.employeeNumber||t.employeeNumber})`:""}`:"â",subtitle:r?`Ticket ID - ${r.serialNumber??r.id}`:void 0,footer:e.jsx(M,{variant:"secondary",onClick:n,children:"Cancel"}),children:[e.jsx("div",{className:"flex gap-6 border-b border-border mb-5 -mt-1",children:St.map(h=>e.jsx(M,{type:"button",variant:"icon",onClick:()=>p(h),className:`h-auto w-auto rounded-none pb-2 text-sm font-medium border-b-2 -mb-px ${m===h?"border-primary text-primary":"border-transparent text-text-secondary hover:text-text-primary"}`,children:h},h))}),g&&e.jsx(V,{}),!g&&e.jsx("div",{className:"min-h-[320px]",children:m==="Reward Request"?e.jsxs("div",{className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(_,{label:"Select Category",value:r?.rewardName}),e.jsx(_,{label:"Employee",value:r?.employeeName})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(_,{label:"Department",value:r?.department??r?.departmentName}),e.jsx(_,{label:"Assignee",value:r?.defaultAssigneeName})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("span",{className:"text-xs text-text-secondary",children:"Comment"}),e.jsx("div",{className:"min-h-[72px] px-3 py-2 rounded-lg bg-surface-hover text-sm text-text-secondary",children:r?.description??r?.comment??""})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(_,{label:"Manager Approved Amount",value:r?.amount}),e.jsx(_,{label:"Approved Amount",value:r?.approvedAmount})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(_,{label:"Year",value:r?.year}),e.jsx(_,{label:"Month",value:r?.month?b.find(h=>h.id===r.month)?.monthName??"":""})]})]}):e.jsxs("div",{className:"flex flex-col gap-3",children:[u&&e.jsx(V,{}),!u&&j.length===0&&e.jsx(Me,{}),!u&&j.map((h,v)=>e.jsx(Rt,{item:h},v))]})})]})},At=tt({category:L().optional(),employee:L().optional(),department:L().optional(),comment:L().optional(),managerApprovedAmount:L().optional(),year:L().optional(),month:L().optional(),assignee:L().min(1,"Assignee is required"),approvedAmount:L().min(1,"Approved Amount is required").regex(/^\d+(\.\d{1,2})?$/,"Enter a valid amount")}),Ct=["Reward Request","History"],Z="w-full h-10 px-3 border border-border rounded-lg text-sm bg-surface-hover text-text-secondary appearance-none disabled:opacity-100",kt=({item:t})=>e.jsxs("div",{className:"border border-border rounded-xl p-4 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[t.image?.[0]?e.jsx("img",{src:t.image[0],alt:t.updatedByName,className:"w-9 h-9 rounded-lg object-cover shrink-0"}):e.jsx("div",{className:"w-9 h-9 rounded-lg bg-primary text-white flex items-center justify-center text-sm font-semibold shrink-0 uppercase",children:t.updatedByName?.charAt(0)?.toUpperCase()??"?"}),e.jsx("span",{className:"text-sm font-medium text-text-primary",children:Fe(t)})]}),t.comment&&e.jsxs("div",{className:"flex flex-col gap-1 border-t border-border pt-3",children:[e.jsx("span",{className:"text-xs font-semibold text-primary",children:"Remarks"}),e.jsx("p",{className:"text-sm text-text-secondary leading-relaxed",children:t.comment})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border pt-3",children:[e.jsx("span",{className:"text-xs text-text-secondary",children:t.updatedAt?De(t.updatedAt):"â"}),e.jsx(te,{status:t.statusName})]})]}),qe=({row:t,dataType:a,tab:n,onClose:m,canAction:p=!0})=>{const[i,N]=s.useState("Reward Request"),[g,j]=s.useState(null),[u,b]=s.useState(""),r=t?.nominatationId??t?.id,{data:h,isLoading:v}=We({nominatationId:r,dataType:a,enabled:!!t}),{data:C=[],isLoading:R}=Te(r),{mutate:E,isPending:c}=Ze(),{register:w,handleSubmit:S,reset:d,watch:D,setValue:T,formState:{errors:l,isValid:O}}=et(At),x=h??t,{data:y=[],isLoading:I}=mt(h?.rewardId??t?.rewardId,!!t&&!v),{data:o=[]}=Ie();s.useEffect(()=>{if(!x||I)return;const A=x.defaultAssigneeId??x.assignedToId??x.assigneeId??"",B=y.find(G=>G.userId===A);d({category:x.rewardName??"",employee:x.employeeName??"",department:x.department??x.departmentName??"",comment:x.description??x.comment??"",managerApprovedAmount:String(x.managerApprovedAmount??""),year:String(x.year??""),month:o.find(G=>
1G.id===x.month)?.monthName??"",assignee:B?B.userId:String(A),approvedAmount:String(x.approvedAmount??"")})},[x?.nominatationId,I,o]),s.useEffect(()=>{t||(d(),N("Reward Request"))},[t,d]);const k=s.useCallback((A,B,G)=>{E({nominatationId:r,defaultAssigneeId:A.assignee,approvedAmount:Number(A.approvedAmount),remarks:null,actionType:B,rewardComment:G??""},{onSuccess:()=>{d(),m()}})},[E,r,d,m]),q=s.useCallback(A=>S(B=>{b(""),j({action:A,values:B})})(),[S]),P=s.useCallback(()=>S(A=>k(A,"update",""))(),[S,k]),H=s.useCallback(()=>q("rejected"),[q]),pe=s.useCallback(()=>q("accepted"),[q]),xe=s.useCallback(()=>j(null),[]),ue=s.useCallback(A=>b(A.target.value),[]),he=()=>{if(!g)return;const{action:A,values:B}=g;j(null),b(""),k(B,A,u)};return e.jsxs(e.Fragment,{children:[e.jsxs(ee,{open:!!t,onClose:m,width:560,avatar:x?x.image?.[0]??x.profileImage?e.jsx("img",{src:x.image?.[0]??(Array.isArray(x.profileImage)?x.profileImage[0]:x.profileImage),alt:x.employeeName,className:"w-10 h-10 rounded-lg object-cover shrink-0"}):e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary text-white text-sm font-semibold flex items-center justify-center shrink-0 uppercase",children:x.employeeName?.[0]??"?"}):null,title:x?`${x.employeeName??"â"}${x.employeeNumber||t?.employeeNumber?` (${x.employeeNumber||t.employeeNumber})`:""}
1`:"â",subtitle:x?`Ticket ID - ${x.serialNumber??x.id}`:void 0,footer:e.jsxs(e.Fragment,{children:[e.jsx(M,{variant:"secondary",onClick:m,className:"mr-auto",children:"Cancel"}),i==="Reward Request"&&e.jsxs(e.Fragment,{children:[e.jsx(M,{variant:"danger",disabled:!p||c,onClick:H,children:"Rejected"}),e.jsx(M,{variant:"success",disabled:!p||!O||c,onClick:pe,children:n==="allRewards"?"Mark Open":"Accepted"}),e.jsx(M,{variant:"warning",disabled:!p||!O||c,onClick:P,children:"Update"})]})]}),children:[e.jsx("div",{className:"flex gap-6 border-b border-border mb-5 -mt-1",children:Ct.map(A=>e.jsx(M,{type:"button",variant:"icon",onClick:()=>N(A),className:`h-auto w-auto rounded-none pb-2 text-sm font-medium border-b-2 -mb-px ${i===A?"border-primary text-primary":"border-transparent text-text-secondary hover:text-text-primary"}`,children:A},A))}),v&&e.jsx(V,{}),!v&&e.jsx("div",{className:"min-h-[320px]",children:i==="Reward Request"?e.jsxs("form",{id:"rewards-edit-form",onSubmit:S(k),className:"flex flex-col gap-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(F,{label:"Select Category",children:e.jsx(U,{...w("category"),disabled:!0,className:Z})}),e.jsx(F,{label:"Employee",children:e.jsx(U,{...w("employee"),disabled:!0,className:Z})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(F,{label:"Department",children:e.jsx(U,{...w("department"),disabled:!0,className:Z})}),e.jsx(F,{label:"Assignee",required:!0,error:l.assignee,children:e.jsx(X,{value:D("assignee")??"",onChange:A=>T("assignee",A??"",{shouldValidate:!0}),options:y.map(A=>({value:String(A.userId),label:A.employeeNumberAndName})),placeholder:"Select",disabled:I,hasError:!!l.assignee})})]}),e.jsx(F,{label:"Comment",children:e.jsx(re,{...w("comment"),disabled:!0,rows:3,className:"resize-none opacity-50"})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(F,{label:"Manager Approved Amount",children:e.jsx(U,{...w("managerApprovedAmount"),disabled:!0,className:Z})}),e.jsx(F,{label:"Approved Amount",required:!0,error:l.approvedAmount,children:e.jsx(U,{type:"text",...w("approvedAmount"),hasError:!!l.approvedAmount})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(F,{label:"Year",children:e.jsx(U,{...w("year"),disabled:!0,className:Z})}),e.jsx(F,{label:"Month",children:e.jsx(U,{...w("month"),disabled:!0,className:Z})})]})]}):e.jsxs("div",{className:"flex flex-col gap-3",children:[R&&e.jsx(V,{}),!R&&C.length===0&&e.jsx(Me,{}),!R&&C.map((A,B)=>e.jsx(kt,{item:A},B))]})})]}),e.jsx(se,{open:!!g,onClose:xe,onConfirm:he,title:g?.action==="accepted"?n==="allRewards"?"Are you sure you want to mark this reward as open?":"Are you sure you want to accept this reward?":"Are you sure you want to reject this reward?",confirmText:g?.action==="accepted"?n==="allRewards"?"Mark Open":"Accept":"Reject",cancelText:"Cancel",isLoading:c,confirmDisabled:g?.action==="rejected"&&!u.trim(),cancelIcon:null,confirmIcon:null,children:e.jsx(re,{rows:3,value:u,onChange:ue,placeholder:"Enter remark...",className:"resize-none"})})]})},Tt=({item:t})=>e.jsxs("div",{className:"border border-border rounded-xl p-4 flex flex-col gap-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[t.image?.[0]?e.jsx("img",{src:t.image[0],alt:t.updatedByName,className:"w-9 h-9 rounded-lg object-cover shrink-0"}):e.jsx("div",{className:"w-9 h-9 rounded-lg bg-primary text-white flex items-center justify-center text-sm font-semibold shrink-0 uppercase",children:t.updatedByName?.charAt(0)?.toUpperCase()??"?"}),e.jsx("span",{className:"text-sm font-medium text-text-primary",children:Fe(t)})]}),t.comment&&e.jsxs("div",{className:"flex flex-col gap-1 border-t border-border pt-3",children:[e.jsx("span",{className:"text-xs font-semibold text-primary",children:"Remarks"}),e.jsx("p",{className:"text-sm text-text-secondary leading-relaxed",children:t.comment})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-border pt-3",children:[e.jsx("span",{className:"text-xs text-text-secondary",children:t.updatedAt?De(t.updatedAt):"â"}),e.jsx(te,{status:t.statusName})]})]}),It=({src:t,name:a})=>{const[n,m]=s.useState(!1);return s.useEffect(()=>{m(!1)},[t]),t&&!n?e.jsx("img",{src:t,alt:a,onError:()=>m(!0),className:"w-10 h-10 rounded-lg object-cover shrink-0"}):e.jsx("div",{className:"w-10 h-10 rounded-lg bg-primary text-white text-sm font-semibold flex items-center justify-center shrink-0 uppercase",children:a?.[0]??"?"})},ze=({row:t,onClose:a})=>{const n=t?.nominatationId??t?.id,{data:m=[],isLoading:p}=Te(n),{data:i}=pt(n),N=i?.name??t?.employeeName,g=i?.employeeId??t?.employeeNumber,j=t?.image?.[0]??(Array.isArray(t?.profileImage)?t.profileImage[0]:t?.profileImage),u=(Array.isArray(i?.image)?i.image[0]:i?.image)??j;return e.jsx(ee,{open:!!t,onClose:a,width:560,avatar:e.jsx(It,{src:u,name:N}),title:t?`${N??"â"}${g?` (${g})`:""}`:"â",subtitle:`Ticket ID - ${t?.serialNumber??n}`,footer:e.jsx(M,{variant:"secondary",onClick:a,children:"Close"}),children:e.jsxs("div",{className:"flex flex-col gap-3",children:[p&&e.jsx(V,{}),!p&&m.length===0&&e.jsx(Me,{}),!p&&m.map((b,r)=>e.jsx(Tt,{item:b},r))]})})},Ve=[{label:"Ticket ID",key:"serialNumber",cls:"w-40"},{label:"Employee Name",key:"employeeName",cls:"w-40",align:"left"},{label:"Category",key:"rewardName",cls:"w-40",align:"left"},{label:"Referred By",key:"referredByName",cls:"w-40",align:"left"}
1,{label:"Amount",key:"amount",cls:"w-40"},{label:"Approved Amount",key:"approvedAmount",cls:"w-40"},{label:"Status",key:null,cls:"w-40"},{label:"Actions",key:null,cls:"w-40"}];function Et(t,a){return["Rejected","Payroll Ready","Processed","Completed"].includes(t)?[{label:"View",icon:Re},{label:"History",icon:ie}]:[{label:"Edit",icon:Ae,disabled:!a},{label:"History",icon:ie},{label:"Delete",icon:Ye,tone:"danger",disabled:!a}]}function Dt({filters:t={},search:a=""}){const{canAction:n}=ke("Payroll"),[m,p]=s.useState(1);s.useEffect(()=>{p(1)},[t,a]);const[i,N]=s.useState("createdOn"),[g,j]=s.useState("DESC"),[u,b]=s.useState(null),[r,h]=s.useState(null),[v,C]=s.useState(null),[R,E]=s.useState(null),{data:c,isFetching:w}=xt({page:m,pageSize:Y,sortBy:i,sortOrder:g,userId:t.empNames??[],rewardId:(t.rewardIds??[]).map(Number),empStatus:t.empStatus??[],empType:(t.empTypes??[]).map(Number),startDate:t.startDate??"",endDate:t.endDate??""}),S=Je(),d=c?.records??[],D=c?.totalCount??0,T=a?d.filter(y=>String(y.employeeName??"").toLowerCase().includes(a.toLowerCase())):d,l=y=>{i===y?j(I=>I==="ASC"?"DESC":"ASC"):(N(y),j("ASC")),p(1)},O=s.useCallback(()=>S.mutate({nominatationId:v?.nominatationId??v?.id},{onSuccess:()=>C(null)}),[S,v]),x=s.useCallback(()=>C(null),[]);return e.jsxs(e.Fragment,{children:[w&&e.jsx(V,{}),e.jsx("div",{className:"bg-surface rounded-xl border border-border overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[700px] border-collapse text-sm table-fixed",children:[e.jsx("thead",{children:e.jsx("tr",{className:"bg-surface-hover",children:Ve.map(({label:y,key:I,cls:o,align:k})=>e.jsx("th",{className:`${o} px-4 py-3 ${k==="left"?"text-left":"text-center"} text-xs font-semibold text-text-secondary whitespace-nowrap`,children:e.jsxs("span",{className:"inline-flex items-start gap-1.5",children:[y,I&&e.jsx(ce,{column:I,sortBy:i,sortOrder:g,onSort:l})]})},y))})}),e.jsx("tbody",{children:T.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:Ve.length,className:"text-center py-12 text-text-secondary text-sm",children:"No records found"})}):T.map((y,I)=>{const o=y.statusName??y.status;return e.jsxs("tr",{className:"hover:bg-surface-hover border-t border-border cursor-pointer",onClick:()=>b(y),children:[e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary",children:y.serialNumber??y.id??"-"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(me,{name:y.employeeName,empNumber:y.employeeNumber,dept:y.department,image:y.image})}),e.jsx("td",{className:"px-4 py-3 text-left text-[13px] text-text-primary max-w-0",children:e.jsx(z,{title:y.rewardName??"",placement:"top",children:e.jsx("span",{className:"block truncate",children:y.rewardName??"-"})})}),e.jsx("td",{className:"px-4 py-3 text-left text-[13px] text-text-primary max-w-0",children:e.jsx(z,{title:y.referredByName??"",placement:"top",children:e.jsx("span",{className:"block truncate",children:y.referredByName??"-"})})}),e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary",children:y.amount??"-"}),e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary",children:y.approvedAmount??"-"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"flex justify-center",children:e.jsx(te,{status:o})})}),e.jsx("td",{className:"px-4 py-3 text-center",onClick:k=>k.stopPropagation(),children:e.jsx(Oe,{trigger:e.jsx(ve,{size:"small","aria-label":"Row actions",children:e.jsx(Se,{sx:{fontSize:16}})}),items:Et(o,n),onAction:k=>{k==="View"&&b(y),k==="Edit"&&h(y),k==="Delete"&&C(y),k==="History"&&E(y)},minWidth:160})})]},y.id??I)})})]})})}),e.jsx(de,{page:m,totalCount:D,pageSize:Y,onPageChange:p}),e.jsx($e,{row:u,dataType:"teamRewards",onClose:()=>b(null)}),e.jsx(qe,{row:r,dataType:"teamRewards",canAction:n,onClose:()=>h(null)}),e.jsx(ze,{row:R,onClose:()=>E(null)}),e.jsx(se,{open:!!v,title:"Are you sure you want to delete this ticket?",confirmText:"Delete",cancelText:"Cancel",isLoading:S.isPending,onConfirm:O,onClose:x})]})}const He=[{label:"Ticket ID",key:"serialNumber",cls:"w-40"},{label:"Employee",key:"employeeName",cls:"w-40",align:"left"},{label:"Category",key:"rewardName",cls:"w-40",align:"left"},{label:"Referred By",key:"referredByName",cls:"w-40",align:"left"},{label:"Assigned To",key:"assignedTo",cls:"w-40",align:"left"}
1,{label:"Amount",key:"amount",cls:"w-40"},{label:"Approved Amount",key:"approvedAmount",cls:"w-40"},{label:"Generated On",key:"createdOn",cls:"w-40"},{label:"Status",key:null,cls:"w-40"},{label:"Actions",key:null,cls:"w-40"}];function Ot(t){const a=[];return["Rejected","Payroll Ready","Processed","Completed"].includes(t)?a.push({label:"View",icon:Re}):a.push({label:"Edit",icon:Ae}),a.push({label:"History",icon:ie}),a}function Mt({filters:t={},search:a=""}){const[n,m]=s.useState(1);s.useEffect(()=>{m(1)},[t,a]);const[p,i]=s.useState("employeeName"),[N,g]=s.useState("ASC"),[j,u]=s.useState(null),[b,r]=s.useState(null),[h,v]=s.useState(null),{data:C,isFetching:R}=ut({page:n,pageSize:Y,sortBy:p,sortOrder:N,dataType:t.assignee==="myTeamAssignee"?"teamAssignee":"myAssignee",userId:t.empNames??[],rewardId:(t.rewardIds??[]).map(Number),empStatus:t.empStatus??[],empType:(t.empTypes??[]).map(Number),status:t.status??[],department:(t.department??[]).map(Number),startDate:t.startDate??"",endDate:t.endDate??""}),E=C?.records??[],c=C?.totalCount??0,w=a?E.filter(d=>String(d.employeeName??"").toLowerCase().includes(a.toLowerCase())):E,S=d=>{p===d?g(D=>D==="ASC"?"DESC":"ASC"):(i(d),g("ASC")),m(1)};return e.jsxs(e.Fragment,{children:[R&&e.jsx(V,{}),e.jsx("div",{className:"bg-surface rounded-xl border border-border overflow-hidden",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[860px] border-collapse text-sm table-fixed",children:[e.jsx("thead",{children:e.jsx("tr",{className:"bg-surface-hover",children:He.map(({label:d,key:D,cls:T,align:l})=>e.jsx("th",{className:`${T} px-4 py-3 ${l==="left"?"text-left":"text-center"} text-xs font-semibold text-text-secondary whitespace-nowrap`,children:e.jsxs("span",{className:"inline-flex items-start gap-1.5",children:[d,D&&e.jsx(ce,{column:D,sortBy:p,sortOrder:N,onSort:S})]})},d))})}),e.jsx("tbody",{children:w.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:He.length,className:"text-center py-12 text-text-secondary text-sm",children:"No records found"})}):w.map((d,D)=>{const T=d.statusName??d.status;return e.jsxs("tr",{className:"hover:bg-surface-hover border-t border-border cursor-pointer",onClick:()=>u(d),children:[e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary",children:d.serialNumber??d.id??"-"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(me,{name:d.employeeName,empNumber:d.employeeNumber,dept:d.department,image:d.image})}),e.jsx("td",{className:"px-4 py-3 text-left text-[13px] text-text-primary max-w-0",children:e.jsx(z,{title:d.rewardName??"",placement:"top",children:e.jsx("span",{className:"block truncate",children:d.rewardName??"-"})})}),e.jsx("td",{className:"px-4 py-3 text-left text-[13px] text-text-primary max-w-0",children:e.jsx(z,{title:d.referredByName??"",placement:"top",children:e.jsx("span",{className:"block truncate",children:d.referredByName??"-"})})}),e.jsx("td",{className:"px-4 py-3 text-left text-[13px] text-text-primary max-w-0",children:e.jsx(z,{title:d.assignedTo??"",placement:"top",children:e.jsx("span",{className:"block truncate",children:d.assignedTo??"-"})})}),e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary",children:d.amount??"-"}),e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary",children:d.approvedAmount??"-"}),e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary whitespace-nowrap",children:Be(d.createdOn)}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"flex justify-center",children:e.jsx(te,{status:T})})}),e.jsx("td",{className:"px-4 py-3 text-center",onClick:l=>l.stopPropagation(),children:e.jsx(Oe,{trigger:e.jsx(ve,{size:"small","aria-label":"Row actions",children:e.jsx(Se,{sx:{fontSize:16}})}),items:Ot(T),onAction:l=>{l==="View"&&u(d),l==="Edit"&&r(d),l==="History"&&v(d)},minWidth:160})})]},d.id??D)})})]})})}),e.jsx(de,{page:n,totalCount:c,pageSize:Y,onPageChange:m}),e.jsx($e,{row:j,dataType:"myAssignee",onClose:()=>u(null)}),e.jsx(qe,{row:b,dataType:"myAssignee",onClose:()=>r(null)}),e.jsx(ze,{row:h,onClose:()=>v(null)})]})}const _e=[{label:"Ticket ID",key:"serialNumber",cls:"w-40"},{label:"Employee Name",key:"employeeName",cls:"w-40",align:"left"},{label:"Category",key:"rewardName",cls:"w-40",align:"left"},{label:"Referred By",key:"referredByName",cls:"w-40",align:"left"},{label:"Assigned To",key:"assignedTo",cls:"w-40",align:"left"}
1,{label:"Amount",key:"amount",cls:"w-40"},{label:"Approved Amount",key:"approvedAmount",cls:"w-40"},{label:"Generated On",key:"createdOn",cls:"w-40"},{label:"Status",key:null,cls:"w-40"},{label:"Actions",key:null,cls:"w-40"}];function Ft(t,a){const n=[];return["Requested","Payroll Ready","Completed"].includes(a)&&n.push({label:"Edit",icon:Ae}),["Rejected","Payroll Ready","Processed","Completed"].includes(a)&&n.push({label:"View",icon:Re}),["Payroll Ready"].includes(a)&&n.push({label:"Mark Complete",icon:rt}),["Completed"].includes(a)&&n.push({label:"Mark Open",icon:lt}),n.push({label:"History",icon:ie}),["Requested","Rejected","Payroll Ready"].includes(a)&&n.push({label:"Delete",icon:Ye,tone:"danger"}),n}function Lt({filters:t={},search:a=""}){const[n,m]=s.useState(1);s.useEffect(()=>{m(1)},[t,a]);const[p,i]=s.useState("createdOn"),[N,g]=s.useState("DESC"),[j,u]=s.useState(null),[b,r]=s.useState(null),[h,v]=s.useState(null),[C,R]=s.useState(null),{data:E,isFetching:c}=ht({page:n,pageSize:Y,sortBy:p,sortOrder:N,userId:t.empNames??[],rewardId:(t.rewardIds??[]).map(Number),empStatus:t.empStatus??[],empType:(t.empTypes??[]).map(Number),status:t.status??[],department:(t.department??[]).map(Number),startDate:t.startDate??"",endDate:t.endD
1ate??""}),[w,S]=s.useState(null),[d,D]=s.useState(""),[T,l]=s.useState(null),[O,x]=s.useState(""),y=Je(),I=Ze(),o=E?.records??[],k=E?.totalCount??0,q=a?o.filter(f=>String(f.employeeName??"").toLowerCase().includes(a.toLowerCase())):o,P=f=>{p===f?g(W=>W==="ASC"?"DESC":"ASC"):(i(f),g("ASC")),m(1)},H=s.useCallback(()=>y.mutate({nominatationId:h?.nominatationId??h?.id},{onSuccess:()=>v(null)}),[y,h]),pe=s.useCallback(()=>v(null),[]),xe=s.useCallback(()=>I.mutate({nominatationId:w?.nominatationId??w?.id,actionType:"completed",rewardComment:d},{onSuccess:()=>{S(null),D("")}}),[I,w,d]),ue=s.useCallback(()=>{S(null),D("")},[]),he=s.useCallback(f=>D(f.target.value),[]),A=s.useCallback(()=>I.mutate({nominatationId:T?.nominatationId??T?.id,actionType:"accepted",rewardComment:O},{onSuccess:()=>{l(null),x("")}}),[I,T,O]),B=s.useCallback(()=>{l(null),x("")},[]),G=s.useCallback(f=>x(f.target.value),[]);return e.jsxs(e.Fragment,{children:[c&&e.jsx(V,{}),e.jsx("div",{className:"bg-surface rounded-xl border border-border",children:e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[860px] border-collapse text-sm table-fixed",children:[e.jsx("thead",{children:e.jsx("tr",{className:"bg-surface-hover",children:_e.map(({label:f,key:W,cls:ne,align:$})=>e.jsx("th",{className:`${ne} px-4 py-3 ${$==="left"?"text-left":"text-center"} text-xs font-semibold text-text-secondary whitespace-nowrap`,children:e.jsxs("span",{className:"inline-flex items-start gap-1.5",children:[f,W&&e.jsx(ce,{column:W,sortBy:p,sortOrder:N,onSort:P})]})},f))})}),e.jsx("tbody",{children:q.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:_e.length,className:"text-center py-12 text-text-secondary text-sm",children:"No records found"})}):q.map((f,W)=>{const ne=f.statusName??f.status;return e.jsxs("tr",{className:"hover:bg-surface-hover border-t border-border cursor-pointer",onClick:()=>u(f),children:[e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary",children:f.serialNumber??f.id??"-"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx(me,{name:f.employeeName,empNumber:f.employeeNumber,dept:f.department,image:f.image})}),e.jsx("td",{className:"px-4 py-3 text-left text-[13px] text-text-primary max-w-0",children:e.jsx(z,{title:f.rewardName??"",placement:"top",children:e.jsx("span",{className:"block truncate",children:f.rewardName??"-"})})}),e.jsx("td",{className:"px-4 py-3 text-left text-[13px] text-text-primary max-w-0",children:e.jsx(z,{title:f.referredByName??"",placement:"top",children:e.jsx("span",{className:"block truncate",children:f.referredByName??"-"})})}),e.jsx("td",{className:"px-4 py-3 text-left text-[13px] text-text-primary max-w-0",children:e.jsx(z,{title:f.assignedTo??"",placement:"top",children:e.jsx("span",{className:"block truncate",children:f.assignedTo??"-"})})}),e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary",children:f.amount??"-"}),e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary",children:f.approvedAmount??"-"}),e.jsx("td",{className:"px-4 py-3 text-center text-[13px] text-text-primary whitespace-nowrap",children:Be(f.createdOn)}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("div",{className:"flex justify-center",children:e.jsx(te,{status:ne})})}),e.jsx("td",{className:"px-4 py-3 text-center",onClick:$=>$.stopPropagation(),children:e.jsx(Oe,{trigger:e.jsx(ve,{size:"small","aria-label":"Row actions",children:e.jsx(Se,{sx:{fontSize:16}})}),items:Ft(f,ne),onAction:$=>{$==="Edit"&&r(f),$==="View"&&u(f),$==="Delete"&&v(f),$==="Mark Complete"&&S(f),$==="Mark Open"&&l(f),$==="History"&&R(f)},minWidth:160})})]},f.id??W)})})]})})}),e.jsx(de,{page:n,totalCount:k,pageSize:Y,onPageChange:m}),e.jsx($e,{row:j,dataType:"allRewards",onClose:()=>u(null)}),e.jsx(qe,{row:b,dataType:"allRewards",tab:"allRewards",onClose:()=>r(null)}),e.jsx(ze,{row:C,onClose:()=>R(null)}),e.jsx(se,{open:!!h,title:"Are you sure you want to delete this ticket?",confirmText:"Delete",cancelText:"Cancel",isLoading:y.isPending,onConfirm:H,onClose:pe}),e.jsx(se,{open:!!w,onClose:ue,onConfirm:xe,title:"Are you sure you want to mark this ticket as complete?",confirmText:"Mark Complete",confirmClassName:"px-4",cancelText:"Cancel",isLoading:I.isPending,children:e.jsx(re,{rows:3,value:d,onChange:he,placeholder:"Enter remark...",className:"resize-none"})}),e.jsx(se,{open:!!T,onClose:B,onConfirm:A,title:"Are you sure you want to mark this ticket as open?",confirmText:"Mark Open",cancelText:"Cancel",isLoading:I.isPending,children:e.jsx(re,{rows:3,value:O,onChange:G,placeholder:"Enter remark...",className:"resize-none"})})]})}const Pt=tt({category:L().min(1,"This field is mandatory"),employee:L().min(1,"This field is mandatory"),department:L().optional(),amount:L().min(1,"This field is mandatory").regex(/^\d+(\.\d{1,2})?$/,"Enter a valid amount"),year:L().min(1,"This field is mandatory"),month:L().min(1,"This field is mandatory"),description:L().optional()}),Bt=new Date().getFullYear(),$t=Array.from({length:5},(t,a)=>String(Bt-a)),qt=({open:t,onClose:a})=>{const n=Le(Ce),{canAction:m}=ke("Payroll"),{register:p,handleSubmit:i,reset:N,watch:g,setValue:j,formState:{errors:u,isValid:b}}=et(Pt),r=g("category"),h=g("department"),{data:v=[],isLoading:C}=Ee(t),{data:R=[],isLoading:E}=Ke(t),{canNominateOrgLevel:c}=Ge(),w=c&&!!h,S=h?[Number(h)]:[],d=Qe({userId:n?.userId,departments:S,enabled:t&&!w}),D=yt({departments:S,enabled:t&&w}),{data:T=[],isLoading:l}=w?D:d,{mutate:O,isPending:x}=gt(),{data:y=[]}=Ie();s.useEffect(()=>{if(!r||!v.length)return;const o=v.find(k=>String(k.id??k.rewardId)===String(r));j("amount",o?.amount!=null?String(o.amount):"")},[r,v,j]),s.useEffect(()=>{j("employee","")},[h,j]),s.useEffect(()=>{j("employee","")},[r,j]),s.useEffect(()=>{t&&N()},[t,N]);const I=o=>{O({rewardId:o.category,employeeId:o.employee,departmentId:o.department??"",amount:o.amount,description:o.description||"",year:o.year,month:y.find(k=>k.monthName===o.month)?.id??0},{onSuccess:()=>{N(),a()}})};return e.jsx(ee,{open:t,onClose:a,title:"Rewards Request",width:560,footer:e.jsxs(e.Fragment,{children:[e.jsx(M,{variant:"secondary",onClick:a,children:"Cancel"}
1),e.jsx(M,{type:"submit",form:"rewards-request-form",variant:"primary",disabled:!m||!b||x,children:"Add"})]}),children:e.jsxs("form",{id:"rewards-request-form",onSubmit:i(I),className:"flex flex-col gap-5 pt-2",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(F,{label:"Select Category",required:!0,error:u.category,children:e.jsx(X,{options:v.map(o=>({value:String(o.id??o.rewardId),label:o.name??o.rewardName})),value:r??"",onChange:o=>j("category",o??"",{shouldValidate:!0}),placeholder:"Select",disabled:C})}),e.jsx(F,{label:"Department",error:u.department,children:e.jsx(X,{options:R.map(o=>({value:String(o.id??o.departmentId),label:o.name??o.departmentName})),value:h??"",onChange:o=>j("department",o??"",{shouldValidate:!0}),placeholder:"Select",disabled:E})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(F,{label:"Employee",required:!0,error:u.employee,children:e.jsx(X,{options:T.map(o=>({value:String(o.userId??o.id),label:o.name??o.employeeName})),value:g("employee")??"",onChange:o=>j("employee",o??"",{shouldValidate:!0}),placeholder:"Select",disabled:l})}),e.jsx(F,{label:"Amount",required:!0,error:u.amount,children:e.jsx(U,{type:"text",placeholder:"",...p("amount"),hasError:!!u.amount})})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(F,{label:"Year",required:!0,error:u.year,children:e.jsx(X,{options:$t.map(o=>({value:o,label:o})),value:g("year")??"",onChange:o=>j("year",o??"",{shouldValidate:!0}),placeholder:"Select"})}),e.jsx(F,{label:"Month",required:!0,error:u.month,children:e.jsx(X,{options:y.map(o=>({value:o.monthName,label:o.monthName})),value:g("month")??"",onChange:o=>j("month",o??"",{shouldValidate:!0}),placeholder:"Select"})})]}),e.jsx(F,{label:"Description",error:u.description,children:e.jsx(re,{...p("description"),rows:3,className:"resize-none"})})]})})},zt=[{label:"Active",value:"active"},{label:"Inactive",value:"inactive"}],J={empNames:[],empStatus:[],rewardIds:[],empTypes:[],startDate:"",endDate:""};function oe({title:t,items:a,selected:n=[],onToggle:m}){return e.jsxs("div",{children:[e.jsx(le,{label:t}),e.jsx(at,{items:a,selected:n,onToggle:m})]})}function Vt({open:t,onClose:a,onApply:n,currentFilters:m=J}){const[p,i]=s.useState(J),N=Le(Ce),{data:g=[]}=Ee(t),{data:j=[]}=Xe(t),u=jt();s.useEffect(()=>{t&&(i(m),u.mutate({userId:N?.userId,empStatus:m.empStatus??[],empType:m.empTypes??[]}))},[t]);const b=(c,w)=>i(S=>({...S,[c]:w})),r=c=>{b("empStatus",c),u.mutate({userId:N?.userId,empStatus:c,empType:p.empTypes})},h=c=>{b("empTypes",c),u.mutate({userId:N?.userId,empStatus:p.empStatus,empType:c})},v=()=>{n(p),a()},C=()=>{i(J),n(J),a()},R=(u.data?.data?.records??[]).map(c=>({label:c.employeeNumberAndName??c.name??c.employeeName,value:c.userId??c.id})),E=!ae({...J,...p},J);return e.jsx(ee,{open:t,onClose:a,width:680,title:"Filters",subtitle:"Apply filters to refine your search results",footer:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx(M,{variant:"ghost",onClick:C,children:"Reset All"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(M,{variant:"secondary",className:"rounded-lg",onClick:a,children:"Cancel"}),e.jsx(M,{variant:"primary",className:"rounded-lg",onClick:v,disabled:E,children:"Apply Filters"})]})]}),children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-5",children:[e.jsx(oe,{title:"Employee Status",items:zt,selected:p.empStatus,onToggle:r}),e.jsx(oe,{title:"Employee Type",items:j.map(c=>({label:c.name??c.label,value:c.id??c.value})),selected:p.empTypes,onToggle:h}),e.jsx(oe,{title:"Employee",items:R,selected:p.empNames,onToggle:c=>b("empNames",c)}),e.jsx(oe,{title:"Rewards Type",items:g.map(c=>({label:c.name??c.rewardName,value:c.id??c.rewardId})),selected:p.rewardIds,onToggle:c=>b("rewardIds",c)}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(le,{label:"Date Range"}),e.jsx("div",{className:"grid grid-cols-2 gap-x-6",children:[{label:"From",key:"startDate"},{label:"To",key:"endDate"}].map(({label:c,key:w})=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(Pe,{className:"text-xs font-normal text-text-secondary",children:c}),e.jsx(st,{label:"",value:p[w],onChange:S=>b(w,S)})]},w))})]})]})})}const Ht=[{label:"Active",value:"active"},{label:"Inactive",value:"inactive"}],_t=[{label:"Request",value:"Requested"},{label:"Payroll Ready",value:"Payroll Ready"},{label:"Processed",value:"Processed"},{label:"Rejected",value:"Rejected"}],K={empNames:[],empStatus:[],rewardIds:[],empTypes:[],status:[],department:[],assignee:"myAssignee",startDate:"",endDate:""},Ut=[{label:"My Assignee",value:"myAssignee"},{label:"My Team Assignee",value:"myTeamAssignee"}];function Yt({selected:t="",onToggle:a}){return e.jsxs("div",{className:"col-span-2",children:[e.jsx(le,{label:"Assignee"}),e.jsx("div",{className:"grid grid-cols-2 gap-4",children:Ut.map(n=>e.jsxs(Pe,{className:"flex items-center gap-3 px-3 py-2 border border-border rounded-lg cursor-pointer hover:bg-surface-hover font-normal",children:[e.jsx(it,{name:"assignee",checked:t===n.value,onChange:()=>a(n.value)}),e.jsx("span",{className:"text-sm text-text-primary",children:n.label})]},n.value))})]})}function Q({title:t,items:a,selected:n=[],onToggle:m}){return e.jsxs("div",{children:[e.jsx(le,{label:t}),e.jsx(at,{items:a,selected:n,onToggle:m})]})}function Ue({open:t,onClose:a,onApply:n,currentFilters:m=K,title:p="All Rewards"}){const[i,N]=s.useState(K),g=p==="Assigned Rewards",j=Le(Ce),{data:u=[]}=Ee(t),{data:b=[]}=Xe(t),{data:r=[]}=Ke(t),{data:h=[]}=Qe({userId:j?.userId,departments:i.department?.map(Number)??[],empStatus:i.empStatus,empTypes:i.empTypes,enabled:t&&g}),{data:v=[]}=bt({empStatus:i.empStatus,empType:i.empTypes,department:i.department,enabled:t&&!g}),C=g?h:v;s.useEffect(()=>{t&&N(m)},[t]);const R=(l,O)=>N(x=>({...x,[l]:O})),E=l=>R("empStatus",l),c=l=>R("empTypes",l),w=()=>{n(i),a()},S=()=>{N(K),n(K),a()},d=C.map(l=>({label:l.employeeNumberAndName??l.name??l.employeeName,value:l.userId??l.id})),D=r.map(l=>({label:l.name??l.departmentName,value:l.id??l.departmentId})),T=!ae({...K,...i},K);return e.jsx(ee,{open:t,onClose:a,width:680,title:"Filters",subtitle:"Ap
1ply filters to refine your search results",footer:e.jsxs("div",{className:"flex items-center justify-between w-full",children:[e.jsx(M,{variant:"ghost",onClick:S,children:"Reset All"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(M,{variant:"secondary",className:"rounded-lg",onClick:a,children:"Cancel"}),e.jsx(M,{variant:"primary",className:"rounded-lg",onClick:w,disabled:T,children:"Apply Filters"})]})]}),children:e.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-5",children:[g&&e.jsx(Yt,{selected:i.assignee,onToggle:l=>R("assignee",l)}),e.jsx(Q,{title:"Employee Status",items:Ht,selected:i.empStatus,onToggle:E}),e.jsx(Q,{title:"Department",items:D,selected:i.department,onToggle:l=>R("department",l)}),e.jsx(Q,{title:"Employment Type",items:b.map(l=>({label:l.name??l.label,value:l.id??l.value})),selected:i.empTypes,onToggle:c}),e.jsx(Q,{title:"Employee",items:d,selected:i.empNames,onToggle:l=>R("empNames",l)}),e.jsx(Q,{title:"Reward Type",items:u.map(l=>({label:l.name??l.rewardName,value:l.id??l.rewardId})),selected:i.rewardIds,onToggle:l=>R("rewardIds",l)}),e.jsx(Q,{title:"Rewards Status",items:_t,selected:i.status,onToggle:l=>R("status",l)}),e.jsxs("div",{className:"col-span-2",children:[e.jsx(le,{label:"Date Range"}),e.jsx("div",{className:"grid grid-cols-2 gap-x-6",children:[{label:"From",key:"startDate"},{label:"To",key:"endDate"}].map(({label:l,key:O})=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(Pe,{className:"text-xs font-normal text-text-secondary",children:l}),e.jsx(st,{label:"",value:i[O],onChange:x=>R(O,x)})]},O))})]})]})})}const Gt=[{key:"myRewards",label:"My Rewards"},{key:"myNominations",label:"My Nominations"},{key:"assignedRewards",label:"Assigned Rewards"},{key:"allRewards",label:"All Rewards"}],fe={},Ne={assignee:"myAssignee"},we={},js=()=>{const[t,a]=s.useState(()=>new URLSearchParams(window.location.search).get("tab")||"myRewards"),{search:n}=wt()??{},m=dt(n),{canView:p,canAction:i}=ke("Payroll"),{showAllRewards:N}=Ge(),{hasAssigned:g}=ft(),j=g??t==="assignedRewards",u=s.useMemo(()=>Gt.filter(P=>(P.key!=="myNominations"||p)&&(P.key!=="assignedRewards"||j)&&(P.key!=="allRewards"||N)),[p,j,N]),b=s.useMemo(()=>{const P=u.map(H=>H.key);return P.includes(t)?t:P[0]??"myRewards"},[t,u]),[r,h]=s.useState(!1),[v,C]=s.useState(!1),[R,E]=s.useState(fe),[c,w]=s.useState(!1),[S,d]=s.useState(Ne),[D,T]=s.useState(!1),[l,O]=s.useState(we),x=s.useCallback(P=>{a(P);const H=new URLSearchParams(window.location.search);H.set("tab",P),window.history.replaceState(null,"",`?${H}`)},[]),y=s.useCallback(()=>h(!1),[]),I=s.useCallback(()=>C(!1),[]),o=s.useCallback(()=>w(!1),[]),k=s.useCallback(()=>T(!1),[]),q=b==="myNominations"?e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(ge,{active:ae(R,fe),onClick:()=>C(!0),onReset:()=>E(fe),size:"sm",icon:e.jsx(je,{icon:ye,size:"sm"})}),e.jsx(M,{size:"sm",disabled:i===!1,onClick:()=>h(!0),children:"+ Rewards Request"})]}):b==="assignedRewards"?e.jsx(ge,{active:ae(S,Ne),onClick:()=>w(!0),onReset:()=>d(Ne),size:"sm",icon:e.jsx(je,{icon:ye,size:"sm"})}):b==="allRewards"?e.jsx(ge,{active:ae(l,we),onClick:()=>T(!0),onReset:()=>O(we),size:"sm",icon:e.jsx(je,{icon:ye,size:"sm"})}):null;return nt({title:"Rewards",subtitle:"Your points, badges & recognition",searchPlaceholder:b==="myRewards"?!1:"Search by employee name",tabs:{items:u,activeTab:b,onSwitch:x},rightAction:q,deps:[b,R,S,l,i,u]}),e.jsxs(e.Fragment,{children:[b==="myRewards"&&e.jsx(vt,{}),b==="myNominations"&&p&&e.jsx(Dt,{filters:R,search:m}),b==="assignedRewards"&&j&&e.jsx(Mt,{filters:S,search:m}),b==="allRewards"&&N&&e.jsx(Lt,{filters:l,search:m}),e.jsx(qt,{open:r,onClose:y}),e.jsx(Vt,{open:v,onClose:I,onApply:E,currentFilters:R}),e.jsx(Ue,{open:c,onClose:o,onApply:d,currentFilters:S,title:"Assigned Rewards"}),e.jsx(Ue,{open:D,onClose:k,onApply:O,currentFilters:l,title:"All Rewards"})]})};export{js as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.