import { Component, OnInit } from '@angular/core';
import { AdminPanelService } from './admin-panel.service';

@Component({
  selector: 'app-admin-panel',
  templateUrl: './admin-panel.component.html',
  styleUrls: ['./admin-panel.component.css']
})
export class AdminPanelComponent implements OnInit {
  paymentInfos: any[] = [];

  constructor(private adminPanelService: AdminPanelService) { }

  ngOnInit(): void {
    this.loadPaymentInfo();
  }

  loadPaymentInfo(): void {
    this.adminPanelService.getPaymentInfo().subscribe(
      data => {
        // Сортировка на стороне клиента с явными типами и скобочным синтаксисом
        this.paymentInfos = data.sort((a: Record<string, any>, b: Record<string, any>) => {
          const dateA = new Date(a['Dat']);
          const dateB = new Date(b['Dat']);
          return dateB.getTime() - dateA.getTime();
        });
      },
      error => {
        console.error('Error loading payment info:', error);
      }
    );
  }
}
