import { Injectable , TemplateRef } from '@angular/core' ; import { HsLanguageService } from '../../language/language.service' ; import { HsLayoutService } from './../layout.service' ; export type customToastOptions = { /**
     * Disable text translation
     */ disableLocalization ? : boolean ; /**
     * Toast message background and text style classes, for example - background: (bg-primary, bg-secondary, bg-success, bg-danger, bg-warning, bg-info, bg-light, bg-dark, bg-white)
     * and text: (text-primary, text-secondary, text-success, text-danger, text-warning, text-info, text-light, text-dark, text-white, text-muted)
     */ toastStyleClasses ? : string ; /**
     * Sets custom delay for the toast message
     */ customDelay ? : number ; /**
     * Sets service name from where toast was called
     */ serviceCalledFrom ? : string ; /**
     * Error details
     */ details ? : string [ ] ; } ; @ Injectable ( { providedIn : 'root' , } ) export class HsToastService { constructor ( public HsLanguageService , private HsLayoutService ) { } toasts : any [ ] = [ ] ; param toast remove ( toast ) { this . toasts = this . toasts . filter ( ( t ) => t !== toast ) ; } param textOrTpl param options show ( textOrTpl , options = { } ) { if ( this . toasts . length >= 5 ) { this . toasts = this . toasts . slice ( - 4 ) ; } if ( ! this . toasts . some ( ( toast ) => toast . textOrTpl === textOrTpl && toast ?. serviceCalledFrom === options . serviceCalledFrom ) ) { this . toasts . push ( { textOrTpl , ... options } ) ; } } param header param text param options createToastPopupMessage ( header , text , options = { } ) { this . show ( options . disableLocalization ? text : this . HsLanguageService . getTranslation ( text ) , { header : options . disableLocalization ? header : this . HsLanguageService . getTranslation ( header ) , delay : options . customDelay || 7000 , autohide : true , classname : options . toastStyleClasses || `bg-danger text-light` , serviceCalledFrom : options . serviceCalledFrom , details : options . details || [ ] , } ) ; } shown ( ) { for ( const toastElement of this . HsLayoutService . contentWrapper . querySelectorAll ( '.toast-header .close' ) ) { const classList = toastElement . classList ; classList . add ( 'btn-close' ) ; classList . remove ( 'close' ) ; } } }