import {Component, OnInit, ViewChild, ElementRef} from '@angular/core';
import {AlarmService} from '../alarm.service';
import {NzMessageService} from 'ng-zorro-antd';
import {SendLogComponent} from '../modal/send-log/send-log.component';
import {color, pageSize} from '../../app.constants';
import {WarnListComponent} from '../../modal/warn-list/warn-list.component';
import {OverAllService} from '../../overAll/overAll.service';

@Component({
    selector: 'smart-now-alarm',
    templateUrl: './now-alarm.component.html',
    styles: [
            `
            .tag-warn{
                padding: 5px;
            }
            .tag-warn span{
                border: 1px solid #ccc;
                margin-right: 10px;
                display: inline-block;
                margin-bottom: 10px;
                padding: 2px 4px;
                border-radius: 4px;
            }
            :host ::ng-deep .tag-warn .ant-tag{
                margin-right: 0px;
            }
        `
    ]
})
export class NowAlarmComponent implements OnInit {
    @ViewChild('sendLog') sendLog:SendLogComponent;
    @ViewChild('warnList') warnList:WarnListComponent;

    color = color;
    alarmTotal;
    warnCountList = [];
    loading = false;
    pageCount = pageSize;
    pageNum = 1;
    totalNum;

    constructor(public alarmSer: AlarmService, public message: NzMessageService,
                public overAllSer:OverAllService) {
    }

    ngOnInit() {
        this.search(null);
        this.getType();
    }

    search(hostid){
        const obj = {
            isWaring:'yes',
            hostid:hostid,
        };
        this.warnList.getList(obj);
    }

    getType(){
        this.overAllSer.findHostWarningCount().subscribe(
            (res)=>{
                if(res.errCode == 10000){
                    this.warnCountList = res.data;
                }else{
                    this.message.info(res.errMsg);
                }
            }
        )
    }

    change(e){
        this.pageNum = e;
    }

    //打开modal
    showModal(data){
        this.sendLog.showModal(data);
    }

    getTotal(num){
        this.alarmTotal = num;
    }
}
