<?php

namespace App\Controller\Admin;

use App\Entity\Menu;
use App\Entity\Size;
use App\Entity\User;
use App\Entity\Extra;
use App\Entity\Schedule;
use App\Entity\Restaurant;
use App\Entity\UserAddress;
use App\Traits\TranslatorTrait;
use App\Entity\RestaurantCategory;
use App\Controller\Admin\UserCrudController;
use App\Entity\ExtraType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;

class DashboardController extends AbstractDashboardController
{
    use TranslatorTrait;

    /**
     * @Route("/admin", name="admin")
     */
    public function index(): Response
    {
        if (!$this->getUser()->isIsActive()) {
            return $this->render('layout/inactiveUser.html.twig');
        } else {
            $routeBuilder = $this->get(AdminUrlGenerator::class);
            return $this->redirect($routeBuilder->setController(UserCrudController::class)->generateUrl());
        }
    }

    public function configureDashboard(): Dashboard
    {
        return Dashboard::new()
            ->setTitle('<img width="160px;" src="/img/logo.png">')
            ->disableUrlSignatures();
    }

    public function configureMenuItems(): iterable
    {
        if (in_array('ROLE_ADMIN', $this->getUser()->getRoles())) {
            yield MenuItem::section($this->trans('user.labelInPlural'));
                yield MenuItem::linkToCrud($this->trans('user.labelInPlural'), 'fas fa-users', User::class);

            yield MenuItem::section($this->trans('userAddress.name'));
                yield MenuItem::linkToCrud($this->trans('address.labelInPlural'), 'fa fa-map-marker', UserAddress::class);

            yield MenuItem::section($this->trans('restaurant.labelMenu'));
                yield MenuItem::linkToCrud($this->trans('restaurantCategory.labelInPlural'), 'fa fa-filter', RestaurantCategory::class);
                yield MenuItem::linkToCrud($this->trans('restaurant.labelInPlural'), 'fa fa-shopping-cart', Restaurant::class);
                yield MenuItem::linkToCrud($this->trans('schedule.labelInPlural'), 'fa fa-clock-o', Schedule::class);
                yield MenuItem::linkToCrud($this->trans('menu.labelInPlural'), 'fa fa-cutlery', Menu::class);

                //yield MenuItem::linkToCrud($this->trans('extraType.labelInPlural'), 'fa fa-plus', ExtraType::class);
                //yield MenuItem::linkToCrud($this->trans('extra.labelInPlural'), 'fa fa-plus-square-o', Extra::class);
        }

    }
}
