1import{a as Ee}from"./chunk-3V54CRWW.js";import{a as M}from"./chunk-WJKNM3YB.js";import{a as Le}from"./chunk-WGTUPIET.js";import{a as Se}from"./chunk-FFJPHGCK.js";import{a as be}from"./chunk-CFALFD4N.js";import"./chunk-AT6KDTNF.js";import{a as V,b as Ce,c as De}from"./chunk-GZB5NQ7K.js";import{a as xe}from"./chunk-FDFMLKGX.js";import"./chunk-FDCM67N4.js";import{f as fe,o as he}from"./chunk-I43TBCCP.js";import{a as ye}from"./chunk-Q2OUKDGN.js";import"./chunk-2YJDS7I7.js";import"./chunk-YTN7TCSL.js";import"./chunk-N7HCJULI.js";import{a as ue,b as ve}from"./chunk-YXP3HIYH.js";import{b as ge,c as _e}from"./chunk-IP3PUWFP.js";import"./chunk-AB427IMW.js";import"./chunk-GC4IZX5C.js";import"./chunk-K2JPOUCJ.js";import"./chunk-FDMELVMQ.js";import"./chunk-D4TCOIRS.js";import{a as de,b as pe}from"./chunk-MRHPGF4Z.js";import{a as re,b as se}from"./chunk-FI5HDU2M.js";import{c as le,d as oe}from"./chunk-RD6CMMYT.js";import"./chunk-43QSOUEJ.js";import"./chunk-EYQMV3B5.js";import"./chunk-IRF7SSK4.js";import"./chunk-RJTNPJVP.js";import"./chunk-ZEKO3T4C.js";import"./chunk-KGLUFYAO.js";import"./chunk-PHU7DBHH.js";import{a as $,b as ee}from"./chunk-DP2Z6ZZS.js";import"./chunk-SXHDWJCP.js";import"./chunk-ZV4QY222.js";import{a as ke}from"./chunk-GOSJH5PI.js";import{f as qe}from"./chunk-QSB5BIGC.js";import{a as Re,c as we}from"./chunk-OXLXO3AU.js";import"./chunk-LWGVMHG7.js";import"./chunk-IJVKP264.js";import"./chunk-WF2PYO5H.js";import{e as me,f as ce}from"./chunk-N6A7VSM7.js";import{a as ie}from"./chunk-XGGGEBNP.js";import"./chunk-DVCUWZW7.js";import{a as ne,b as ae}from"./chunk-JQRWBCXI.js";import"./chunk-62JH7AIE.js";import{a as te}from"./chunk-753BGW7L.js";import"./chunk-FM6R6SQV.js";import"./chunk-YT3SJKED.js";import"./chunk-TBYF2LDC.js";import{c as H,f as Y,j as G,x as J,z as K}from"./chunk-K6JXWQGF.js";import{e as X,f as Z}from"./chunk-K6TR4ND5.js";import"./chunk-LBKYIKKB.js";import"./chunk-DVBSY2HJ.js";import"./chunk-HTVQYICE.js";import"./chunk-GYMQPV7B.js";import{qa as T,ua as Q}from"./chunk-355THWVV.js";import{b as U}from"./chunk-UYEVN2YS.js";import"./chunk-HMPDWT3T.js";import"./chunk-UD64SC5Q.js";import{B as O,l as N,m as j,w as z}from"./chunk-LXYQMMEZ.js";import{$b as p,Ac as W,Bc as q,Jb as u,Kb as n,Lb as a,Lc as w,Mb as _,Nc as S,Pc as L,Tb as f,Yb as g,_a as o,db as D,dc as F,ec as P,fc as B,la as m,lb as A,lc as E,ma as c,mc as k,nc as r,oc as y,pc as R,qc as I,rb as h,uc as x,vc as b,wc as C}from"./chunk-E4JUGTIV.js";import"./chunk-WWX6BADO.js";var Te=["rangePicker"],Ve=()=>({width:"520px"}),Me=()=>({width:"480px"}),Ae=()=>({width:"450px"}),Fe=()=>[10,20,30,50,100];function Pe(s,t){if(s&1){let e=f();n(0,"p-button",53),g("onClick",function(){let l=m(e).$implicit,d=p(3);return c(d.setPreset(l.value))}),a()}if(s&2){let e=t.$implicit;u("label",e.label)}}function Be(s,t){if(s&1){let e=f();n(0,"div",50),h(1,Pe,1,1,"p-button",51),n(2,"p-button",52),g("onClick",function(){m(e);let l=p(2);return c(l.clearDateRange())}),a()()}if(s&2){let e=p(2);o(),u("ngForOf",e.datePresets)}}function We(s,t){if(s&1){let e=f();n(0,"div",39)(1,"div",40)(2,"div",41)(3,"p-autocomplete",42),C("ngModelChange",function(l){m(e);let d=p();return b(d.selectedEmployeesFilter,l)||(d.selectedEmployeesFilter=l),c(l)}),g("completeMethod",function(l){m(e);let d=p();return c(d.fetchEmployeesFilter(l.query))})("ngModelChange",function(l){m(e);let d=p();return c(d.onEmployeeFilterChange(l))}),a(),n(4,"p-datepicker",43,1),C("ngModelChange",function(l){m(e);let d=p();return b(d.selectedDateRange,l)||(d.selectedDateRange=l),c(l)}),g("ngModelChange",function(){m(e);let l=p();return c(l.onDateChange())}),h(6,Be,3,1,"ng-template",44),a(),n(7,"p-select",45),C("ngModelChange",function(l){m(e);let d=p();return b(d.selectedStatus,l)||(d.selectedStatus=l),c(l)}),a(),n(8,"p-select",46),C("ngModelChange",function(l){m(e);let d=p();return b(d.selectedLeaveRequestTypeId,l)||(d.selectedLeaveRequestTypeId=l),c(l)}),a()(),n(9,"div",47)(10,"p-button",48),g("onClick",function(){m(e);let l=p();return c(l.resetFilters())}),a(),n(11,"p-button",49),g("onClick",function(){m(e);let l=p();return c(l.applyFilters())}),a()()()()}if(s&2){let e=p();o(3),x("ngModel",e.selectedEmployeesFilter),u("suggestions",e.employeesList)("dropdown",!0)("multiple",!0)("disabled",e.isEmployee),o(),x("ngModel",e.selectedDateRange),u("showButtonBar",!0),o(3),x("ngModel",e.selectedStatus),u("options",e.statusOptions),o(),x("ngModel",e.selectedLeaveRequestTypeId),u("options",e.leaveRequestTypes)}}function Ne(s,t){if(s&1){let e=f();n(0,"tr")(1,"th"),r(2,"#"),a(),n(3,"th"),r(4,"Employee"),a(),n(5,"th"),r(6,"Department"),a(),n(7,"th"),r(8,"Leave Type"),a(),n(9,"th",56),g("click",function(){m(e);let l=p(2);return c(l.onSort("startDate"))}),n(10,"div",57),r(11," Start Date "),_(12,"i"),a()(),n(13,"th",56),g("click",function(){m(e);let l=p(2);return c(l.onSort("endDate"))}),n(14,"div",57),r(15," End Date "),_(16,"i"),a()(),n(17,"th",56),g("click",function(){m(e);let l=p(2);return c(l.onSort("totalDays"))}),n(18,"div",57),r(19," Total Days "),_(20,"i"),a()(),n(21,"th"),r(22,"Status"),a(),n(23,"th"),r(24,"Applied At"),a(),n(25,"th"),r(26,"Actions"),a()()}if(s&2){let e=p(2);o(12),k(e.getSortIcon("startDate")),o(4),k(e.getSortIcon("endDate")),o(4),k(e.getSortIcon("totalDays"))}}function je(s,t){if(s&1){let e=f();n(0,"tr")(1,"td"),r(2),a(),n(3,"td")(4,"div",58),_(5,"app-employee-avatar",59),n(6,"span",60),g("click",function(){let l=m(e).$implicit,d=p(2);return c(d.onViewLeaveRequest(l))}),r(7),a()()(),n(8,"td"),r(9),a(),n(10,"td"),r(11),a(),n(12,"td"),r(13),w(14,"date"),a(),n(15,"td"),r(16),w(17,"date"),a(),n(18,"td"),r(19),a(),n(20,"td"),_(21,"p-tag",61),a(),n(22,"td"),r(23),w(24,"date"),a(),n(25,"td")(26,"div",62)(27,"p-button",63),g("onClick",function(){let l=m(e).$implicit,d=p(2);return c(d.onViewLeaveRequest(l))}),a(),n(28,"p-button",64),g("onClick",function(){let l=m(e).$implicit,d=p(2);return c(d.openEditDialog(l))}),a(),n(29,"p-button",65),g("onClick",function(){let l=m(e).$implicit,d=p(2);return c(d.openDeleteDialog(l))}),a()()()()}if(s&2){let e=t.$implicit,i=t.rowIndex,l=p(2);o(2),y(i+1),o(3),u("name",e.employeeName)("imageId",e.profileImageId),o(2),R(" ",e.employeeName," "),o(2),y(e.departmentName),o(2),y(e.leaveTypeName),o(2),y(S(14,16,e.startDate,"mediumDate")),o(3),y(S(17,19,e.endDate,"mediumDate")),o(3),y(e.totalDays),o(2),u("value",e.status)("severity",l.getStatusSeverity(e.status)),o(2),y(S(24,22,e.appliedAt,"medium")),o(5),u("disabled",!l.canEditLeave(e))("pTooltip",l.canEditLeave(e)?"Edit this request":"Only pending requests can be edited."),o(),u("disabled",!l.canDeleteLeave(e))("pTooltip",l.deleteDisabledReason(e))}}function ze(s,t){s&1&&(n(0,"tr")(1,"td",66),r(2,"No leave requests found for the selected filters."),a()())}function Oe(s,t){if(s&1){let e=f();n(0,"div",54)(1,"p-table",55),g("onLazyLoad",function(l){m(e);let d=p();return c(d.onLazyLoad(l))}),h(2,Ne,27,6,"ng-template",null,2,L)(4,je,30,25,"ng-template",null,3,L)(6,ze,3,0,"ng-template",null,4,L),a()()}if(s&2){let e=p();o(),u("value",e.leaveRequests)("paginator",!0)("rows",e.pageSize)("totalRecords",e.totalRecords)("loading",e.loading)("rowsPerPageOptions",q(8,Fe))("lazy",!0)("first",(e.page-1)*e.pageSize)}}function Ue(s,t){s&1&&(n(0,"div",67)(1,"div",68),_(2,"i",69),n(3,"h3",70),r(4,"No Leave Requests Found"),a(),n(5,"p",71),r(6,"No leave requests found for the selected filters"),a()()())}function Qe(s,t){if(s&1&&(n(0,"div",72),_(1,"i",73),n(2,"span",34),r(3," This employee only has "),n(4,"b"),r(5),a(),r(6," day(s) remaining for this leave type, but this request is for "),n(7,"b"),r(8),a(),r(9,' day(s). Click "Approve Anyway" to approve despite the shortfall. '),a()()),s&2){let e=p();o(5),y(e.insufficientBalanceInfo.remainingDays),o(3),y(e.insufficientBalanceInfo.requestedDays)}}function He(s,t){if(s&1){let e=f();n(0,"div",74)(1,"p-button",75),g("onClick",function(){m(e);let l=p();return c(l.leaveDecisionDialogVisible=!1)}),a(),n(2,"p-button",76),g("onClick",function(){m(e);let l=p();return c(l.submitLeaveDecision())}),a()()}if(s&2){let e=p();o(),u("disabled",e.leaveDecisionSubmitting),o(),u("label",e.leaveDecisionAction==="reject"?"Reject":e.insufficientBalanceInfo?"Approve Anyway":"Approve")("icon",e.leaveDecisionAction==="approve"?"pi pi-check-circle":"pi pi-times-circle")("severity",e.leaveDecisionAction==="approve"?e.insufficientBalanceInfo?"warn":"success":"danger")("loading",e.leaveDecisionSubmitting)}}function Ye(s,t){if(s&1&&(n(0,"div",77),r(1),w(2,"date"),a()),s&2){let e=p();o(),I(" ",e.editingRequest.employeeName,"'s request, filed ",S(2,2,e.editingRequest.appliedAt,"medium"),". ")}}function Ge(s,t){if(s&1){let e=f();n(0,"p-button",78),g("onClick",function(){m(e);let l=p();return c(l.editDialogVisible=!1)}),a(),n(1,"p-button",79),g("onClick",function(){m(e);let l=p();return c(l.saveEdit())}),a()}if(s&2){let e=p();u("disabled",e.editSubmitting),o(),u("loading",e.editSubmitting)("disabled",!e.canSaveEdit)}}function Je(s,t){if(s&1&&(n(0,"p",80),r(1," This leave was approved, so deleting it returns "),n(2,"b"),r(3),a(),r(4),a()),s&2){let e=p();o(3),y(e.selectedForDelete==null?null:e.selectedForDelete.totalDays),o(),I(" day(s) to ",e.selectedForDelete==null?null:e.selectedForDelete.employeeName,"'s ",e.selectedForDelete==null?null:e.selectedForDelete.leaveTypeName," balance. ")}}function Ke(s,t){if(s&1){let e=f();n(0,"p-button",81),g("onClick",function(){m(e);let l=p();return c(l.showDeleteDialog=!1)}),a(),n(1,"p-button",82),g("onClick",function(){m(e);let l=p();return c(l.deleteLeaveRequest())}),a()}}function Xe(s,t){s&1&&(n(0,"div",83)(1,"div",84)(2,"div",58),_(3,"p-skeleton",85),n(4,"div",86),_(5,"p-skeleton",87)(6,"p-skeleton",88),a()(),_(7,"p-skeleton",89),a(),n(8,"div",90),_(9,"p-skeleton",91)(10,"p-skeleton",92),a(),n(11,"div",93),_(12,"p-skeleton",94),a(),n(13,"div",95),_(14,"p-skeleton",96),a()())}function Ze(s,t){if(s&1&&(n(0,"div",83)(1,"div",97)(2,"div",58),_(3,"app-employee-avatar",98),n(4,"div")(5,"div",99),r(6),a(),n(7,"div",100),r(8),a()()(),_(9,"p-tag",101),a(),n(10,"div",102)(11,"div",103),r(12),a(),n(13,"div",104),r(14),w(15,"date"),a()(),n(16,"div",105)(17,"div",106)(18,"div",107),r(19,"From"),a(),n(20,"div",99),r(21),w(22,"date"),a()(),n(23,"div",106)(24,"div",107),r(25,"To"),a(),n(26,"div",99),r(27),w(28,"date"),a()(),n(29,"div",106)(30,"div",107),r(31,"Duration"),a(),n(32,"div",99),r(33),a()()(),n(34,"div",108)(35,"div",109),r(36,"Reason"),a(),n(37,"div",110),r(38),a()(),n(39,"div",111)(40,"div",112)(41,"span",113),r(42,"Decided by"),a(),n(43,"span",114),r(44),a()(),n(45,"div",112)(46,"span",113),r(47,"Decided at"),a(),n(48,"span",114),r(49),w(50,"date"),a()(),n(51,"div",115)(52,"span",113),r(53,"Remarks"),a(),n(54,"span",114),r(55),a()()()()),s&2){let e=p();o(3),u("name",e.leaveRequestDetail.employeeName)("imageId",e.leaveRequestDetail.profileImageId),o(3),y(e.leaveRequestDetail.employeeName),o(2),y(e.leaveRequestDetail.employeeEmail),o(),u("value",e.leaveRequestDetail.status)("severity",e.getStatusSeverity(e.leaveRequestDetail.status)),o(3),R(" Leave Request \u2014 ",e.leaveRequestDetail.leaveTypeName," "),o(2),I(" ",e.leaveRequestDetail.departmentName," \xB7 Applied ",S(15,16,e.leaveRequestDetail.appliedAt,"medium")," "),o(7),y(S(22,19,e.leaveRequestDetail.startDate,"mediumDate")),o(6),y(S(28,22,e.leaveRequestDetail.endDate,"mediumDate")),o(6),R("",e.leaveRequestDetail.totalDays," days"),o(5),R(" ",e.leaveRequestDetail.reason||"No reason provided."," "),o(6),R(" ",e.leaveRequestDetail.decidedByEmployeeName||"\u2014"," "),o(5),R(" ",e.leaveRequestDetail.decidedAt?S(50,25,e.leaveRequestDetail.decidedAt,"medium"):"\u2014"," "),o(6),R(" ",e.leaveRequestDetail.decisionRemarks||"\u2014"," ")}}function $e(s,t){if(s&1){let e=f();n(0,"p-button",120),g("onClick",function(){m(e);let l=p(2);return c(l.onRejectLeave())}),a()}}function et(s,t){if(s&1){let e=f();n(0,"p-button",121),g("onClick",function(){m(e);let l=p(2);return c(l.onApproveLeave())}),a()}}function tt(s,t){if(s&1){let e=f();n(0,"div",116)(1,"p-button",117),g("onClick",function(){m(e);let l=p();return c(l.leaveDetailDialogVisible=!1)}),a(),h(2,$e,1,0,"p-button",118)(3,et,1,0,"p-button",119),a()}if(s&2){let e=p();o(2),u("ngIf",e.canTakeDecision(e.leaveRequestDetail)&&e.canApproveLeave),o(),u("ngIf",e.canTakeDecision(e.leaveRequestDetail)&&e.canApproveLeave)}}var Ie=class s{constructor(t,e,i,l,d,v,it,nt){this.hrService=t;this.api=e;this.messageService=i;this.pendingCountService=l;this.route=d;this.quickActions=v;this.currentUser=it;this.permissionService=nt}rangePicker;leaveRequests=[];loading=!1;totalRecords=0;page=1;pageSize=30;sortBy="appliedAt";sortDir="desc";selectedDateRange=[];datePresets=Ce;selectedEmployeesFilter=[];employeesList=[];selectedStatus=null;selectedLeaveRequestTypeId=null;leaveRequestTypes=[];employeeFilterExplicitlyCleared=!1;showFilters=!0;showDeleteDialog=!1;selectedLeaveRequestId="";selectedForDelete=null;editDialogVisible=!1;editSubmitting=!1;editingRequest=null;editForm={leaveTypeId:null,dateRange:[],reason:""};reasonMaxLength=500;leaveDetailDialogVisible=!1;
1leaveDetailLoading=!1;leaveRequestDetail=null;leaveDecisionDialogVisible=!1;leaveDecisionAction=null;leaveDecisionRemarks="";leaveDecisionSubmitting=!1;leaveDecisionRemarksMaxLength=500;insufficientBalanceInfo=null;forceApproveConfirmed=!1;statusOptions=[{label:"Pending",value:1},{label:"Approved",value:2},{label:"Rejected",value:3},{label:"Cancelled",value:4}];ngOnInit(){this.initializeDefaultDateRange(),this.initializeDefaultEmployeeFilter(),this.loadLeaveRequestTypes();let t=this.route.snapshot.queryParamMap.get("status");if(t){let e=Number(t);isNaN(e)||(this.selectedStatus=e)}this.loadLeaveRequests()}initializeDefaultEmployeeFilter(){let t=Ee(this.route);if(t){this.selectedEmployeesFilter=[t];return}this.currentUserId&&(this.isAdmin||this.isManager||this.api.getEmployees("").subscribe({next:e=>{this.employeesList=(e||[]).map(l=>({id:l.id,name:l.name}));let i=this.employeesList.find(l=>l.id===this.currentUserId);this.selectedEmployeesFilter=[i||{id:this.currentUserId,name:"Current User"}]},error:()=>{this.selectedEmployeesFilter=[{id:this.currentUserId,name:"Current User"}]}}))}initializeDefaultDateRange(){let t=new Date,e=new Date(t.getFullYear(),t.getMonth()-2,t.getDate());this.selectedDateRange=[e,t]}formatDateForApi(t){if(t instanceof Date){let e=t.getFullYear(),i=String(t.getMonth()+1).padStart(2,"0"),l=String(t.getDate()).padStart(2,"0");return`${e}-${i}-${l}`}return t}get currentUserId(){return this.currentUser.id}get isAdmin(){return this.currentUser.isSuperAdmin}get isManager(){return this.currentUser.hasAnyRole([Re.Manager])}get isEmployee(){return this.currentUser.isEmployee}get isPrivileged(){return this.currentUser.isPrivileged}get canApproveLeave(){return this.permissionService.has(M.hr.leave.approve)}get canDeleteAnyLeave(){return this.permissionService.has(M.hr.leave.deleteRequests)}fetchEmployeesFilter(t=""){this.api.getEmployees((t||"").toLowerCase()).subscribe({next:e=>{this.employeesList=(e||[]).map(i=>({id:i.id,name:i.name}))},error:e=>{console.error("Failed to load employees for filter",e),this.employeesList=[]}})}loadLeaveRequestTypes(){this.api.getCompanyLookupItemsByType(9,!0).subscribe({next:t=>{this.leaveRequestTypes=t.map(e=>({label:e.name,value:e.id}))},error:t=>{console.error("Failed to load Leave Requests:",t),this.leaveRequestTypes=[]}})}toggleFilters(){this.showFilters=!this.showFilters}openApplyLeaveDialog(){let t=this.selectedEmployeesFilter?.length===1?this.selectedEmployeesFilter[0]:null;this.quickActions.open(ke.ApplyLeave,{employeeId:t?.id,employeeName:t?.name}).subscribe(e=>{e.outcome!=="cancelled"&&this.onQuickActionCompleted(e)})}onQuickActionCompleted(t){this.messageService.add({severity:t.outcome==="partial"?"warn":"success",summary:t.outcome==="partial"?"Needs attention":"Done",detail:t.message,life:5e3}),this.page=1,this.loadLeaveRequests()}openDeleteDialog(t){this.selectedLeaveRequestId=t.id,this.selectedForDelete=t,this.showDeleteDialog=!0}onViewLeaveRequest(t){this.leaveDetailDialogVisible=!0,this.leaveDetailLoading=!0,this.leaveRequestDetail=null,this.hrService.getLeaveRequestDetail(t.id).subscribe({next:e=>{this.leaveRequestDetail={id:e.id,employeeName:e.employeeName,employeeEmail:e.employeeEmail,departmentName:e.departmentName,leaveTypeName:e.leaveTypeName,startDate:e.startDate,endDate:e.endDate,totalDays:e.totalDays,reason:e.reason,status:e.status,appliedAt:e.appliedAt,decidedAt:e.decidedAt,decidedByEmployeeName:e.decidedByEmployeeName,decisionRemarks:e.decisionRemarks,employeeId:e.employeeId},this.leaveDetailLoading=!1},error:e=>{this.leaveDetailLoading=!1,this.leaveDetailDialogVisible=!1,this.messageService.add({severity:"error",summary:"Error",detail:e?.error?.message||"Failed to load leave request details."})}})}onApproveLeave(){this.leaveRequestDetail?.id&&(this.leaveDecisionAction="approve",this.leaveDecisionRemarks="",this.insufficientBalanceInfo=null,this.forceApproveConfirmed=!1,this.leaveDecisionDialogVisible=!0)}onRejectLeave(){this.leaveRequestDetail?.id&&(this.leaveDecisionAction="reject",this.leaveDecisionRemarks="",this.insufficientBalanceInfo=null,this.forceApproveC
1onfirmed=!1,this.leaveDecisionDialogVisible=!0)}submitLeaveDecision(){if(!this.leaveRequestDetail?.id||!this.leaveDecisionAction||this.leaveDecisionSubmitting)return;let t={leaveRequestId:this.leaveRequestDetail.id,remarks:this.leaveDecisionRemarks?.trim()||void 0,forceApprove:this.leaveDecisionAction==="approve"?this.forceApproveConfirmed:void 0},e=this.leaveDecisionAction==="approve"?this.hrService.approveLeaveRequest(t):this.hrService.rejectLeaveRequest(t);this.leaveDecisionSubmitting=!0,e.subscribe({next:i=>{this.leaveDecisionSubmitting=!1,this.leaveDecisionDialogVisible=!1,this.insufficientBalanceInfo=null,this.messageService.add({severity:"success",summary:"Success",detail:i?.message||`Leave request ${this.leaveDecisionAction}d successfully.`}),this.leaveDetailDialogVisible=!1,this.loadLeaveRequests(),this.pendingCountService.hrRefresh()},error:i=>{if(this.leaveDecisionSubmitting=!1,i?.status===409&&i?.error?.insufficientBalance){this.insufficientBalanceInfo={remainingDays:i.error.remainingDays,requestedDays:i.error.requestedDays},this.forceApproveConfirmed=!0;return}this.messageService.add({severity:"error",summary:"Error",detail:i?.error?.message||`Failed to ${this.leaveDecisionAction} leave request.`})}})}deleteLeaveRequest(){this.selectedLeaveRequestId&&this.hrService.deleteLeaveRequest(this.selectedLeaveRequestId).subscribe({next:t=>{this.messageService.add({severity:"success",summary:"Success",detail:t?.message||"Leave request deleted successfully."}),this.showDeleteDialog=!1,this.selectedLeaveRequestId="",this.selectedForDelete=null,this.loadLeaveRequests(),this.pendingCountService.hrRefresh()},error:t=>{this.messageService.add({severity:"error",summary:"Error",detail:t?.error?.message||"Failed to delete leave request."})}})}canDeleteLeave(t){return t?this.canDeleteAnyLeave?!0:this.isPendingLeave(t)&&t.employeeId===this.currentUserId:!1}deleteDisabledReason(t){return this.canDeleteLeave(t)?"":this.isPendingLeave(t)?"You can only delete your own requests.":"Only pending requests can be deleted."}isApprovedLeave(t){return(t?.status||"").toLowerCase()==="approved"}canEditLeave(t){return!t||!this.isPendingLeave(t)?!1:this.canApproveLeave||t.employeeId===this.currentUserId}openEditDialog(t){this.editingRequest=t,this.editForm={leaveTypeId:t.leaveTypeId,dateRange:[new Date(t.startDate),new Date(t.endDate)],reason:t.reason||""},this.editDialogVisible=!0}get canSaveEdit(){return!!this.editingRequest&&!!this.editForm.leaveTypeId&&this.editForm.dateRange?.length===2&&!!this.editForm.dateRange[0]&&!!this.editForm.dateRange[1]&&!this.editSubmitting}saveEdit(){this.canSaveEdit&&(this.editSubmitting=!0,this.hrService.updateLeaveRequest(this.editingRequest.id,{leaveTypeId:this.editForm.leaveTypeId,startDate:this.formatDateForApi(this.editForm.dateRange[0]),endDate:this.formatDateForApi(this.editForm.dateRange[1]),reason:this.editForm.reason?.trim()||""}).subscribe({next:t=>{this.editSubmitting=!1,this.editDialogVisible=!1,this.editingRequest=null,this.messageService.add({severity:"success",summary:"Updated",detail:t?.message||"Leave request updated successfully."}),this.loadLeaveRequests()},error:t=>{this.editSubmitting=!1,this.messageService.add({severity:"error",summary:"Error",detail:t?.error?.message||"Failed to update the leave request.",life:6e3})}}))}isPendingLeave(t){return(t?.status||"").toLowerCase()==="pending"}canTakeDecision(t){if(!t?.status)return!1;let e=t.status.toLowerCase();return e!=="approved"&&e!=="rejected"}loadLeaveRequests(){this.loading=!0;let t=this.selectedDateRange?.[0]?this.formatDateForApi(this.selectedDateRange[0]):void 0,e=this.selectedDateRange?.[1]?this.formatDateForApi(this.selectedDateRange[1]):void 0,i;this.selectedEmployeesFilter?.length?i=this.selectedEmployeesFilter.map(d=>d.id).join(","):!this.employeeFilterExplicitlyCleared&&this.currentUserId&&!this.isAdmin&&!this.isManager&&(i=this.currentUserId);let l={page:this.page,pageSize:this.pageSize,sortBy:this.sortBy,sortDir:this.sortDir,fromDate:t,toDate:e,searchedEmployeeIds:i,status:this.selectedStatus,leaveRequestId:this.selectedLeaveRequestTypeId||void 0};this.hrService.getLeaveRequests(l).subscribe({next:d=>{this.leaveRequests=d?.items||[],this.totalRecords=d?.totalCount||0,this.loading=!1},error:d=>{console.error("Failed to load leave requests:",d),this.messageService.add({severity:"error",summary:"Error",detail:"Failed to load leave requests"}),this.loading=!1}})}onEmployeeFilterChange(t){(!t||Array.isArray(t)&&t.length===0)&&(this.employeeFilterExplicitlyCleared=!0)}onDateChange(){}setPreset(t){this.selectedDateRange=De(t),this.page=1,this.loadLeaveRequests(),V(this.rangePicker)}clearDateRange(){this.selectedDateRange=[],V(this.rangePicker)}
1applyFilters(){if(!this.selectedDateRange?.[0]||!this.selectedDateRange?.[1]){this.messageService.add({severity:"warn",summary:"Warning",detail:"Please select both start and end dates"});return}this.page=1,this.loadLeaveRequests()}resetFilters(){this.initializeDefaultDateRange(),this.selectedEmployeesFilter=[],this.employeeFilterExplicitlyCleared=!0,this.selectedStatus=null,this.selectedLeaveRequestTypeId=null,this.sortBy="appliedAt",this.sortDir="desc",this.page=1,this.loadLeaveRequests()}onSort(t){this.sortBy.toLowerCase()===t.toLowerCase()?this.sortDir=this.sortDir==="asc"?"desc":"asc":(this.sortBy=t,this.sortDir="asc"),this.page=1,this.loadLeaveRequests()}onLazyLoad(t){let e=t?.rows||this.pageSize,i=Math.floor((t?.first||0)/e)+1;(i!==this.page||e!==this.pageSize)&&(this.page=i,this.pageSize=e,this.loadLeaveRequests())}getSortIcon(t){return this.sortBy.toLowerCase()!==t.toLowerCase()?"pi pi-sort-alt text-gray-400":this.sortDir==="asc"?"pi pi-sort-amount-up-alt text-blue-600":"pi pi-sort-amount-down text-blue-600"}getStatusSeverity(t){switch((t||"").toLowerCase()){case"approved":return"success";case"pending":return"warn";case"rejected":return"danger";case"cancelled":return"secondary";default:return"secondary"}}static \u0275fac=function(e){return new(e||s)(D(Le),D(ie),D(T),D(xe),D(U),D(qe),D(we),D(te))};static \u0275cmp=A({type:s,selectors:[["app-leave-requests"]],viewQuery:function(e,i){if(e&1&&F(Te,5),e&2){let l;P(l=B())&&(i.rangePicker=l.first)}},features:[W([T])],decls:60,vars:39,consts:[["footer",""],["rangePicker",""],["header",""],["body",""],["emptymessage",""],[1,"card","reports-page"],[1,"reports-header","flex","flex-col","md:flex-row","md:justify-between","md:items-center","mb-4"],[1,"header-title","font-semibold","text-xl"],["keyword","HR.leaveRequest.overview"],[1,"header-actions","flex","items-center","gap-2","mt-2","md:mt-0"],["icon","pi pi-sliders-h","styleClass","p-button-outlined","pTooltip","Toggle Filters","tooltipPosition","top",3,"onClick"],["label","Apply Leave","icon","pi pi-plus",3,"onClick"],["class","filter-section mb-4",4,"ngIf"],["class","mobile-scroll-table",4,"ngIf"],["class","text-center py-12",4,"ngIf"],[3,"visibleChange","visible","header","modal"],[1,"flex","flex-col","gap-3"],[1,"text-sm","text-gray-600","m-0"],["class","flex items-start gap-2 p-3 rounded border border-yellow-300 bg-yellow-50 text-yellow-800",4,"ngIf"],[1,"flex","items-center","justify-between","mb-2"],[1,"block","text-sm","font-medium"],[3,"value","max"],["rows","4","placeholder","Add remarks (optional)",1,"w-full","p-inputtext",3,"ngModelChange","ngModel","maxlength"],["header","Edit Leave Request",3,"visibleChange","visible","modal"],[1,"flex","flex-col","gap-4"],["class","text-sm text-gray-500",4,"ngIf"],[1,"block","text-sm","font-medium","mb-2"],["optionLabel","label","optionValue","value","placeholder","Select leave type","appendTo","body","styleClass","w-full",3,"ngModelChange","ngModel","options"],["selectionMode","range","dateFormat","yy-mm-dd","appendTo","body","styleClass","w-full","placeholder","Start and end date",3,"ngModelChange","ngModel","showIcon"],[1,"block","mt-1","text-gray-500"],["rows","3","placeholder","Reason for this leave",1,"w-full","p-inputtext",3,"ngModelChange","ngModel","maxlength"],["header","Confirm Delete",3,"visibleChange","visible","modal"],[1,"flex","items-start","gap-3"],[1,"pi","pi-exclamation-triangle","text-red-500","text-2xl","mt-0.5"],[1,"text-sm"],[1,"m-0","mb-2"],["class","m-0 font-medium text-red-600",4,"ngIf"],["header","Leave Request Details","styleClass","w-full max-w-2xl p-0 overflow-hidden leave-detail-dialog",3,"visibleChange","visible","modal"],["class","flex flex-col leave-detail-container",4,"ngIf"],[1,"filter-section","mb-4"],[1,"filters-panel","w-full","max-w-none","flex","flex-col","gap-3"],[1,"grid","grid-cols-1","md:grid-cols-2","xl:grid-cols-4","gap-3","items-center"],["optionLabel","name","placeholder","Employees","display","chip","appendTo","body","styleClass","w-full",3,"ngModelChange","completeMethod","ngModel","suggestions","dropdown","multiple","disabled"],["selectionMode","range","dateFormat","yy-mm-dd","appendTo","body","styleClass","w-full","placeholder","Date Range",3,"ngModelChange","ngModel","showButtonBar"],["pTemplate","footer"],["optionLabel","label","optionValue","value","placeholder","All Statuses","appendTo","body",1,"w-full",3,"ngModelChange","ngModel","options"],["optionLabel","label","optionValue","value","placeholder","All Leave Types","appendTo","body",1,"w-full",3,"ngModelChange","ngModel","options"],[1,"flex","justify-start"],["label","Reset","icon","pi pi-refresh","severity","secondary",1,"mr-2",3,"onClick"],["label","Filter","icon","pi pi-filter","severity","primary",3,"onClick"],[1,"flex","flex-wrap","gap-2","p-2","border-t"],["size","small",3,"label","onClick",4,"ngFor","ngForOf"],["label","Clear","size","small","severity","secondary",3,"onClick"],["size","small",3,"onClick","label"],[1,"mobile-scroll-table"],["paginatorDropdownAppendTo","body",1,"p-datatable-gridlines",3,"onLazyLoad","value","paginator","rows","totalRecords","loading","rowsPerPageOptions","lazy","first"],[1,"curs
1or-pointer",3,"click"],[1,"flex","items-center","gap-2"],[1,"flex","items-center","gap-3"],[3,"name","imageId"],[1,"text-primary","cursor-pointer",3,"click"],[3,"value","severity"],[1,"flex","gap-2"],["icon","pi pi-eye","styleClass","p-button-rounded p-button-text p-button-info",3,"onClick"],["icon","pi pi-pencil","styleClass","p-button-rounded p-button-text","tooltipPosition","top",3,"onClick","disabled","pTooltip"],["icon","pi pi-trash","styleClass","p-button-rounded p-button-text p-button-danger","tooltipPosition","top",3,"onClick","disabled","pTooltip"],["colspan","9",1,"text-center"],[1,"text-center","py-12"],[1,"flex","flex-col","items-center","justify-center"],[1,"pi","pi-calendar-times","text-6xl","text-gray-400","mb-4"],[1,"text-xl","font-semibold","text-gray-600","mb-2"],[1,"text-gray-500"],[1,"flex","items-start","gap-2","p-3","rounded","border","border-yellow-300","bg-yellow-50","text-yellow-800"],[1,"pi","pi-exclamation-triangle","mt-1"],[1,"flex","gap-2","justify-end"],["label","Cancel","icon","pi pi-times","severity","secondary",3,"onClick","disabled"],[3,"onClick","label","icon","severity","loading"],[1,"text-sm","text-gray-500"],["label","Cancel","icon","pi pi-times","styleClass","p-button-text",3,"onClick","disabled"],["label","Save Changes","icon","pi pi-check",3,"onClick","loading","disabled"],[1,"m-0","font-medium","text-red-600"],["label","Cancel","icon","pi pi-times","styleClass","p-button-text",3,"onClick"],["label","Delete","icon","pi pi-trash","styleClass","p-button-danger",3,"onClick"],[1,"flex","flex-col","leave-detail-container"],[1,"flex","items-center","justify-between","px-5","py-4","bg-gray-50","border-b","border-gray-200"],["shape","circle","size","2.5rem"],[1,"flex","flex-col","gap-2"],["width","10rem","height","0.9rem"],["width","8rem","height","0.75rem"],["width","4rem","height","1.5rem"],[1,"px-5","pt-5","pb-1"],["width","14rem","height","1.25rem","styleClass","mb-2"],["width","10rem","height","0.75rem"],[1,"mx-5","my-4"],["
1width","100%","height","3.5rem","borderRadius","8px"],[1,"mx-5","mb-4"],["width","100%","height","4rem","borderRadius","8px"],[1,"flex","items-center","justify-between","px-5","py-4","bg-gray-50","border-b","border-gray-200","leave-detail-header"],["size","md",3,"name","imageId"],[1,"text-sm","font-medium","text-gray-900"],[1,"text-xs","text-gray-500"],["styleClass","leave-status-tag",3,"value","severity"],[1,"px-5","pt-5","pb-1","leave-subject-block"],[1,"text-lg","font-medium","text-gray-900"],[1,"text-xs","text-gray-500","mt-0.5"],[1,"mx-5","my-4","flex","rounded-lg","border","border-gray-200","bg-gray-50","overflow-hidden","divide-x","divide-gray-200","leave-date-bar"],[1,"flex-1","py-2.5","px-4","text-center"],[1,"text-xs","uppercase","tracking-wide","text-gray-400","mb-1"],[1,"mx-5","mb-4","border","border-l-[3px]","border-l-violet-400","border-gray-200","rounded-r-lg","px-4","py-3","leave-reason-block"],[1,"text-xs","uppercase","tracking-wide","text-gray-400","font-medium","mb-2"],[1,"text-sm","text-gray-800","leading-relaxed","whitespace-pre-line"],[1,"mx-5","border-t","border-gray-100","pt-3","pb-4","grid","grid-cols-2","gap-x-2","gap-y-2","leave-decision-meta"],[1,"flex","items-baseline","gap-1"],[1,"text-xs","text-gray-400","w-20","shrink-0"],[1,"text-sm","text-gray-800"],[1,"flex","items-baseline","gap-1","col-span-2"],[1,"flex","gap-2","justify-end","leave-detail-footer"],["label","Close","icon","pi pi-times","severity","secondary",3,"onClick"],["label","Reject","icon","pi pi-times-circle","severity","danger",3,"onClick",4,"ngIf"],["label","Approve","icon","pi pi-check-circle","severity","success",3,"onClick",4,"ngIf"],["label","Reject","icon","pi pi-times-circle","severity","danger",3,"onClick"],["label","Approve","icon","pi pi-check-circle","severity","success",3,"onClick"]],template:function(e,i){if(e&1){let l=f();_(0,"p-toast"),n(1,"div",5)(2,"div",6)(3,"h4",7),r(4,"Leave Requests"),_(5,"app-help-icon",8),a(),n(6,"div",9)(7,"p-button",10),g("onClick",function(){return m(l),c(i.toggleFilters())}),a(),n(8,"p-button",11),g("onClick",function(){return m(l),c(i.openApplyLeaveDialog())}),a()()(),h(9,We,12,11,"div",12)(10,Oe,8,9,"div",13)(11,Ue,7,0,"div",14),a(),n(12,"p-dialog",15),C("visibleChange",function(v){return m(l),b(i.leaveDecisionDialogVisible,v)||(i.leaveDecisionDialogVisible=v),c(v)}),n(13,"div",16)(14,"p",17),r(15),a(),h(16,Qe,10,2,"div",18),n(17,"div")(18,"div",19)(19,"label",20),r(20,"Remarks (optional)"),a(),_(21,"app-character-counter",21),a(),n(22,"textarea",22),C("ngModelChange",function(v){return m(l),b(i.leaveDecisionRemarks,v)||(i.leaveDecisionRemarks=v),c(v)}),a()()(),h(23,He,3,5,"ng-template",null,0,L),a(),n(25,"p-dialog",23),C("visibleChange",function(v){return m(l),b(i.editDialogVisible,v)||(i.editDialogVisible=v),c(v)}),n(26,"div",24),h(27,Ye,3,5,"div",25),n(28,"div")(29,"label",26),r(30,"Leave Type"),a(),n(31,"p-select",27),C("ngModelChange",function(v){return m(l),b(i.editForm.leaveTypeId,v)||(i.editForm.leaveTypeId=v),c(v)}),a()(),n(32,"div")(33,"label",26),r(34,"Dates"),a(),n(35,"p-datepicker",28),C("ngModelChange",function(v){return m(l),b(i.editForm.dateRange,v)||(i.editForm.dateRange=v),c(v)}),a(),n(36,"small",29),r(37," Both days are counted, so a single-day leave has the same start and end date. "),a()(),n(38,"div")(39,"div",19)(40,"label",20),r(41,"Reason"),a(),_(42,"app-character-counter",21),a(),n(43,"textarea",30),C("ngModelChange",function(v){return m(l),b(i.editForm.reason,v)||(i.editForm.reason=v),c(v)}),a()()(),h(44,Ge,2,3,"ng-template",null,0,L),a(),n(46,"p-dialog",31),C("visibleChange",function(v){return m(l),b(i.showDeleteDialog,v)||(i.showDeleteDialog=v),c(v)}),n(47,"div",32),_(48,"i",33),n(49,"div",34)(50,"p",35),r(51,"Are you sure you want to delete this leave request?"),a(),h(52,Je,5,3,"p",36),a()(),h(53,Ke,2,0,"ng-template",null,0,L),a(),n(55,"p-dialog",37),C("visibleChange",function(v){return m(l),b(i.leaveDetailDialogVisible,v)||(i.leaveDetailDialogVisible=v),c(v)}),h(56,Xe,15,0,"div",38)(57,Ze,56,28,"div",38)(58,tt,4,2,"ng-template",null,0,L),a()}e&2&&(o(9),u("ngIf",i.showFilters),o(),u("ngIf",i.leaveRequests.length>0),o(),u("ngIf",i.leaveRequests.length===0&&!i.loading),o(),E(q(36,Ve)),x("visible",i.leaveDecisionDialogVisible),u("header",i.leaveDecisionAction==="approve"?"Confirm Approve Leave":"Confirm Reject Leave")("modal",!0),o(3),R(" Are you sure you want to ",i.leaveDecisionAction," this leave request? "),o(),u("ngIf",i.insufficientBalanceInfo),o(5),u("value",i.leaveDecisionRemarks)("max",i.leaveDecisionRemarksMaxLength),o(),x("ngModel",i.leaveDecisionRemarks),u("maxlength",i.leaveDecisionRemarksMaxLength),o(3),E(q(37,Me)),x("visible",i.editDialogVisible),u("modal",!0),o(2),u("ngIf",i.editingRequest),o(4),x("ngModel",i.editForm.leaveTypeId),u("options",i.leaveRequestTypes),o(4),x("ngModel",i.editForm.dateRange),u("showIcon",!0),o(7),u("value",i.editForm.reason)("max",i.reasonMaxLength),o(),x("ngModel",i.editForm.reason),u("maxlength",i.reasonMaxLength),o(3),E(q(38,Ae)),x("visible",i.showDeleteDialog),u("modal",!0),o(6),u("ngIf",i.isApprovedLeave(i.selectedForDelete)),o(3),x("visible",i.leaveDetailDialogVisible),u("modal",!0),o(),u("ngIf",i.leaveDetailLoa
1ding),o(),u("ngIf",!i.leaveDetailLoading&&i.leaveRequestDetail))},dependencies:[be,O,N,j,K,H,Y,J,G,Z,X,Q,_e,ge,he,fe,ee,$,ve,ue,oe,le,pe,de,ce,me,ae,ne,Se,se,re,ye,z],styles:[".reports-page[_ngcontent-%COMP%]{padding:1.5rem}.reports-header[_ngcontent-%COMP%]{border-bottom:1px solid #e5e7eb;padding-bottom:1rem}.header-title[_ngcontent-%COMP%]{color:#374151}.filter-section[_ngcontent-%COMP%]{background:#f9fafb;padding:1rem;border-radius:.5rem;border:1px solid #e5e7eb}.filters-panel[_ngcontent-%COMP%]{width:100%;max-width:100%}.mobile-scroll-table[_ngcontent-%COMP%]{overflow-x:auto}.mobile-scroll-table[_ngcontent-%COMP%] .p-datatable[_ngcontent-%COMP%]{min-width:900px}.leave-detail-container[_ngcontent-%COMP%]{border:1px solid #e5e7eb;border-radius:.5rem}@media (max-width: 768px){.reports-page[_ngcontent-%COMP%]{padding:1rem}.filter-section[_ngcontent-%COMP%]{padding:.75rem}.filters-panel[_ngcontent-%COMP%]{max-width:none}}"]})};export{Ie as LeaveRequestsComponent};
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.