<?php

namespace MintyPHP\Module\HelpCenter\Providers;

use MintyPHP\App\AppContainer;
use MintyPHP\App\Module\Contracts\LayoutContextProvider;
use MintyPHP\Service\Access\AuthorizationService;

final class HelpCenterLayoutProvider implements LayoutContextProvider
{
    public function provide(array $session, AppContainer $container): array
    {
        $userId = (int) ($session['user']['id'] ?? 0);
        if ($userId <= 0) {
            return ['help-center.nav' => ['can_view_api_docs' => false]];
        }

        try {
            $authService = $container->get(AuthorizationService::class);
            $canViewApiDocs = $authService->authorize('api_docs.view', [
                'actor_user_id' => $userId,
            ])->isAllowed();
        } catch (\Throwable) {
            $canViewApiDocs = false;
        }

        return ['help-center.nav' => ['can_view_api_docs' => $canViewApiDocs]];
    }
}
