import { CommonModule } from '@angular/common';
import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Header } from '../../models/header';
import {
  faSort,
  faSortDown,
  faSortUp,
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeModule } from '@fortawesome/angular-fontawesome';
import { SORT } from '../../enums/sort';
import { Result } from '../../models/result';
import { Page } from '../../models/page';

@Component({
  selector: 'fbi-table',
  standalone: true,
  imports: [CommonModule, FontAwesomeModule],
  templateUrl: './table.component.html',
  styleUrl: './table.component.scss',
})
export class TableComponent {
  @Input() data!: Result;

  @Output() page = new EventEmitter<Page>();
  @Output() sort = new EventEmitter<Header>();

  faSortDown = faSortDown;
  faSortUp = faSortUp;
  faSort = faSort;
  SORT = SORT;

  onPage(event: MouseEvent): void {
    event.stopPropagation();
    this.page.emit();
  }

  onSort(event: MouseEvent, header: Header): void {
    event.stopPropagation();
    this.sort.emit(header);
  }
}
