import { Component, Input, SimpleChanges } from '@angular/core';
import { PieChartComponent } from '../pie-chart/pie-chart.component';
import { CommonNzModule } from './../../../../../common.nz.module';
import { PanelHeaderComponent } from './../panel-header/panel-header.component';
import { PanelNotificationComponent } from './../panel-notification/panel-notification.component';

const redColor: [string, string] = ['#FF7E75', '#FE6257'];
const blueColor: [string, string] = ['#508FFE', '#1E70FF'];
const whiteColor: [string, string] = ['#D9EFFF', '#B6D2E6'];
const yellowColor: [string, string] = ['#FDD568', '#F7C335'];
const greenColor: [string, string] = ['#53EFCD', '#24D3AC'];

@Component({
  selector: 'plan-panel',
  standalone: true,
  imports: [CommonNzModule, PieChartComponent, PanelHeaderComponent, PanelNotificationComponent],
  templateUrl: './plan-panel.component.html',
  styleUrl: './plan-panel.component.less',
})
export class PlanPanelComponent {
  @Input() data: Datav.HazardStatisticsData | null = null;

  total = 0;
  deadline = 0;

  ngOnChanges(changes: SimpleChanges): void {
    if (changes['data']) {
      if (this.data) {
        this.setTotal();
        this.setInfoValues();
      }
    }
  }

  infos: { name: string; value: number; percent: string; colors: [string, string] }[] = [
    { name: '排查任务未制定', value: 30, percent: '30%', colors: redColor },
    { name: '已制定但未下发', value: 16, percent: '16%', colors: whiteColor },
    { name: '已下发但未开展', value: 24, percent: '24%', colors: blueColor },
    { name: '排查任务已开展', value: 20, percent: '20%', colors: greenColor },
    { name: '排查任务已结束', value: 10, percent: '10%', colors: yellowColor },
  ];

  setTotal() {
    this.total = this.data?.troubleshootResolveInfo.total || 0;
    this.deadline = this.data?.troubleshootResolveAdventNumber || 0;
  }
  setInfoValues() {
    const [unMake, made, publish, processing, completed] = this.infos;
    unMake.value = this.data?.troubleshootResolveInfo?.unformulated || 0;
    unMake.percent = this.data?.troubleshootResolveInfo?.unformulatedPercentage || '0%';

    made.value = this.data?.troubleshootResolveInfo?.unissued || 0;
    made.percent = this.data?.troubleshootResolveInfo?.unissuedPercentage || '0%';

    publish.value = this.data?.troubleshootResolveInfo?.uninitiated || 0;
    publish.percent = this.data?.troubleshootResolveInfo?.uninitiatedPercentage || '0%';

    processing.value = this.data?.troubleshootResolveInfo?.initiated || 0;
    processing.percent = this.data?.troubleshootResolveInfo?.initiatedPercentage || '0%';

    completed.value = this.data?.troubleshootResolveInfo?.completed || 0;
    completed.percent = this.data?.troubleshootResolveInfo?.completedPercentage || '0%';

    this.infos = this.infos.slice(); // for refreshing chart
  }
}
