import { Component, EventEmitter, Input, Output } from '@angular/core';
import { CommonNzModule } from '../../../../../common.nz.module';
import { BasicDataService } from '../../../../../services/basic.service';
import { KnowledgeService } from '../../../../../services/knowledge.service';
import { getHazardFinalStatusColor, getHazardStatusText, hazardLevelColor } from '../../hazard.utils';

import { transformTime } from '../../../../../pipe/time.pipe';
@Component({
  selector: 'hazard-card',
  standalone: true,
  imports: [CommonNzModule],
  templateUrl: './card.component.html',
  styleUrl: './card.component.less',
})
export class HazardCardComponent {
  @Input({ required: true }) data!: Hazard.HazardDto;
  @Output() onViewDetail = new EventEmitter<Hazard.HazardDto>();
  hazardLevelColor = hazardLevelColor;

  constructor(
    private knowledge: KnowledgeService,
    private basic: BasicDataService
  ) {}
  handleViewDetail(data: Hazard.HazardDto) {
    this.onViewDetail.emit(data);
  }
  get typeName() {
    return this.knowledge.getTypeName(this.data.riskType);
  }
  get categoryName() {
    return this.knowledge.getCategoryName(this.data.riskCategory, this.data.riskType);
  }
  get responsibleDepartmentName() {
    return this.basic.getDepartmentName(this.data.toDepartment);
  }
  get hazardStatusText() {
    return getHazardStatusText(this.data.status);
  }
  get hazardFinalStatusBgColor() {
    return this.hazardFinalStatusColor ? this.hazardFinalStatusColor + '28' : '';
  }
  get hazardFinalStatusColor() {
    return getHazardFinalStatusColor(this.data.finalStatus);
  }
  get images() {
    return this.data.images.slice(0, 4).map(i => i);
  }
  get submitDate() {
    return this.data.updatedDate ? transformTime(this.data.updatedDate, 'MM/DD HH:mm') : '';
  }
}
