import { Component, Input, OnInit, output } from '@angular/core';
import { SearchFilters } from '@app/domain/search/search-filters';

@Component({
  selector: 'app-pagination',
  standalone: true,
  imports: [],
  templateUrl: './pagination.component.html',
  styleUrl: './pagination.component.scss',
})
export class PaginationComponent implements OnInit {
  @Input({ required: true }) filters: SearchFilters = {} as SearchFilters;
  onPageChange = output<SearchFilters>();
  currentPage = 1;

  ngOnInit() {
    this.currentPage = this.filters.page!;
  }

  goToPreviousPage() {
    this.currentPage = this.currentPage - 1;
    this.emitPageChange();
  }

  goToNextPage() {
    this.currentPage = this.currentPage + 1;
    this.emitPageChange();
  }

  private emitPageChange() {
    const filters = { ...this.filters, page: this.currentPage };
    this.onPageChange.emit(filters);
  }
}
