<?php

namespace App\Filament\Resources\TenantResource\Pages;

use App\Filament\Resources\TenantResource;
use App\Models\Tenant;
use App\Support\Tenants\TenantActionSurface;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditTenant extends EditRecord
{
    protected static string $resource = TenantResource::class;

    protected function getHeaderActions(): array
    {
        return array_values(array_filter([
            Actions\ActionGroup::make([
                TenantResource::makeRestoreTenantAction(
                    TenantActionSurface::TenantEditHeader,
                    'You do not have permission to restore tenants.',
                ),
                TenantResource::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 Tenant
                    && in_array(
                        TenantResource::lifecycleActionDescriptor($this->getRecord(), TenantActionSurface::TenantEditHeader)?->key,
                        ['archive', 'restore'],
                        true,
                    )),
        ]));
    }
}
