import { i18n } from '@osd/i18n' ; import { Subscription } from 'rxjs' ; import { I18nStart } from '../i18n' ; import { ToastsService , ToastsSetup , ToastsStart } from './toasts' ; import { IUiSettingsClient } from '../ui_settings' ; import { OverlayStart } from '../overlays' ; interface SetupDeps { uiSettings : IUiSettingsClient ; } interface StartDeps { i18n : I18nStart ; overlays : OverlayStart ; targetDomElement : HTMLElement ; } public export class NotificationsService { private readonly toasts : ToastsService ; private uiSettingsErrorSubscription ? : Subscription ; private targetDomElement ? : HTMLElement ; constructor ( ) { this . toasts = new ToastsService ( ) ; } public setup ( { uiSettings } ) { const notificationSetup = { toasts : this . toasts . setup ( { uiSettings } ) } ; this . uiSettingsErrorSubscription = uiSettings . getUpdateErrors$ ( ) . subscribe ( ( error ) => { notificationSetup . toasts . addDanger ( { title : i18n . translate ( 'core.notifications.unableUpdateUISettingNotificationMessageTitle' , { defaultMessage : 'Unable to update UI setting' , } ) , text : error . message , } ) ; } ) ; return notificationSetup ; } public start ( { i18n : i18nDep , overlays , targetDomElement } ) { this . targetDomElement = targetDomElement ; const toastsContainer = document . createElement ( 'div' ) ; targetDomElement . appendChild ( toastsContainer ) ; return { toasts : this . toasts . start ( { i18n : i18nDep , overlays , targetDomElement : toastsContainer } ) , } ; } public stop ( ) { this . toasts . stop ( ) ; if ( this . targetDomElement ) { this . targetDomElement . textContent = '' ; } if ( this . uiSettingsErrorSubscription ) { this . uiSettingsErrorSubscription . unsubscribe ( ) ; } } } public export interface NotificationsSetup { /**  ToastsSetup toasts : ToastsSetup ; } public export interface NotificationsStart { /**  ToastsStart toasts : ToastsStart ; }