import { Component, OnInit, inject, signal } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TranslateModule, TranslateService } from '@ngx-translate/core';
import { CardModule } from 'primeng/card';
import { ChartModule } from 'primeng/chart';
import { ProgressSpinnerModule } from 'primeng/progressspinner';
import { PageHeaderComponent } from '../../../shared/components/page-header/page-header.component';
import { HrReportService } from '../../../core/services/hr-report.service';

@Component({
  selector: 'app-hr-dashboard',
  standalone: true,
  imports: [
    CommonModule,
    TranslateModule,
    CardModule,
    ChartModule,
    ProgressSpinnerModule,
    PageHeaderComponent,
  ],
  templateUrl: './hr-dashboard.component.html',
  styleUrl: './hr-dashboard.component.scss',
})
export class HrDashboardComponent implements OnInit {
  private reportService = inject(HrReportService);
  private translate = inject(TranslateService);

  loading = signal(true);
  workforceData = signal<any>(null);
  attendanceData = signal<any>(null);
  leaveData = signal<any>(null);
  payrollData = signal<any>(null);

  ngOnInit(): void {
    this.loadDashboardData();
  }

  loadDashboardData(): void {
    this.loading.set(true);
    this.reportService.getWorkforceReport().subscribe({
      next: (res) => {
        this.workforceData.set(res.data || res);
        this.loading.set(false);
      },
      error: () => this.loading.set(false),
    });
    this.reportService.getAttendanceReport().subscribe({
      next: (res) => this.attendanceData.set(res.data || res),
      error: () => {},
    });
    this.reportService.getLeaveReport().subscribe({
      next: (res) => this.leaveData.set(res.data || res),
      error: () => {},
    });
    this.reportService.getPayrollSummaryReport().subscribe({
      next: (res) => this.payrollData.set(res.data || res),
      error: () => {},
    });
  }
}
