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

const hazardStatusColor: Record<string, string> = {
  0: '#5E5E5E',
  1: '#3083E6',
  2: '#21A858',
};
const hazardStatusBgColor: Record<string, string> = {
  0: '#5E5E5E66',
  1: '#3083E666',
  2: '#30E67A66',
};

const hazardStatusText: Record<string, string> = {
  0: '已关闭',
  1: '审核中',
  2: '已处置',
};
@Component({
  selector: 'hazard-card',
  standalone: true,
  imports: [CommonNzModule],
  templateUrl: './card.component.html',
  styleUrl: './card.component.less',
})
export class HazardCardComponent {
  @Input() 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.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 hazardStatusText() {
    return hazardStatusText[this.data.status];
  }
  get hazardStatusBgColor() {
    return this.hazardStatusColor ? this.hazardStatusColor + '28' : '';
  }
  get hazardStatusColor() {
    return hazardStatusColor[this.data.status] ? hazardStatusColor[this.data.status] : '';
  }
  get images() {
    return this.data.images.slice(0, 4).map(i => i);
  }
}
