import{a as p}from"./chunk-CVN2SFTO.js";import{s as l,t as y,w as h,x as N}from"./chunk-CPKBOKTQ.js";import{A as c,G as g,T as a,ka as d,la as L,nd as A,q as u,qa as f,va as m}from"./chunk-PGS4AHIT.js";L();y();var i=function(n){return n[n.InAssignedLocation=1]="InAssignedLocation",n[n.NotInAssignedLocation=2]="NotInAssignedLocation",n[n.NoLocationRestrictions=3]="NoLocationRestrictions",n[n.NoAssignedLocations=4]="NoAssignedLocations",n}(i||{});A();N();var O=(()=>{class n extends p{constructor(e){super(),this.apiService=e,this._isGeofencingEnabled=!0,this.geofencingLoaded=!1}loadGeofencingSettings(){return this.geofencingLoaded?c(this._isGeofencingEnabled):this.apiService.get(l.humanResources.geofencingEnabled).pipe(d(e=>{this._isGeofencingEnabled=e.isGeofencingEnabled,this.geofencingLoaded=!0}),a(e=>(console.warn("Failed to load geofencing settings, defaulting to enabled:",e),this._isGeofencingEnabled=!0,this.geofencingLoaded=!0,c(!0))),g(()=>this._isGeofencingEnabled))}isGeofencingEnabled(){return this._isGeofencingEnabled}checkLocationEntryType(e){return this.apiService.post(l.humanResources.checkLocationEntryType,e).pipe(a(t=>(console.error("Location check failed:",t),c({success:!1,message:"Location check failed",locationCode:null,locationName:null,entryType:null,entryTypeName:null,isWorkFromHome:!1,isLocationRestricted:!0,checkResult:i.NotInAssignedLocation,canActForSelf:!1,canActForOthers:!1}))))}getCurrentLocationAndValidate(e){return new u(t=>{if(!navigator.geolocation){t.next({success:!1,message:"Geolocation is not supported by this browser",locationCode:null,locationName:null,entryType:null,entryTypeName:null,isWorkFromHome:!1,isLocationRestricted:!0,checkResult:i.NotInAssignedLocation,canActForSelf:!1,canActForOthers:!1}),t.complete();return}navigator.geolocation.getCurrentPosition(o=>{let s={worker:e,latitude:o.coords.latitude,longitude:o.coords.longitude};this.checkLocationEntryType(s).subscribe({next:r=>{t.next(r),t.complete()},error:r=>{t.error(r)}})},o=>{let s={worker:e,latitude:null,longitude:null};this.checkLocationEntryType(s).subscribe({next:r=>{t.next(r),t.complete()},error:r=>{t.next({success:!1,message:`Geolocation error: ${o.message}`,locationCode:null,locationName:null,entryType:null,entryTypeName:null,isWorkFromHome:!1,isLocationRestricted:!0,checkResult:i.NotInAssignedLocation,canActForSelf:!1,canActForOthers:!1}),t.complete()}})},{enableHighAccuracy:!0,timeout:1e4,maximumAge:3e5})})}shouldSkipLocationCheck(){return!this.isGeofencingEnabled()}getDefaultPermissions(){return{canActForSelf:!0,canActForOthers:!0}}extractPermissions(e){return{canActForSelf:!!e?.canActForSelf,canActForOthers:!!e?.canActForOthers}}isLocationValid(e){return e?.success===!0}isInAssignedLocation(e){return e?.checkResult===i.InAssignedLocation}hasNoLocationRestrictions(e){return e?.checkResult===i.NoLocationRestrictions}hasNoAssignedLocations(e){return e?.checkResult===i.NoAssignedLocations}isNotInAssignedLocation(e){return e?.checkResult===i.NotInAssignedLocation}isWorkFromHomeAllowed(e){return e?.isWorkFromHome===!0}isLocationRestricted(e){return e?.isLocationRestricted===!0}getLocationCheckMessage(e){return e?.message||"Unknown location check result"}getLocationCode(e){return e?.locationCode||null}getLocationName(e){return e?.locationName||null}getEntryType(e){return e?.entryType||null}getEntryTypeName(e){return e?.entryTypeName||null}validateLocationWithCoordinates(e,t,o){let s={worker:e,latitude:t,longitude:o};return this.checkLocationEntryType(s)}getCurrentPosition(){return new Promise((e,t)=>{if(!navigator.geolocation){t(new Error("Geolocation is not supported by this browser"));return}navigator.geolocation.getCurrentPosition(o=>{e({latitude:o.coords.latitude,longitude:o.coords.longitude})},o=>{t(new Error(`Geolocation error: ${o.message}`))},{enableHighAccuracy:!0,timeout:1e4,maximumAge:0})})}clearGeofencingCache(){this.geofencingLoaded=!1,this._isGeofencingEnabled=!0}reloadGeofencingSettings(){return this.clearGeofencingCache(),this.loadGeofencingSettings()}static{this.\u0275fac=function(t){return new(t||n)(m(h))}}static{this.\u0275prov=f({token:n,factory:n.\u0275fac,providedIn:"root"})}}return n})();export{O as a};
