<?php

declare(strict_types=1);

namespace PpPhp\Core\Theme;

/**
 * NavbarRegistry
 *
 * Master catalogue of navbar / shell **layout types**. A navbar type is pure
 * data describing how the application chrome is arranged (topbar, sidebar,
 * horizontal menu, boxed …). The Style SPA lets the user pick one; the preview
 * and the built app render accordingly. Each type only carries structure +
 * sensible shell defaults — colours/tokens stay in the theme, so the two are
 * independent and composable.
 */
final class NavbarRegistry
{
    /**
     * @return array<int, array<string, mixed>>
     */
    public static function all(): array
    {
        return [
            [
                'id' => 'classic',
                'label' => 'Classic',
                'description' => 'Fixed topbar with a left sidebar menu — the familiar admin layout.',
                'layout' => 'both',            // topbar + sidebar
                'menuPlacement' => 'sidebar',
                'defaults' => [
                    'topbar' => ['enabled' => true, 'fixed' => true],
                    'sidebar' => ['enabled' => true, 'position' => 'left'],
                ],
            ],
            [
                'id' => 'horizontal',
                'label' => 'Horizontal',
                'description' => 'Single top bar with a horizontal menu, no sidebar — clean and spacious.',
                'layout' => 'topbar',
                'menuPlacement' => 'topbar',
                'defaults' => [
                    'topbar' => ['enabled' => true, 'fixed' => true],
                    'sidebar' => ['enabled' => false],
                ],
            ],
            [
                'id' => 'sidebar',
                'label' => 'Sidebar',
                'description' => 'Full-height vertical sidebar with a slim content header.',
                'layout' => 'sidebar',
                'menuPlacement' => 'sidebar',
                'defaults' => [
                    'topbar' => ['enabled' => true, 'fixed' => true, 'height' => '52px'],
                    'sidebar' => ['enabled' => true, 'position' => 'left'],
                ],
            ],
            [
                'id' => 'rail',
                'label' => 'Icon rail',
                'description' => 'Narrow icon-only sidebar that expands on hover — maximises content space.',
                'layout' => 'both',
                'menuPlacement' => 'sidebar',
                'defaults' => [
                    'topbar' => ['enabled' => true, 'fixed' => true],
                    'sidebar' => ['enabled' => true, 'position' => 'left', 'compact' => true, 'width' => '72px'],
                ],
            ],
            [
                'id' => 'boxed',
                'label' => 'Boxed',
                'description' => 'Centered, contained layout with a rounded topbar — great for focused apps.',
                'layout' => 'topbar',
                'menuPlacement' => 'topbar',
                'defaults' => [
                    'topbar' => ['enabled' => true, 'fixed' => false],
                    'sidebar' => ['enabled' => false],
                ],
            ],
            [
                'id' => 'hero',
                'label' => 'Hero',
                'description' => 'Tall gradient topbar with prominent branding and a horizontal menu.',
                'layout' => 'topbar',
                'menuPlacement' => 'topbar',
                'defaults' => [
                    'topbar' => ['enabled' => true, 'fixed' => false, 'gradient' => true, 'height' => '84px'],
                    'sidebar' => ['enabled' => false],
                ],
            ],
        ];
    }

    /** @return array<int, string> */
    public static function ids(): array
    {
        return array_map(static fn (array $n): string => (string) $n['id'], self::all());
    }

    public static function get(string $id): ?array
    {
        foreach (self::all() as $navbar) {
            if (($navbar['id'] ?? '') === $id) {
                return $navbar;
            }
        }
        return null;
    }
}
