import { Component, EventEmitter, Input, Output } from '@angular/core';
import { CommonNzModule } from '../../../../../common.nz.module';
import {
  getPriorityLabel,
  getStatusLabel,
  ProblemAssessmentPriority,
  ProblemAssessmentStatus,
} from '../problem-assessment.utils';
import { KnowledgeService } from './../../../../../services/knowledge.service';

@Component({
  selector: 'problem-assessment-card',
  standalone: true,
  imports: [CommonNzModule],
  templateUrl: './problem-card.component.html',
  styleUrl: './problem-card.component.less',
})
export class ProblemAssessmentCardComponent {
  @Input() data!: ProblemAssessment.ProblemAssessmentDto;
  @Output() onDetail = new EventEmitter<ProblemAssessment.ProblemAssessmentDto>();

  constructor(private readonly knowledge: KnowledgeService) {}

  unassessed = ProblemAssessmentStatus.Unassessed;
  assessing = ProblemAssessmentStatus.Assessing;
  assessed = ProblemAssessmentStatus.Assessed;

  normal = ProblemAssessmentPriority.Normal;
  emergency = ProblemAssessmentPriority.Emergency;

  handleViewDetail() {
    this.onDetail.emit(this.data);
  }

  get statusText() {
    if (this.data.status === ProblemAssessmentStatus.Assessing) {
      return '研判中...';
    }
    return getStatusLabel(this.data.status);
  }

  get priorityText() {
    return getPriorityLabel(this.data.priority);
  }

  get problemTypeText() {
    const typeText = this.knowledge.getTypeName(this.data.type);
    const categoryText = this.knowledge.getCategoryName(this.data.category, this.data.type);
    return `${typeText} - ${categoryText}`;
  }
}
