import {Component, OnInit, TemplateRef, ViewChild} from '@angular/core';

import {Item, NotificationService} from 'm2-core';
import {CdDemoComponent} from '../../../../abstract/CdDemoComponent';
import {CdHelperService} from '../../../../../../service/cd-helper.service';


@Component({
    templateUrl: './cd-notification-service-demo.component.html',
    styleUrls: ['./cd-notification-service-demo.component.scss']
})
export class CdNotificationServiceDemoComponent extends CdDemoComponent implements OnInit {

    constructor(
        private notificationService: NotificationService,
        private cdHelperService: CdHelperService
    ) {
        super();
    }

    @ViewChild('customNotificationBodyTmpl') customNotificationBodyTmpl: TemplateRef<any>;

    lifetimeModel = 3000;

    private get lifetime(): number {
        return this.lifetimeModel && +this.lifetimeModel;
    }

    item?: Item;

    async ngOnInit() {
        this.item = await this.cdHelperService.getAnyItem();
    }

    success() {
        this.notificationService.success(this.customNotificationBodyTmpl, this.lifetime);
    }

    info() {
        this.notificationService.info($localize`Информационное сообщение`, this.lifetime);
    }

    warn() {
        this.notificationService.warn($localize`Предупреждение`, this.lifetime);
    }

    error() {
        this.notificationService.error($localize`Сообщение об ошибке`, this.lifetime,
            () => console.log('close button click callback'));
    }

}
