<?php

namespace App\Controller\Admin;

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;

#[AdminDashboard(routePath: '/admin', routeName: 'admin')]
class DashboardController extends AbstractDashboardController
{
    public function index(): Response
    {
        // Redirect to Games CRUD index by default
        $adminUrlGenerator = $this->container->get(\EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator::class);
        $url = $adminUrlGenerator->setController(\App\Controller\Admin\GameCrudController::class)->generateUrl();
        return $this->redirect($url);

        // Option 1. You can make your dashboard redirect to some common page of your backend
        //
        // 1.1) If you have enabled the "pretty URLs" feature:
        // return $this->redirectToRoute('admin_user_index');
        //
        // 1.2) Same example but using the "ugly URLs" that were used in previous EasyAdmin versions:
        // $adminUrlGenerator = $this->container->get(AdminUrlGenerator::class);
        // return $this->redirect($adminUrlGenerator->setController(OneOfYourCrudController::class)->generateUrl());

        // Option 2. You can make your dashboard redirect to different pages depending on the user
        //
        // if ('jane' === $this->getUser()->getUsername()) {
        //     return $this->redirectToRoute('...');
        // }

        // Option 3. You can render some custom template to display a proper dashboard with widgets, etc.
        // (tip: it's easier if your template extends from @EasyAdmin/page/content.html.twig)
        //
        // return $this->render('some/path/my-dashboard.html.twig');
    }

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

    public function configureMenuItems(): iterable
    {
        yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
        yield MenuItem::section('Game Management');
        yield MenuItem::linkToCrud('Games', 'fas fa-gamepad', \App\Entity\Game::class);
        yield MenuItem::section('Universe');
        yield MenuItem::linkToCrud('Galaxies', 'fas fa-galactic-republic', \App\Entity\Galaxy::class);
        yield MenuItem::linkToCrud('Sectors', 'fas fa-project-diagram', \App\Entity\Sector::class);
        yield MenuItem::linkToCrud('Systems', 'fas fa-sun', \App\Entity\System::class);
        yield MenuItem::linkToCrud('Planets', 'fas fa-globe', \App\Entity\Planet::class);
        yield MenuItem::section('Accounts');
        yield MenuItem::linkToCrud('Users', 'fas fa-user', \App\Entity\User::class);
        yield MenuItem::linkToCrud('Players', 'fas fa-users', \App\Entity\Player::class);
    }
}
