import { ChangeDetectionStrategy, Component, inject } from '@angular/core';
import { CommonModule } from '@angular/common';
import { Router } from '@angular/router';
import { AdminModerationFacade } from '../facade/admin-moderation.facade';
import { AdminReportTargetType } from '../models/admin-report.model';
import { TranslatePipe } from '../../../../i18n/translate.pipe';
import { LanguageService } from '../../../../services/language.service';
import { ButtonComponent } from '../../../../shared/ui/button/button.component';
import { BadgeComponent } from '../../../../shared/ui/badge/badge.component';
import { TableComponent } from '../../../../shared/ui/table/table.component';
import { EmptyStateComponent } from '../../../../shared/ui/empty-state/empty-state.component';
import { SkeletonComponent } from '../../../../shared/ui/skeleton/skeleton.component';

@Component({
  selector: 'app-admin-reports-list-page',
  standalone: true,
  imports: [CommonModule, TranslatePipe, ButtonComponent, BadgeComponent, TableComponent, EmptyStateComponent, SkeletonComponent],
  templateUrl: './admin-reports-list-page.component.html',
  styleUrls: ['./admin-reports-list-page.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class AdminReportsListPageComponent {
  readonly facade = inject(AdminModerationFacade);
  private readonly router = inject(Router);
  private readonly languageService = inject(LanguageService);

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

  back(): void {
    void this.router.navigate([this.languageService.currentLanguage(), 'backoffice', 'moderation']);
  }

  openTarget(targetType: AdminReportTargetType, targetId: string): void {
    if (!targetId) return;
    const lang = this.languageService.currentLanguage();
    if (targetType === 'review') {
      void this.router.navigate([lang, 'backoffice', 'moderation', targetId]);
    } else if (targetType === 'product') {
      void this.router.navigate([lang, 'backoffice', 'products', targetId, 'edit']);
    }
  }

  canOpen(targetType: AdminReportTargetType, targetId: string): boolean {
    return !!targetId && (targetType === 'review' || targetType === 'product');
  }
}
