<?php

namespace Modules\Stock\Controller;

use Exception;
use Modules\Stock\Helper\RulesHelper;
use Skeleton\Controller\Controller;

class GestionStockController extends Controller
{
    /**
     * @throws Exception
     */
    public function gestionAction() : string
    {
        $trad = $this->getTranslationService();

        $generalItems = [];
        $parametrageItems = [];

        if (RulesHelper::hasParametrageAccessRights($this->pdo)) {
            $parametrageItems[] = ['title' => $trad->t('Paramétrage stock'), 'path' => $this->router->generateUri('Stock.Numerotation.numerotationForm')];
        }
        if (RulesHelper::hasDemandeServiceAccessRights($this->pdo)) {
            $generalItems[] = ['title' => $trad->t('Demandes de service'), 'path' => $this->router->generateUri('Stock.DemandeService.gestion')];
        }
        if (RulesHelper::hasImportUniverselAccessRights($this->pdo)) {
            $generalItems[] = ['title' => $trad->t('Import universel DS'), 'path' => $this->router->generateUri('Stock.ImportUniversel.gestion')];
        }
        if (RulesHelper::hasBonEntreeAccessRights($this->pdo)) {
            $generalItems[] = ['title' => $trad->t('Bons d\'entrée'), 'path' => $this->router->generateUri('Stock.BonEntree.gestion')];
        }
        if (RulesHelper::hasBonSortieAccessRights($this->pdo)) {
            $generalItems[] = ['title' => $trad->t('Bons de sortie'), 'path' => $this->router->generateUri('Stock.BonSortie.gestion')];
        }
        if (RulesHelper::hasBonTransfertAccessRights($this->pdo)) {
            $generalItems[] = ['title' => $trad->t('Bons de transfert'), 'path' => $this->router->generateUri('Stock.BonTransfert.gestion')];
        }
        if (RulesHelper::hasMouvementAccessRights($this->pdo)) {
            $generalItems[] = ['title' => $trad->t('Visualisation des mouvements'), 'path' => $this->router->generateUri('Stock.Mouvement.gestion')];
        }

        $generalItems[] = ['title' => $trad->t('Stocks locaux'), 'path' => $this->router->generateUri('Stock.StockLocal.gestion')];
        $generalItems[] = ['title' => $trad->t('Articles'), 'path' => $this->router->generateUri('Stock.StockArticle.gestion')];

        if (RulesHelper::hasInvAccessRights($this->pdo)) {
            $generalItems[] = ['title' => $trad->t('Inventaires'), 'path' => $this->router->generateUri('Stock.Inventaire.gestion')];
        }
        if (RulesHelper::hasIndisponibiliteAccessRights($this->pdo)) {
            $generalItems[] = ['title' => $trad->t('Indisponibilités'), 'path' => $this->router->generateUri('Stock.Indisponibilite.gestion')];
        }

        $menus = [
            ['title' => null, 'items' => $generalItems],
            [
                'title' => $trad->t('Tables'),
                'items' => [
                    ['title' => $trad->t('Rubriques'), 'path' => $this->router->generateUri('Stock.Rubrique.gestion')],
                    ['title' => $trad->t('Sites'), 'path' => $this->router->generateUri('Stock.SiteStock.gestion')],
                    ['title' => $trad->t('Tiers'), 'path' => $this->router->generateUri('Stock.Tiers.gestion')],
                    ['title' => $trad->t('Magasiniers'), 'path' => $this->router->generateUri('Stock.Magasinier.magasiniersGestion')],
                ]
            ],
        ];

        if (!empty($parametrageItems)) {
            $menus[] = ['title' => $trad->t('Paramétrage'), 'items' => $parametrageItems];
        }

        return $this->renderer->render('@Stock/GestionStock/gestion', [
            'menus' => $menus,
            'menuActive' => 'Stock',
        ]);
    }
}
