import { Component, EventEmitter, Input, Output } from '@angular/core';
import { CommonNzModule } from '../../../../../common.nz.module';
import { hazardFinalStatusOptions, hazardLevelOptions, SearchParams } from '../../hazard.utils';

@Component({
  selector: 'hazard-search',
  standalone: true,
  imports: [CommonNzModule],
  templateUrl: './hazard-search.component.html',
  styleUrl: './hazard-search.component.less',
})
export class HazardSearchComponent {
  @Input() isTaskRelative: boolean = false;
  @Output() onChange = new EventEmitter<SearchParams>();
  @Output() onExitTaskRelative = new EventEmitter<void>();
  state: SearchParams = {
    status: -1,
    finalStatus: '',
    level: '',
    onlyMine: false,
  };
  statusOptions = [{ value: '', label: '全部状态' }, ...hazardFinalStatusOptions];
  levelOptions = [{ value: '', label: '全部等级' }, ...hazardLevelOptions];

  handleExitTaskRelative() {
    this.onExitTaskRelative.emit();
  }
  handleStatusChange(s: string) {
    this.state.finalStatus = s;
    this.onChange.emit(this.state);
  }
  handleLevelChange(l: string) {
    this.state.level = l;
    this.onChange.emit(this.state);
  }
  handleParamsChange() {
    this.onChange.emit(this.state);
  }
  getParams() {
    return this.state;
  }
  get finalStatusText() {
    return this.statusOptions.find(op => op.value === this.state.finalStatus)?.label || '全部状态';
  }
  get levelText() {
    return this.levelOptions.find(op => op.value === this.state.level)?.label || '隐患等级';
  }
}
