import { Component, OnInit, Output, Input } from '@angular/core';
import { EventEmitter } from '@angular/core';
import { NzMessageService } from 'ng-zorro-antd';
import { addDays, startOfMinute, format } from 'date-fns';

@Component({
  selector: 'app-select-date-yytime',
  templateUrl: './select-date-yytime.component.html',
  styleUrls: ['./select-date-yytime.component.less']
})
export class SelectDateYytimeComponent implements OnInit {
  @Input() date:any;
  @Output() submitFormYytimeE = new EventEmitter();
  @Output() submitFormDirectE = new EventEmitter();
  @Output() cancelFlagHand = new EventEmitter();
  yyDate = null; //预约日期-患者其他服务
  yyTime = null; //预约时间-患者其他服务
  constructor(
    private message: NzMessageService,
  ) { }

  ngOnInit() {
    if(this.date){
      this.yyDate = startOfMinute(new Date(this.date));
      this.yyTime = startOfMinute(new Date(this.date));
    }
  }

  // 下一日(患者其他服务)
  nextDay() {
    this.yyDate = addDays(this.yyDate, 1);
  }

  // 隐藏模态框
  hideModal() {
    this.cancelFlagHand.emit(false)
  }

  // 预约陪检
  submitFormYytime(): void {
    if(!this.yyDate || !this.yyTime) {
      this.message.warning('请选择完整预约时间');
      return;
    }
    this.submitFormYytimeE.emit(format(this.yyDate, 'yyyy-MM-dd') + ' ' + format(startOfMinute(this.yyTime), 'HH:mm:ss'));
  }

  // 立即执行
  submitFormDirect(): void {
    this.submitFormDirectE.emit();
  }
}

