<?php

namespace App\Filament\Resources\Workspaces\Pages;

use App\Filament\Resources\Workspaces\WorkspaceResource;
use App\Models\Workspace;
use App\Support\Auth\Capabilities;
use App\Support\Rbac\WorkspaceUiEnforcement;
use Filament\Actions;
use Filament\Resources\Pages\ViewRecord;

class ViewWorkspace extends ViewRecord
{
    protected static string $resource = WorkspaceResource::class;

    protected function getHeaderActions(): array
    {
        return [
            WorkspaceUiEnforcement::forTableAction(
                Actions\EditAction::make()
                    ->visible(fn (): bool => WorkspaceResource::canEdit($this->record)),
                fn (): ?Workspace => $this->record,
            )
                ->preserveVisibility()
                ->requireCapability(Capabilities::WORKSPACE_MANAGE)
                ->apply(),
        ];
    }
}
