<?php

declare(strict_types=1);


namespace App\Blog\Support;

/**
 * 从已启用插件的 manifest 中收集 Filament 页面/资源。
 */
class PluginPages
{
    public static function pages(): array
    {
        return self::collect('filament_pages');
    }

    public static function resources(): array
    {
        return self::collect('filament_resources');
    }

    private static function collect(string $key): array
    {
        $manager = app(PluginManager::class);
        $classes = [];

        foreach ($manager->all() as $pluginKey => $plugin) {
            if (! $plugin['enabled']) {
                continue;
            }

            $manifest = $manager->manifest($pluginKey);

            foreach ($manifest[$key] ?? [] as $class) {
                if (class_exists($class)) {
                    $classes[] = $class;
                }
            }
        }

        return $classes;
    }
}
