<?php

declare(strict_types=1);

/*
 * This file is part of the Ferienpass package.
 *
 * (c) Richard Henkenjohann <richard@ferienpass.online>
 *
 * For more information visit the project website <https://ferienpass.online>
 * or the documentation under <https://docs.ferienpass.online>.
 */

namespace Ferienpass\CmsBundle\Controller\Fragment;

use Ferienpass\CoreBundle\Controller\AbstractPrivateFragmentController;
use Knp\Menu\Provider\MenuProviderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\Translation\TranslatorInterface;

class UserAccountNavigationController extends AbstractPrivateFragmentController
{
    public function __construct(private readonly MenuProviderInterface $menuProvider, private readonly TranslatorInterface $translator)
    {
    }

    public function __invoke(Request $request): Response
    {
        $menu = $this->menuProvider->get('user_account_navigation');
        $items = [];

        $icons = [
            'personalData' => 'lucide:user',
            'participants' => 'lucide:users',
            'changePassword' => 'lucide:lock-keyhole',
            'passkeys' => 'lucide:fingerprint',
            'closeAccount' => 'lucide:trash-2',
            'consents' => 'lucide:clipboard-check',
            'dataUsage' => 'lucide:share-2',
            'payments' => 'lucide:credit-card',
        ];

        foreach ($menu->getChildren() as $item) {
            $items[] = [
                'name' => $this->translator->trans('userAccount.navigation.'.$item->getName(), [], 'cms'),
                'url' => $item->getUri(),
                'active' => (bool) $item->isCurrent(),
                'icon' => $icons[$item->getName()] ?? 'lucide:circle',
            ];
        }

        return $this->render('@Contao/fragment/user_account/_navigation.html.twig', [
            'items' => $items,
        ]);
    }
}
