<?php

declare(strict_types=1);

namespace App\Filament\Support;

use Closure;
use Filament\Actions\Action;
use Illuminate\Database\Eloquent\Model;

final class DberpPrintFilamentAction
{
    public static function configure(Action $action): Action
    {
        return $action
            ->color('gray')
            ->outlined()
            ->openUrlInNewTab();
    }

    /**
     * @param  (Closure(Model): bool)|null  $visibleResolver
     */
    public static function forDocument(string $documentKey, ?Closure $visibleResolver = null): Action
    {
        $action = Action::make('print')
            ->label(__('dberp.print.actions.print'))
            ->url(fn (Model $record): string => route('dberp.documents.print', [
                'documentKey' => $documentKey,
                'record' => $record->getKey(),
            ]));

        if ($visibleResolver !== null) {
            $action->visible($visibleResolver);
        }

        return self::configure($action);
    }
}
