<?php

namespace App\Filament\Pages;

use Filament\Pages\Dashboard as BaseDashboard;
use Illuminate\Support\Facades\Auth;

/**
 * The tenant dashboard, gated on `dashboard.access`.
 *
 * Filament's stock Dashboard page carries no authorization of its own, so
 * registering it directly put "Dashboard" in the sidebar for every authenticated
 * user — including one with no permissions whatsoever — even though
 * `dashboard.access` has always existed in the catalog and every dashboard
 * widget already checked it. The menu entry and the page are now governed by the
 * same permission as the widgets on it.
 *
 * A user who holds nothing at all therefore has no navigation and no landing
 * page. That is the honest outcome rather than an empty dashboard implying access
 * they do not have, and it cannot loop: {@see \App\Services\UserLanding::urlFor()}
 * only redirects when the target differs from the current path.
 */
class Dashboard extends BaseDashboard
{
    public static function canAccess(): bool
    {
        return Auth::user()?->hasPermissionTo('dashboard.access') ?? false;
    }

    public static function shouldRegisterNavigation(): bool
    {
        return static::canAccess();
    }
}
