<?php

namespace Plainwork\Ui;

use Plainwork\Http\Router;

class PageMap
{
    public $router = Router::class;
    private array $decorators = [];
    private array $breadcrumbTitle = [];

    public function decorate(string $route, string $pageDecoratorClass): self
    {
        $this->decorators[$route] ??= [];
        $this->decorators[$route][] = $pageDecoratorClass;

        return $this;
    }

    public function getDecorators(string $path): array
    {
        list($route,) = $this->router->parsePath($path);

        return $this->decorators[$route] ?? [];
    }

    public function setBreadcrumbTitle(string $route, $title): self
    {
        $this->breadcrumbTitle[$route] = $title;

        return $this;
    }

    public function getBreadcrumbTitle(string $path)
    {
        list($route,) = $this->router->parsePath($path);

        return $this->breadcrumbTitle[$route] ?? null;
    }
}
