{"version":3,"file":"cccteam-ccc-lib-ui-notification-service.mjs","sources":["../../../projects/ccc-lib/ui-notification-service/notification.service.ts","../../../projects/ccc-lib/ui-notification-service/cccteam-ccc-lib-ui-notification-service.ts"],"sourcesContent":["import { Injectable, signal } from '@angular/core';\nimport { CreateNotificationMessage, NotificationMessage } from '@cccteam/ccc-lib/types';\n\n@Injectable({\n  providedIn: 'root',\n})\nexport class NotificationService {\n  private notificationId = signal(0);\n  private _notifications = signal<NotificationMessage[]>([]);\n  notifications = this._notifications.asReadonly();\n\n  /**\n   * Adds a new global notification.\n   * @param notification The notification message to add.\n   * @returns The unique ID assigned to the notification.\n   */\n  addGlobalNotification(notification: CreateNotificationMessage): number {\n    this.notificationId.update((id) => id + 1);\n    const newNotification: NotificationMessage = {\n      ...notification,\n      id: this.notificationId(),\n    };\n    const existingNotification = this._notifications().find((n) => n.message === newNotification.message);\n    if (existingNotification) {\n      this.updateNotification({ ...existingNotification, ...newNotification });\n      return existingNotification.id;\n    }\n    this._notifications.update((current) => [...current, newNotification]);\n    return newNotification.id;\n  }\n\n  /**\n   * Dismisses a global notification by its ID.\n   * @param notificationId The ID of the notification to dismiss.\n   */\n  dismissGlobalNotificationById(notificationId: number): void {\n    this._notifications.update((current) => current.filter((notification) => notification.id !== notificationId));\n  }\n\n  /**\n   * Dismisses a specific global notification.\n   * @param notification The notification to dismiss.\n   */\n  dismissGlobalNotification(notification: NotificationMessage): void {\n    this.dismissGlobalNotificationById(notification.id);\n  }\n\n  /**\n   * Updates an existing notification.\n   * @param updatedNotification The notification with updated information.\n   */\n  updateNotification(updatedNotification: NotificationMessage): void {\n    this._notifications.update((current) =>\n      current.map((notification) =>\n        notification.id === updatedNotification.id ? { ...notification, ...updatedNotification } : notification,\n      ),\n    );\n  }\n}\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './index';\n"],"names":[],"mappings":";;;MAMa,mBAAmB,CAAA;AACtB,IAAA,cAAc,GAAG,MAAM,CAAC,CAAC,qFAAC;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