<?php

namespace MintyPHP\Module\Bookmarks\Providers;

use MintyPHP\App\AppContainer;
use MintyPHP\App\Module\Contracts\LayoutContextProvider;
use MintyPHP\Module\Bookmarks\Support\BookmarkUrlNormalizer;

final class BookmarksLayoutProvider implements LayoutContextProvider
{
    public function provide(array $session, AppContainer $container): array
    {
        $grouped = is_array($session['module.bookmarks.grouped'] ?? null)
            ? $session['module.bookmarks.grouped']
            : ['groups' => [], 'ungrouped' => []];

        $currentPath = BookmarkUrlNormalizer::canonicalizeRequestUri(
            (string) ($_SERVER['REQUEST_URI'] ?? ''),
            localeBase()
        );

        return [
            'bookmarks.nav' => [
                'grouped' => $grouped,
                'current_path' => $currentPath,
            ],
        ];
    }
}
