import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { AdminMonitoringFacade } from '../facade/admin-monitoring.facade';
import { AdminDashboardFacade } from '../../dashboard/facade/admin-dashboard.facade';
import { TranslatePipe } from '../../../../i18n/translate.pipe';
import { InputComponent } from '../../../../shared/ui/input/input.component';
import { BadgeComponent } from '../../../../shared/ui/badge/badge.component';
import { TableComponent } from '../../../../shared/ui/table/table.component';
import { SkeletonComponent } from '../../../../shared/ui/skeleton/skeleton.component';
import { EmptyStateComponent } from '../../../../shared/ui/empty-state/empty-state.component';
import { ButtonComponent } from '../../../../shared/ui/button/button.component';

@Component({
  selector: 'app-admin-monitoring-page',
  standalone: true,
  imports: [CommonModule, FormsModule, TranslatePipe, InputComponent, BadgeComponent, TableComponent, SkeletonComponent, EmptyStateComponent, ButtonComponent],
  templateUrl: './admin-monitoring-page.component.html',
  styleUrls: ['./admin-monitoring-page.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class AdminMonitoringPageComponent {
  readonly facade = inject(AdminMonitoringFacade);
  readonly dashboardFacade = inject(AdminDashboardFacade);

  readonly categories = ['all', 'audit', 'security', 'login', 'failed_login', 'api', 'error', 'warning'] as const;

  private readonly queueLabels: Record<string, string> = {
    'order-notifications': 'Order notifications',
    'media-processing': 'Media processing',
    'webhook-delivery': 'Webhook delivery',
  };

  private readonly webhookEventLabels: Record<string, string> = {
    'order.created': 'New order placed',
    'inventory.updated': 'Inventory updated',
  };

  constructor() {
    this.facade.loadAll();
  }

  queueLabel(name: string): string {
    return this.queueLabels[name] ?? name;
  }

  webhookEventLabel(event: string): string {
    return this.webhookEventLabels[event] ?? event;
  }
}
