<commit_before><?php

declare(strict_types=1);

namespace Orchid\Press\Http\Composers;

use Orchid\Platform\Dashboard;
use Orchid\Platform\ItemMenu;
use Orchid\Platform\Menu;
use Orchid\Press\Entities\Single;

class PressMenuComposer
{
    /**
     * @var Dashboard
     */
    private $dashboard;

    public function __construct(Dashboard $dashboard)
    {
        $this->dashboard = $dashboard;
    }

    /**
     * Registering the main menu items.
     */
    public function compose(): void
    {
        $this->registerMenuPost();
    }


    protected function registerMenuPost(): self
    {
        $this->dashboard->getEntities()
            ->where('display', true)
            ->sortBy('sort')
            ->each(function ($page) {
                $route = is_a($page, Single::class) ? 'platform.entities.type.page' : 'platform.entities.type';
                $params = is_a($page, Single::class) ? [$page->slug, $page->slug] : [$page->slug];

                $this->dashboard->menu->add(Menu::MAIN,
                    ItemMenu::label($page->name)
                        ->slug($page->slug)
                        ->icon($page->icon)
                        ->title($page->title)
                        ->route($route, $params)
                        ->permission('platform.entities.type.'.$page->slug)
                        ->sort($page->sort)
                        ->canSee($page->display)
                );
            });

        return $this;
    }
}<commit_msg>fix hierarchical menu active state bug<commit_after><?php

declare(strict_types=1);

namespace Orchid\Press\Http\Composers;

use Orchid\Platform\Dashboard;
use Orchid\Platform\ItemMenu;
use Orchid\Platform\Menu;
use Orchid\Press\Entities\Single;

class PressMenuComposer
{
    /**
     * @var Dashboard
     */
    private $dashboard;

    public function __construct(Dashboard $dashboard)
    {
        $this->dashboard = $dashboard;
    }

    /**
     * Registering the main menu items.
     */
    public function compose(): void
    {
        $this->registerMenuPost();
    }


    protected function registerMenuPost(): self
    {
        $this->dashboard->getEntities()
            ->where('display', true)
            ->sortBy('sort')
            ->each(function ($page) {
                $route = is_a($page, Single::class) ? 'platform.entities.type.page' : 'platform.entities.type';
                $params = is_a($page, Single::class) ? [$page->slug, $page->slug] : [$page->slug];
                $active = [route($route, $params), route($route, $params) . '/*'];

                $this->dashboard->menu->add(Menu::MAIN,
                    ItemMenu::label($page->name)
                        ->slug($page->slug)
                        ->icon($page->icon)
                        ->title($page->title)
                        ->route($route, $params)
                        ->permission('platform.entities.type.'.$page->slug)
                        ->sort($page->sort)
                        ->canSee($page->display)
                        ->active($active)
                );
            });

        return $this;
    }
}
{'fraction_non_alphanumeric': 0.15079872204472844, 'fraction_numerical': 0.0006389776357827476, 'mean_word_length': 1.6898625429553265, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '660202', 'n_tokens_mistral': 889, 'n_tokens_neox': 869, 'n_words': 145}