import { Component, OnInit, OnDestroy } from '@angular/core';
import { TaModalServiceService, MODAL_CONTENT, MODAL_STATE } from 'app/ta/ta-modal-service.service';

@Component({
  selector: 'app-ta-modal-select-reject',
  templateUrl: './ta-modal-select-reject.component.html',
  styleUrls: ['./ta-modal-select-reject.component.scss']
})
export class TaModalSelectRejectComponent implements OnInit, OnDestroy {

  showSelect: boolean;
  showReject: boolean;
  showModal: boolean;

  private subscriptions = [];

  constructor(
    private modalService: TaModalServiceService
  ) {
    this.subscriptions.push(this.modalService.modal_content.subscribe(content => {
      console.log('content selected', content);
      this.showReject = content == MODAL_CONTENT.REJECT;
      this.showSelect = content == MODAL_CONTENT.SELECT;
    }))
  
    console.log('init modal component');
    this.subscriptions.push(this.modalService.modal_state.subscribe(state => {
      console.log('state', state);
      this.showModal = state == MODAL_STATE.OPEN;
    }));
    
  }

  ngOnInit() {
  }

  ngOnDestroy() {
    this.subscriptions.forEach(sub => {
      sub.unsubscribe();
    });
  }

  modalCancel() {
    this.modalService.cancel();
  }

  modalConfirm() {
    this.modalService.confirm();
  }


}
