<?php

namespace App\Controller\Admin;


use App\Entity\CollectifData\CollectifData;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Assets;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Lc\SovBundle\Controller\Dashboard\DashboardAdminController as SovDashboardController;
use Symfony\Component\HttpFoundation\Response;

class DashboardAnimatorController extends SovDashboardController
{
    protected $adminUrlGenerator;

    public function __construct(AdminUrlGenerator $adminUrlGenerator)
    {
        $this->adminUrlGenerator = $adminUrlGenerator;
    }

    public function index(): Response
    {
        $urlCreate = $this->adminUrlGenerator
            ->setController(CollectifDataCrudController::class)
            ->setAction(Action::NEW)
            ->generateUrl();

        $nbForm = $this->getDoctrine()
            ->getRepository(CollectifData::class)
            ->findByUser($this->getUser());

        return $this->render(
            '/adminlte/dashboard-animator.html.twig',
            [
                'urlCreate' => $urlCreate,
                'nbForm' => count($nbForm),
            ]
        );
    }

    public function configureAssets(): Assets
    {
        $assets = parent::configureAssets(); // TODO: Change the autogenerated stub

        $assets->addWebpackEncoreEntry('app-backend');

        return $assets;
    }

    public function configureMenuItems(): iterable
    {
        $urlCreate = $this->adminUrlGenerator
            ->setController(CollectifDataCrudController::class)
            ->setAction(Action::NEW)
            ->generateUrl();

        yield MenuItem::linkToDashboard('dashboard', 'far fa-circle');
        yield MenuItem::linkToUrl('data_collectif_create', 'fas fa-plus', $urlCreate);
        yield MenuItem::subMenu('account', 'fas fa-user')
            ->setSubItems(
                [
                    MenuItem::linkToRoute('account_profile', 'fas fa-user-cog', 'sov_admin_account_profile'),
                    MenuItem::linkToRoute('account_password', 'fas fa-key', 'sov_admin_account_password'),
                ]
            );
    }
}
