import { Component, EventEmitter, Input, OnInit, Output, OnChanges, SimpleChanges } from "@angular/core";
import { NzMessageService } from 'ng-zorro-antd';
@Component({
  selector: "app-dialog-delete",
  templateUrl: "./dialog-delete.component.html",
  styleUrls: ["./dialog-delete.component.less"],
})
export class DialogDeleteComponent implements OnInit, OnChanges {
  @Output() hideDelModalEvent = new EventEmitter<any>();
  @Output() confirmDelEvent = new EventEmitter<any>();
  @Output() cancelDelEvent = new EventEmitter<any>();
  @Input() btnLoading: boolean = false;
  @Input() cancenlLoading: boolean = false;
  @Input() delModal: boolean = false;
  @Input() content: string = "您确定要删除吗？";
  @Input() tips: string = "";
  @Input() confirmTxt: string = "确定";
  @Input() cancelTxt: string = "取消";
  @Input() isChecked: boolean = false;
  @Input() isSelected: boolean = false;
  @Input() isSelectedArr: any[] = [];
  @Input() deptDisplay: number = 0;
  @Input() isShowConfirm: boolean = true;
  @Input() isShowConfirmInfo: string = '';
  @Input() isShowEndDeptId: boolean = false;
  @Input() isShowEndDeptIdArr: any[] = [];
  constructor(private message: NzMessageService) {}

  isRemandClean:boolean = true;
  isLoading:boolean = false;
  recoveryRoom:any = null;
  endDeptId:any = null;

  ngOnInit() {}

  ngOnChanges(changes: SimpleChanges){
    if(changes.delModal && changes.delModal.currentValue){
      this.isRemandClean = true;
      this.isLoading = false;
      // this.recoveryRoom = null;
    }
    if(changes.isShowEndDeptIdArr){
      this.endDeptId = this.isShowEndDeptIdArr.length === 1 ? this.isShowEndDeptIdArr[0].id : null;
      console.log('this.isShowEndDeptIdArr:', this.isShowEndDeptIdArr)
    }
    if(changes.isSelected && changes.isSelectedArr){
      if(changes.isSelectedArr.currentValue.length === 1){
        this.recoveryRoom = changes.isSelectedArr.currentValue[0].id;
      }
    }
  }

  // 隐藏
  hideDelModal(e: string) {
    this.hideDelModalEvent.emit(e);
  }

  // 确认删除
  confirmDel() {
    // 如何送回苏醒室开启，并且未选择苏醒室
    if(this.isSelected && !this.recoveryRoom){
      this.message.info('请选择苏醒科室！');
      return;
    }
    if(this.isShowEndDeptId && !this.endDeptId){
      this.message.info('请选择终点科室！');
      return;
    }
    let data:any = {};
    if(this.isChecked){
      data.isRemandClean = this.isRemandClean;
    }
    if(this.isSelected){
      data.recoveryRoom = this.recoveryRoom;
    }
    if(this.isShowEndDeptId){
      data.endDeptId = this.endDeptId;
    }
    this.confirmDelEvent.emit(data);
  }

  // 取消|否
  cancel(type: string) {
    if (type == "cancel") {
      //取消
      this.hideDelModal("cancel");
    } else if (type == "no") {
      //否
      this.cancelDelEvent.emit();
    }
  }
}
