import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';

@Component({
    selector: 'smart-topology',
    templateUrl: './topology.component.html',
    styles: []
})
export class TopologyComponent implements OnInit {

    isVisible = false;
    title: string;
    validateForm:FormGroup;

    constructor(private fb:FormBuilder) {
    }

    ngOnInit() {
        this.initForm();
    }

    initForm(){
        this.validateForm = this.fb.group(
            {
                name:['',[Validators.required]],
                time:['',[Validators.required]],
                group:['']
            }
        )
    }

    showAddMOodal() {
        this.isVisible = true;
        this.title = '添加拓扑图';
    }

    showEditModal() {
        this.title = '编辑拓扑图';
        this.isVisible = true;
    }

    handleOk(){
        for(const i  in this.validateForm.controls){
            this.validateForm.controls[i].markAsDirty();
            this.validateForm.controls[i].updateValueAndValidity();
        }
        if(this.validateForm.invalid){
            return false;
        }
        if(this.title == "添加拓扑图"){
            this.create();
        }
        if(this.title == "编辑拓扑图"){
            this.update();
        }
    }

    create(){}

    update(){}

    handleCancel() {
        this.isVisible = false;
    }

}
