import { Component, input } from "@angular/core";

import { JslibModule } from "@bitwarden/angular/jslib.module";
import { ReportProgress } from "@bitwarden/bit-common/dirt/reports/risk-insights";
import { ProgressBarComponent } from "@bitwarden/components";

// Map of progress step to display config
const ProgressStepConfig = Object.freeze({
  [ReportProgress.FetchingMembers]: { message: "reviewingMemberData", progress: 20 },
  [ReportProgress.AnalyzingPasswords]: { message: "analyzingPasswords", progress: 40 },
  [ReportProgress.CalculatingRisks]: { message: "calculatingRisks", progress: 60 },
  [ReportProgress.GeneratingReport]: { message: "generatingReports", progress: 80 },
  [ReportProgress.Saving]: { message: "compilingInsightsProgress", progress: 95 },
  [ReportProgress.Complete]: { message: "reportGenerationDone", progress: 100 },
} as const);

// FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush
// eslint-disable-next-line @angular-eslint/prefer-on-push-component-change-detection
@Component({
  selector: "dirt-report-loading",
  imports: [JslibModule, ProgressBarComponent],
  templateUrl: "./report-loading.component.html",
})
export class ReportLoadingComponent {
  // Progress step input from parent component.
  // Recommended: delay emissions to this input to ensure each step displays for a minimum time.
  // Refer to risk-insights.component for implementation example.
  readonly progressStep = input<ReportProgress>(ReportProgress.FetchingMembers);

  // Expose config map to template for direct lookup
  protected readonly stepConfig = ProgressStepConfig;
}
