<?php

declare(strict_types=1);

namespace App\Filament\Pages\Concerns;

use BackedEnum;
use Illuminate\Contracts\Support\Htmlable;
use UnitEnum;

/**
 * 独立 Filament 页面面包屑：导航分组 → 当前页标题（两级、无链接）。
 *
 * Filament 5.6 约定：整型键为纯文本，字符串键为可点击 URL。
 */
trait InteractsWithDberpNavigationGroupBreadcrumbs
{
    /**
     * @return array<int|string, string|Htmlable>
     */
    public function getBreadcrumbs(): array
    {
        $group = static::getNavigationGroup();
        $title = $this->getTitle();

        if ($group === null || $group === '') {
            return [$title];
        }

        $groupLabel = $group instanceof BackedEnum
            ? (string) $group->value
            : ($group instanceof UnitEnum
                ? $group->name
                : (string) $group);

        return [
            $groupLabel,
            $title,
        ];
    }
}
