{"version":3,"file":"cccteam-ccc-lib-auth-has-permission.mjs","sources":["../../../projects/ccc-lib/auth-has-permission/has-permission.directive.ts","../../../projects/ccc-lib/auth-has-permission/cccteam-ccc-lib-auth-has-permission.ts"],"sourcesContent":["import { Directive, Input, TemplateRef, ViewContainerRef, effect, inject, signal } from '@angular/core';\nimport { AuthService } from '@cccteam/ccc-lib/auth-service';\nimport { PermissionScope } from '@cccteam/ccc-lib/types';\n\n@Directive({\n  selector: '[cccHasPermission]',\n  standalone: true,\n})\nexport class HasPermissionDirective {\n  private auth = inject(AuthService);\n  private templateRef = inject(TemplateRef<unknown>);\n  private viewContainer = inject(ViewContainerRef);\n\n  private scope = signal<PermissionScope | undefined>(undefined);\n\n  @Input()\n  set cccHasPermission(scope: PermissionScope) {\n    this.scope.set(scope);\n  }\n\n  constructor() {\n    effect(() => {\n      const scope = this.scope();\n\n      if (this.auth.hasPermission(scope) && this.auth.authenticated()) {\n        if (!this.viewContainer.get(0)) {\n          this.viewContainer.createEmbeddedView(this.templateRef);\n        }\n      } else {\n        this.viewContainer.clear();\n      }\n    });\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;;MAQa,sBAAsB,CAAA;AACzB,IAAA,IAAI,GAAG,MAAM,CAAC,WAAW,CAAC;AAC1B,IAAA,WAAW,GAAG,MAAM,EAAC,WAAoB,EAAC;AAC1C,IAAA,aAAa,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAExC,IAAA,KAAK,GAAG,MAAM,CAA8B,SAAS,4EAAC;IAE9D,IACI,gBAAgB,CAAC,KAAsB,EAAA;AACzC,QAAA,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC;IACvB;AAEA,IAAA,WAAA,GAAA;QACE,MAAM,CAAC,MAAK;AACV,YAAA,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,EAAE;AAE1B,YAAA,IAAI,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,KA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