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 { getHazardTypeText } from '../../../hazard.utils';
import { getPositionLikeDtoText } from './../../../../../../shared/compose-position-pick-modal/compose-position-pick-modal.component';

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 riskTypeName() {
    return this.knowledge.getTypeName(this.data.riskType);
  }
  get categoryName() {
    return this.knowledge.getCategoryName(this.data.riskCategory, this.data.riskType);
  }
  get riskItemTitle() {
    return this.knowledge.getRiskItemTitle(this.data.riskPoint);
  }
  get typeName() {
    return getHazardTypeText(this.data.type);
  }
  get responsibleDepartmentName() {
    return this.basic.getDepartmentName(this.data.toDepartment);
  }
  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 + '%';
  }
  get positionName() {
    return getPositionLikeDtoText(this.data, this.basic.lines, this.basic.positions, this.basic.positionCategories);
  }
  get equipmentName() {
    return this.basic.getEquipmentName(this.data.equipment);
  }
  get operationName() {
    return this.basic.getOperationName(this.data.operation);
  }
}
