1import{r as p,j as e}from"./vendor-react-DKbe1Umz.js";import{y as Z,cX as _,D as V,Z as J,B as v,c as G,d as q,e as Y,A as Q,E as K,F as R,G as k,C as f,s as T,t as S,v as N,cY as ee,cZ as se,u as $,L as w,S as ae,g as te,h as ne,i as ie,j as de,P as B,O,k as D,R as z,T as U,n as W,c_ as M,c$ as re,d0 as le,d1 as ce,l as b,d2 as oe}from"./index-DZ74KeH3.js";import{E as me}from"./EmptyState-B9ZWMRjO.js";import{C as H}from"./calendar-D1tc6ow-.js";import{C as ue}from"./ContextualHelpButton-DKr5Uxvh.js";import{b3 as xe,k as E,i as ve,ce as C,cd as I,B as X,fG as he,bi as pe,c8 as ge,fH as je,fI as fe,ay as Ne}from"./vendor-ui-DMaW9-Ov.js";import{a as h,g as ye,h as be,y as we,r as A,m as De,p as L,A as Ce}from"./vendor-dates-5UNeOyFW.js";import"./vendor-data-CjSe2wkl.js";import"./vendor-charts-DWX9qznF.js";import"./vendor-forms-C2vWC2ab.js";const Le={Vacation:fe,Sick:je,Personal:ge,Bereavement:pe,"Jury Duty":he,Other:X};function Pe(n){const u=Le[n]||X;return e.jsx(u,{className:"w-5 h-5"})}function F(n){switch(n){case"PENDING":return e.jsxs(b,{variant:"secondary",className:"gap-1","data-testid":"badge-status-pending",children:[e.jsx(Ne,{className:"w-3 h-3"}),"Pending"]});case"APPROVED":return e.jsxs(b,{className:"gap-1 bg-green-600","data-testid":"badge-status-approved",children:[e.jsx(I,{className:"w-3 h-3"}),"Approved"]});case"DENIED":return e.jsxs(b,{variant:"destructive",className:"gap-1","data-testid":"badge-status-denied",children:[e.jsx(C,{className:"w-3 h-3"}),"Denied"]});default:return e.jsx(b,{variant:"outline",children:n})}}function P(n,u){return De(L(u),L(n))+1}function Re({balances:n,isLoading:u,isError:i}){return u?e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:[1,2,3,4,5,6].map(a=>e.jsx(f,{className:"animate-pulse",children:e.jsxs(N,{className:"p-4",children:[e.jsx("div",{className:"h-4 bg-muted rounded w-16 mb-2"}),e.jsx("div",{className:"h-8 bg-muted rounded w-12"})]})},a))}):i?e.jsx(f,{"data-testid":"card-balance-error",children:e.jsxs(N,{className:"p-6 flex items-center gap-3 text-destructive",children:[e.jsx(ve,{className:"w-5 h-5 shrink-0"}),e.jsx("span",{className:"text-sm",children:"Failed to load leave balances. Please try refreshing the page."})]})}):n.length===0?e.jsx(f,{"data-testid":"card-balance-empty",children:e.jsx(N,{className:"p-6 text-center text-muted-foreground",children:e.jsx("span",{className:"text-sm",children:"No leave types configured for your organization."})})}):e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-4",children:n.map(a=>e.jsx(f,{"data-testid":`card-balance-${a.leaveTypeName}`,children:e.jsxs(N,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[Pe(a.leaveTypeName),e.jsx("span",{className:"text-sm font-medium truncate",children:a.leaveTypeName})]}),e.jsx("div",{className:"text-2xl font-bold",children:a.remaining}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[a.used," used / ",a.annualAllowance," total"]}),e.jsx("div",{className:"mt-2 h-1.5 bg-muted rounded-full overflow-hidden",children:e.jsx("div",{className:D("h-full rounded-full transition-all",a.remaining<=0?"bg-red-500":a.remaining<=2?"bg-yellow-500":"bg-green-500"),style:{width:`${a.annualAllowance>0?Math.min(100,(a.annualAllowance-a.used)/a.annualAllowance*100):0}%`}})})]})},a.leaveTypeId))})}function ke({onClose:n}){const{data:u=[]}=ee(),i=se(),{toast:a}=$(),[x,t]=p.useState(""),[d,j]=p.useState(),[o,r]=p.useState(),[l,m]=p.useState(""),c=async()=>{if(!x||!d||!o){a({title:"Error",description:"Please select leave type, start date, and end date",variant:"destructive"});return}if(o<d){a({title:"Error",description:"End date must be after start date",variant:"destructive"});return}try{await i.mutateAsync({leaveTypeId:x,startDate:h(d,"yyyy-MM-dd"),endDate:h(o,"yyyy-MM-dd"),reason:l||void 0}),a({title:"Success",description:"Leave request submitted successfully"}),n()}catch{a({title:"Error",description:"Failed to submit leave request",variant:"destructive"})}},y=u.filter(g=>g.isActive);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(w,{children:"Leave Type"}),e.jsxs(ae,{value:x,onValueChange:t,children:[e.jsx(te,{"data-testid":"select-leave-type",children:e.jsx(ne,{placeholder:"Select leave type"})}),e.jsx(ie,{children:y.map(g=>e.jsx(de,{value:g.id,children:g.name},g.id))})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{children:"Start Date"}),e.jsxs(B,{children:[e.jsx(O,{asChild:!0,children:e.jsxs(v,{variant:"outline",className:D("w-full justify-start text-left font-normal",!d&&"text-muted-foreground"),"data-testid":"input-leave-start-date",children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),d?h(d,"PPP"):"Pick a date"]})}),e.jsx(z,{className:"w-auto p-0",align:"start",children:e.jsx(H,{mode:"single",selected:d,onSelect:j,initialFocus:!0})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(w,{children:"End Date"}),e.jsxs(B,{children:[e.jsx(O,{asChild:!0,children:e.jsxs(v,{variant:"outline",className:D("w-full justify-start text-left font-normal",!o&&"text-muted-foreground"),"data-testid":"input-leave-end-date",children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),o?h(o,"PPP"):"Pick a date"]})}),e.jsx(z,{className:"w-auto p-0",align:"start",children:e.jsx(H,{mode:"single",selected:o,onSelect:r,initialFocus:!0,disabled:d?{before:d}:void 0})})]})]})]}),d&&o&&o>=d&&e.jsxs("div",{className:"text-sm text-muted-foreground",children:["Duration: ",P(h(d,"yyyy-MM-dd"),h(o,"yyyy-MM-dd"))," day(s)"]}),e.jsxs("div",{children:[e.jsx(w,{children:"Reason (optional)"}
1),e.jsx(U,{value:l,onChange:g=>m(g.target.value),placeholder:"Provide a reason for your leave request...","data-testid":"input-leave-reason"})]}),e.jsxs(W,{children:[e.jsx(v,{variant:"outline",onClick:n,"data-testid":"button-cancel-leave",children:"Cancel"}),e.jsx(v,{onClick:c,disabled:i.isPending,"data-testid":"button-submit-leave",children:i.isPending?"Submitting...":"Submit Request"})]})]})}function Te(){const{data:n=[],isLoading:u}=M({scope:"mine"}),i=re(),{toast:a}=$(),x=async t=>{try{await i.mutateAsync(t),a({title:"Cancelled",description:"Leave request has been cancelled"})}catch{a({title:"Error",description:"Failed to cancel leave request",variant:"destructive"})}};return u?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading..."}):n.length===0?e.jsx(me,{icon:E,title:"No leave requests yet",description:"Submit your first leave request above to get started.",testId:"empty-state-leave"}):e.jsx("div",{className:"space-y-3",children:n.map(t=>e.jsxs("div",{className:"flex items-center justify-between p-4 border rounded-lg","data-testid":`request-history-${t.id}`,children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-medium",children:t.leaveTypeName}),F(t.status)]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[t.startDate," to ",t.endDate," (",P(t.startDate,t.endDate)," days)"]}),t.reason&&e.jsx("div",{className:"text-sm text-muted-foreground mt-1",children:t.reason}),t.reviewerNote&&e.jsxs("div",{className:"text-sm mt-1 italic text-muted-foreground",children:["Reviewer note: ",t.reviewerNote]})]}),(t.status==="PENDING"||t.status==="APPROVED")&&e.jsxs(v,{size:"sm",variant:"outline",onClick:()=>x(t.id),disabled:i.isPending,"data-testid":`button-cancel-request-${t.id}`,children:[e.jsx(C,{className:"w-4 h-4 mr-1"}),"Cancel"]})]},t.id))})}function Se(){const{data:n=[],isLoading:u}=M({status:"PENDING"}),{data:i=[],isLoading:a}=M({status:"APPROVED"}),x=le(),t=ce(),{toast:d}=$(),[j,o]=p.useState(""),[r,l]=p.useState(null),[m,c]=p.useState(null),y=async()=>{if(!(!r||!m))try{m==="approve"?(await x.mutateAsync({id:r,note:j||void 0}),d({title:"Approved",description:"Leave request has been approved"})):(await t.mutateAsync({id:r,note:j||void 0}),d({title:m==="revoke"?"Revoked":"Denied",description:`Leave request has been ${m==="revoke"?"revoked":"denied"}. Balance restored.`})),l(null),c(null),o("")}catch{d({title:"Error",description:"Failed to process leave request",variant:"destructive"})}};return u||a?e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading..."}):n.length===0&&i.length===0?e.jsxs("div",{className:"text-center py-8",children:[e.jsx(I,{className:"w-12 h-12 mx-auto text-green-500 mb-3"}),e.jsx("h3",{className:"text-lg font-medium mb-1",children:"All Caught Up!"}),e.jsx("p",{className:"text-muted-foreground",children:"There are no pending leave requests to review."})]}):e.jsxs(e.Fragment,{children:[n.length>0&&e.jsxs("div",{className:"space-y-3 mb-6",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Pending Requests"}),n.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-4 border rounded-lg","data-testid":`pending-leave-${s.id}`,children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsxs("span",{className:"font-medium",children:[s.employeeFirstName," ",s.employeeLastName]}),e.jsx(b,{variant:"outline",children:s.leaveTypeName}),F(s.status)]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s.startDate," to ",s.endDate," (",P(s.startDate,s.endDate)," days)"]}),s.reason&&e.jsx("div",{className:"text-sm text-muted-foreground mt-1",children:s.reason})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(v,{size:"sm",onClick:()=>{l(s.id),c("approve")},"data-testid":`button-approve-leave-${s.id}`,children:[e.jsx(I,{className:"w-4 h-4 mr-1"}),"Approve"]}),e.jsxs(v,{size:"sm",variant:"destructive",onClick:()=>{l(s.id),c("deny")},"data-testid":`button-deny-leave-${s.id}`,children:[e.jsx(C,{className:"w-4 h-4 mr-1"}),"Deny"]})]})]},s.id))]}),i.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"text-sm font-semibold text-muted-foreground uppercase tracking-wide",children:"Approved Leave (can be revoked)"}),i.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-4 border rounded-lg","data-testid":`approved-leave-${s.id}`,children:[e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsxs("span",{className:"font-medium",children:[s.employeeFirstName," ",s.employeeLastName]}),e.jsx(b,{variant:"outline",children:s.leaveTypeName}),F(s.status)]}),e.jsxs("div",{className:"text-sm text-muted-foreground",children:[s.startDate," to ",s.endDate," (",P(s.startDate,
1s.endDate)," days)"]}),s.reason&&e.jsx("div",{className:"text-sm text-muted-foreground mt-1",children:s.reason})]}),e.jsx("div",{className:"flex gap-2",children:e.jsxs(v,{size:"sm",variant:"destructive",onClick:()=>{l(s.id),c("revoke")},"data-testid":`button-revoke-leave-${s.id}`,children:[e.jsx(C,{className:"w-4 h-4 mr-1"}),"Revoke"]})})]},s.id))]}),e.jsx(V,{open:!!r,onOpenChange:s=>{s||(l(null),c(null),o(""))},children:e.jsxs(G,{"data-testid":"dialog-review-leave",children:[e.jsx(q,{children:e.jsxs(Y,{children:[m==="approve"?"Approve":m==="revoke"?"Revoke":"Deny"," Leave Request"]})}),e.jsxs("div",{className:"space-y-4",children:[m==="revoke"&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Revoking an approved leave request will restore the employee's leave balance and remove the associated calendar event."}),e.jsxs("div",{children:[e.jsx(w,{children:"Note (optional)"}),e.jsx(U,{value:j,onChange:s=>o(s.target.value),placeholder:"Add a note for the employee...","data-testid":"input-review-note"})]})]}),e.jsxs(W,{children:[e.jsx(v,{variant:"outline",onClick:()=>{l(null),c(null),o("")},"data-testid":"button-cancel-review",children:"Cancel"}),e.jsx(v,{variant:m==="approve"?"default":"destructive",onClick:y,disabled:x.isPending||t.isPending,"data-testid":"button-confirm-review",children:x.isPending||t.isPending?"Processing...":m==="approve"?"Approve":m==="revoke"?"Revoke":"Deny"})]})]})})]})}function Ae(){const{data:n=[],isLoading:u}=oe(),[i,a]=p.useState(new Date),x=ye(i),t=be(i),d=we({start:x,end:t}),j=r=>n.filter(l=>{const m=L(l.startDate),c=L(l.endDate);return Ce(r,{start:m,end:c})||A(r,m)||A(r,c)});if(u)return e.jsx("div",{className:"text-center py-8 text-muted-foreground",children:"Loading..."});const o=x.getDay();return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"text-lg font-semibold",children:h(i,"MMMM yyyy")}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(v,{variant:"outline",size:"sm",onClick:()=>a(new Date(i.getFullYear(),i.getMonth()-1,1)),"data-testid":"button-team-calendar-prev",children:"Previous"}),e.jsx(v,{variant:"outline",size:"sm",onClick:()=>a(new Date),"data-testid":"button-team-calendar-today",children:"Today"}),e.jsx(v,{variant:"outline",size:"sm",onClick:()=>a(new Date(i.getFullYear(),i.getMonth()+1,1)),"data-testid":"button-team-calendar-next",children:"Next"})]})]}),e.jsxs("div",{className:"grid grid-cols-7 gap-1",children:[["Sun","Mon","Tue","Wed","Thu","Fri","Sat"].map(r=>e.jsx("div",{className:"text-center text-sm font-medium text-muted-foreground p-2",children:r},r)),Array.from({length:o}).map((r,l)=>e.jsx("div",{className:"min-h-20 p-1"},`pad-${l}`)),d.map(r=>{const l=j(r),m=A(r,new Date);return e.jsxs("div",{className:D("min-h-20 p-1 border rounded-md bg-background",m&&"border-primary border-2"),"data-testid":`team-calendar-day-${h(r,"yyyy-MM-dd")}`,children:[e.jsx("div",{className:"text-xs font-medium mb-1",children:h(r,"d")}),e.jsxs("div",{className:"space-y-0.5",children:[l.slice(0,3).map(c=>{var y;return e.jsxs("div",{className:"text-[10px] truncate bg-blue-100 dark:bg-blue-900 text-blue-800 dark:text-blue-200 rounded px-1",title:`${c.employeeFirstName} ${c.employeeLastName} - ${c.leaveTypeName}`,children:[c.employeeFirstName," ",(y=c.employeeLastName)==null?void 0:y[0],"."]},c.id)}),l.length>3&&e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:["+",l.length-3," more"]})]})]},r.toString())})]})]})}function Ge(){const{user:n}=Z(),[u,i]=p.useState(!1),a=["ADMIN","MANAGER"].includes((n==null?void 0:n.role)||""),{data:x=[],isLoading:t,isError:d}=_();return e.jsx("div",{className:"min-h-screen bg-background",children:e.jsxs("main",{className:"mx-auto max-w-full px-4 sm:px-6 py-6 sm:py-8",children:[e.jsxs("div",{className:"mb-6 flex flex-col sm:flex-row sm:items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground","data-testid":"text-page-title",children:"Leave Management"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Manage time-off requests and leave balances"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ue,{}),e.jsxs(V,{open:u,onOpenChange:i,children:[e.jsx(J,{asChild:!0,children:e.jsxs(v,{"data-testid":"button-new-leave-request",children:[e.jsx(xe,{className:"w-4 h-4 mr-2"}),"Request Leave"]})}),e.jsxs(G,{"data-testid":"dialog-new-leave-request",children:[e.jsx(q,{children:e.jsx(Y,{children:"New Leave Request"})}),e.jsx(ke,{onClose:()=>i(!1)})]})]})]})]}),e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold mb-3","data-testid":"text-balance-heading",children:"My Leave Balances"}),e.jsx(Re,{balances:x,isLoading:t,isError:d})]}),e.jsxs(Q,{defaultValue:"my-requests",className:"space-y-4",children:[e.jsxs(K,{"data-testid":"tabs-leave-management",children:[e.jsx(R,{value:"my-requests","data-testid":"tab-my-requests",children:"My Requests"}),a&&e.jsx(R,{value:"pending-review","data-testid":"tab-pending-review",children:"Pending Review"}),a&&e.jsx(R,{value:"team-calendar","data-testid":"tab-team-calendar",children:"Team Calendar"})]}),e.jsx(k,{value:"my-requests",children:e.jsxs(f,{children:[e.jsx(T,{children:e.jsx(S,{children:"My Leave Request History"})}),e.jsx(N,{children:e.jsx(Te,{})})]})}),a&&e.jsx(k,{value:"pending-review",children:e.jsxs(f,{children:[e.jsx(T,{children:e.jsx(S,{children:"Pending Leave Requests"})}),e.jsx(N,{children:e.jsx(Se,{})})]})}),a&&e.jsx(k,{value:"team-calendar",children:e.jsxs(f,{children:[e.jsx(T,{children:e.jsx(S,{children:"Team Leave Calendar"})}),e.jsx(N,{children:e.jsx(Ae,{})})]})})]})]})})}export{Ge 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.