<?php

namespace App\Controller\Admin;

use App\Entity\Customer;
use App\Entity\Payment;
use App\Entity\Ticket;
use App\Repository\PaymentRepository;
use App\Repository\TicketRepository;
use EasyCorp\Bundle\EasyAdminBundle\Attribute\AdminDashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;

#[AdminDashboard(routePath: '/admin', routeName: 'admin')]
class ViewController extends AbstractDashboardController
{
    public function __construct(private readonly PaymentRepository $paymentRepository, private readonly TicketRepository $ticketRepository)
    {
    }

    #[Route('/admin', name: 'admin')]
    public function index(): Response
    {
        return $this->render('admin/dashboard.html.twig', [
            'totalMoney' => $this->paymentRepository->getTotalMoneyMade(),
            'foodData' => $this->ticketRepository->getFoodData(),
            'totalTickets' => $this->ticketRepository->count(),
        ]);
    }

    public function configureDashboard(): Dashboard
    {
        return Dashboard::new()->setTitle('Abiball Admin Interface');
    }

    public function configureMenuItems(): iterable
    {
        yield MenuItem::linktoDashboard('Dashboard', 'fa fa-home');
        yield MenuItem::section('Daten');
        yield MenuItem::linkToCrud('Kunden', 'fa fa-users', Customer::class);
        yield MenuItem::linkToCrud('Tickets', 'fa fa-ticket', Ticket::class);
        yield MenuItem::linkToCrud('Zahlungen', 'fa fa-money', Payment::class);
    }
}
