import { Component, OnInit, ViewChild, Input, SimpleChanges, EventEmitter, Output } from '@angular/core';
import { FormGroup, NgForm } from '@angular/forms';

@Component({
  selector: 'app-save-confirmation',
  templateUrl: './save-confirmation.component.html',
  styleUrls: ['./save-confirmation.component.scss']
})
export class SaveConfirmationComponent implements OnInit {
  @Input() modal;
  @Input() formGrp: FormGroup;
  @Input() formDir?: NgForm;
  @Input() type;
  @Input() labels;
  @Output() public ignoreChange: EventEmitter<any> = new EventEmitter();  
  @Output() public save: EventEmitter<any> = new EventEmitter();
  @Output() public hideModal: EventEmitter<any> = new EventEmitter();
  
  constructor() { }

  ngOnInit() {}

  ngOnChanges(changes: SimpleChanges) {
    if (changes.labels) {
      this.labels = changes.labels.currentValue;
    }
    if (changes.type) {
      this.type = changes.type.currentValue;
    }
  }

  ignoreChanges() {
    this.ignoreChange.emit();
  }

  closeModal() {
    this.hideModal.emit();
  }

  saveModal() {
    this.save.emit();
  }
}
