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';

const hazardLevelColor: Record<string, string> = {
  '重大': '#FA5F25',
  'A': '#FFA100',
  B: '#6600FF',
  C: '#3083E6',
};

@Component({
  selector: 'hazard-detail-header',
  standalone: true,
  imports: [CommonNzModule],
  templateUrl: './detail-header.component.html',
  styleUrl: './detail-header.component.less',
})
export class DetailHeaderComponent {
  @Input() data: Hazard.HazardDto = {} as Hazard.HazardDto;
  @Output() onClose = new EventEmitter<void>();
  constructor(
    private knowledge: KnowledgeService,
    private basic: BasicDataService
  ) {}

  get typeName() {
    return this.knowledge.getTypeName(this.data.type);
  }
  get categoryName() {
    return this.knowledge.getCategoryName(this.data.category, this.data.type);
  }
  get responsibleDepartmentsName() {
    return this.basic.departments
      .filter(d => this.data.responsibleDepartments.includes(d.id))
      .map(d => d.name)
      .join('、');
  }
  get hazardLevelBgColor() {
    return this.hazardLevelColor ? this.hazardLevelColor + '28' : '';
  }
  get hazardLevelColor() {
    return hazardLevelColor[this.data.level] ? hazardLevelColor[this.data.level] : '';
  }
  get levelProgress() {
    return ['C', 'B', 'A', '重'].findIndex(l => this.data.level.indexOf(l) > -1) * 25 + 25 + '%';
  }
}
