<?php

namespace App\Filament\Resources\BackupSetResource\Pages;

use App\Filament\Resources\BackupSetResource;
use App\Support\Navigation\CrossResourceNavigationMatrix;
use App\Support\Navigation\RelatedNavigationResolver;
use Filament\Actions\Action;
use Filament\Resources\Pages\ViewRecord;

class ViewBackupSet extends ViewRecord
{
    protected static string $resource = BackupSetResource::class;

    protected function getHeaderActions(): array
    {
        return [
            Action::make('primary_related')
                ->label(fn (): string => app(RelatedNavigationResolver::class)
                    ->primaryListAction(CrossResourceNavigationMatrix::SOURCE_BACKUP_SET, $this->getRecord())?->actionLabel ?? 'Open related record')
                ->url(fn (): ?string => app(RelatedNavigationResolver::class)
                    ->primaryListAction(CrossResourceNavigationMatrix::SOURCE_BACKUP_SET, $this->getRecord())?->targetUrl)
                ->hidden(fn (): bool => ! (app(RelatedNavigationResolver::class)
                    ->primaryListAction(CrossResourceNavigationMatrix::SOURCE_BACKUP_SET, $this->getRecord())?->isAvailable() ?? false))
                ->color('gray'),
        ];
    }
}
