import { Component, EventEmitter, Input, Output } from '@angular/core';
import { CommonNzModule } from '../../../../../common.nz.module';
import { transformTime } from '../../../../../pipe/time.pipe';
import { BasicDataService } from '../../../../../services/basic.service';
import { getCycleText, getHazardPlanTypeText } from '../inspection-plan.utils';

@Component({
  selector: 'plan-card',
  standalone: true,
  imports: [CommonNzModule],
  templateUrl: './plan-card.component.html',
  styleUrl: './plan-card.component.less',
})
export class PlanCardComponent {
  @Input() data!: Hazard.InspectionPlan;
  @Output() onViewDetail = new EventEmitter<Hazard.InspectionPlan>();
  constructor(private basic: BasicDataService) {
    basic.$fetched.subscribe(() => {
      this.setInfoValues();
    });
  }
  ngOnInit() {
    this.setInfoValues();
  }
  infos = [
    { label: '排查周期', value: '' },
    { label: '排查时间', value: '' },
    { label: '发布时间', value: '' },
    { label: '发布部门', value: '' },
  ];
  setInfoValues() {
    if (!this.data) return;
    const [du, time, createTime, d] = this.infos;
    const { startDate, endDate, createdDate, createUserDept } = this.data;
    du.value = getCycleText(this.data);
    time.value = `${transformTime(startDate, 'YYYY/MM/DD')} - ${transformTime(endDate, 'YYYY/MM/DD')}`;
    createTime.value = transformTime(createdDate, 'YYYY/MM/DD');
    d.value = this.basic.getDepartmentName(createUserDept);
  }
  handleViewDetail(data: Hazard.InspectionPlan) {
    this.onViewDetail.emit(data);
  }
  get typeText() {
    return getHazardPlanTypeText(this.data.type);
  }
  get statusText() {
    return this.data.status;
    // return getHazardPlanStatusText(this.data.status);
  }
}
