{"version":3,"file":"cccteam-ccc-lib-guards.mjs","sources":["../../../projects/ccc-lib/guards/can-deactivate.guard.ts","../../../projects/ccc-lib/guards/cccteam-ccc-lib-guards.ts"],"sourcesContent":["import { inject } from '@angular/core';\nimport { MatDialog } from '@angular/material/dialog';\nimport { CanDeactivateFn, UrlTree } from '@angular/router';\nimport { LeavePageConfirmationModalComponent } from '@cccteam/ccc-lib/ccc-resource-modals';\nimport { FormStateService } from '@cccteam/ccc-lib/ccc-resource-services';\nimport { FRONTEND_LOGIN_PATH } from '@cccteam/ccc-lib/types';\nimport { firstValueFrom, Observable, tap } from 'rxjs';\n\nexport type CanDeactivateType = Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree;\n\nexport interface CanComponentDeactivate {\n  canDeactivate: () => CanDeactivateType;\n}\n\nexport const canDeactivateGuard: CanDeactivateFn<CanComponentDeactivate> = async (_, __, ___, nextState) => {\n  const dialog = inject(MatDialog);\n  const formStateService = inject(FormStateService);\n  const loginPath = inject(FRONTEND_LOGIN_PATH);\n\n  if (nextState?.url.includes(loginPath)) {\n    return true;\n  }\n\n  if (!formStateService.isDirty()) {\n    return true;\n  }\n\n  const existingDialog = dialog.openDialogs.find(\n    (d) => d.componentInstance instanceof LeavePageConfirmationModalComponent,\n  );\n\n  const dialogRef = existingDialog ?? dialog.open(LeavePageConfirmationModalComponent, { delayFocusTrap: false });\n\n  const result = dialogRef.afterClosed().pipe(\n    tap((value) => {\n      if (value === true) {\n        formStateService.resetDirtyForms();\n      }\n    }),\n  );\n\n  return firstValueFrom(result);\n};\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;;;;AAcO,MAAM,kBAAkB,GAA4C,OAAO,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,SAAS,KAAI;AACzG,IAAA,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC;AAChC,IAAA,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACjD,IAAA,MAAM,SAAS,GAAG,MAAM,CAAC,mBAAmB,CAAC;IAE7C,IAAI,SAAS,EAAE,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AACtC,QAAA,OAAO,IAAI;IACb;AAEA,IAAA,IAAI,CAAC,gBAAgB,CAAC,OAAO,EAAE,EAAE;AAC/B,QAAA,OAAO,IAAI;IACb;AAEA,IAAA,MAAM,cAAc,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAC5C,CAAC,CAAC,KAAK,CAAC,CAAC,iBAAiB,YAAY,mCAAmC,CAC1E;AAED,IAAA,MAAM,SAAS,GAAG,cAAc,IAAI,MAAM,CAAC,IAAI,CAAC,mCAAmC,EAAE,EAAE,cAAc,EAAE,KAAK,EAAE,CAAC;AAE/G,IAAA,MAAM,MAAM,GAAG,SAAS,CAAC,WAAW,EAAE,CAAC,IAAI,CACzC,GAAG,CAAC,CAAC,KAAK,KAAI;AACZ,QAAA,IAAI,KAAK,KAAK,IAAI,EAAE;YAClB,gBAAgB,CAAC,eAAe,EAAE;QACpC;IACF,CAAC,CAAC,CACH;AAED,IAAA,OAAO,cAAc,CAAC,MAAM,CAAC;AAC/B;;AC1CA;;AAEG;;;;"}