import { Component, EventEmitter, Input, Output } from '@angular/core';
import { RoundState } from '../../../inspection-plan.utils';
import { CommonNzModule } from './../../../../../../../common.nz.module';

export interface Round {
  meta: Hazard.InspectionPlanRound;
  state: RoundState;
  time: string;
}

const getTimeStateText = (state: RoundState) => {
  switch (state) {
    case RoundState.Current:
      return '当前';
    case RoundState.UnStart:
      return '未开始';
    case RoundState.Expired:
      return '已过期';
    case RoundState.Completed:
      return '已完成';
    default:
      return '';
  }
};

const getTimeStateColor = (state: RoundState) => {
  switch (state) {
    case RoundState.Current:
      return '#007bff';
    case RoundState.Completed:
      return '#22c55e';
    default:
      return '#7d8da6';
  }
};

@Component({
  selector: 'plan-task-rounds',
  standalone: true,
  imports: [CommonNzModule],
  templateUrl: './task-rounds.component.html',
  styleUrl: './task-rounds.component.less',
})
export class TaskRoundsComponent {
  @Output() onSelect = new EventEmitter<Round>();
  @Input() data: Hazard.InspectionPlanDetail = {} as Hazard.InspectionPlanDetail;
  @Input() departmentId = -1;
  @Input() rounds: Round[] = [];
  @Input() selectedRoundId = -1;
  @Input() filled = false;
  // ngOnChanges(changes: SimpleChanges): void {
  //   if (changes['data']) {
  //     this.setRounds();
  //   }
  //   if (changes['departmentId']) {
  //     this.setRounds();
  //   }
  // }

  onRoundChange(round: Round) {
    this.onSelect.emit(round);
  }
  getStatus(d: Hazard.InspectionPlanRound): RoundState {
    const now = new Date();
    if (new Date(d.startDate) > now) {
      return RoundState.UnStart;
    }
    if (new Date(d.endDate) < now) {
      return RoundState.Expired;
    }
    return RoundState.Current;
  }
  getTimeStateColor(state: RoundState) {
    return getTimeStateColor(state);
  }
  getTimeStateText(state: RoundState) {
    return getTimeStateText(state);
  }
  getFilled(d: Hazard.InspectionPlanRound): boolean {
    // 未填写/已填写/已完成
    return d.status !== '未填写';
  }
}
