<?php

namespace App\Filament\Resources\ManagedEnvironmentResource\Pages;

use App\Filament\Resources\ManagedEnvironmentResource;
use App\Models\ManagedEnvironment;
use App\Support\Tenants\TenantActionSurface;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditManagedEnvironment extends EditRecord
{
    protected static string $resource = ManagedEnvironmentResource::class;

    protected function getHeaderActions(): array
    {
        return array_values(array_filter([
            Actions\ActionGroup::make([
                ManagedEnvironmentResource::makeRestoreTenantAction(
                    TenantActionSurface::TenantEditHeader,
                    'You do not have permission to restore tenants.',
                ),
                ManagedEnvironmentResource::makeArchiveTenantAction(
                    TenantActionSurface::TenantEditHeader,
                    'You do not have permission to archive tenants.',
                ),
            ])
                ->label('Lifecycle')
                ->icon('heroicon-o-archive-box')
                ->color('gray')
                ->visible(fn (): bool => $this->getRecord() instanceof ManagedEnvironment
                    && in_array(
                        ManagedEnvironmentResource::lifecycleActionDescriptor($this->getRecord(), TenantActionSurface::TenantEditHeader)?->key,
                        ['archive', 'restore'],
                        true,
                    )),
        ]));
    }
}
