import { Component } from '@angular/core';
import { horizontalInOutReverse300ms } from '../../../../common.animation';
import { CommonNzModule } from '../../../../common.nz.module';
import { FilterButtonGroupComponent } from '../../../../shared/filter-button-group/filter-button-group.component';
import { ProblemAssessmentDetailComponent, ProblemAssessmentDetailConfig } from './detail/detail.component';
import { statusOptions } from './problem-assessment.utils';
import { ProblemAssessmentCardComponent } from './problem-card/problem-card.component';

const getRandomInteger = (x: number) => {
  return Math.floor(Math.random() * x);
};

const getMockData = (): ProblemAssessment.ProblemAssessmentDto => {
  return {
    id: getRandomInteger(100000),
    type: getRandomInteger(3),
    category: getRandomInteger(3),
    reportingTime: '2024-01-01',
    department: '部门',
    status: getRandomInteger(3),
    priority: getRandomInteger(2),
    name: '问题名称',
    creator: '创建人',
    involvedEquipments: [1, 2, 3],
    involvedOperations: [1, 2, 3],
    involvedPositions: [1, 2, 3],
    description: '问题描述',
  };
};

@Component({
  selector: 'app-problem-assessment',
  standalone: true,
  imports: [
    CommonNzModule,
    FilterButtonGroupComponent,
    ProblemAssessmentCardComponent,
    ProblemAssessmentDetailComponent,
  ],
  templateUrl: './problem-assessment.component.html',
  styleUrl: './problem-assessment.component.less',
  animations: [horizontalInOutReverse300ms],
})
export class ProblemAssessmentComponent {
  list: ProblemAssessment.ProblemAssessmentDto[] = Array.from({ length: 10 }).map(() => getMockData());
  detailConfig: ProblemAssessmentDetailConfig = {
    visible: false,
    data: {} as ProblemAssessment.ProblemAssessmentDto,
  };
  statusOptions = statusOptions;
  status: number | undefined = undefined;

  changeStatus(status: number) {
    this.status = status;
  }

  handleViewDetail(data: ProblemAssessment.ProblemAssessmentDto) {
    this.detailConfig.visible = true;
    this.detailConfig.data = data;
  }
  handleCloseDetail() {
    this.detailConfig.visible = false;
  }
}
