<?php

declare(strict_types=1);

namespace App\Filament\Support;

use Closure;
use Illuminate\Database\Eloquent\Builder;

final class NavigationBadge
{
    public static function whenPositive(int $count): ?string
    {
        return $count > 0 ? (string) $count : null;
    }

    public static function colorWhenPositive(int $count, string $color = 'warning'): ?string
    {
        return $count > 0 ? $color : null;
    }

    /**
     * @param  Closure(): Builder  $queryFactory
     */
    public static function fromQuery(Closure $queryFactory): ?string
    {
        return self::whenPositive($queryFactory()->count());
    }

    /**
     * @param  Closure(): Builder  $queryFactory
     */
    public static function colorFromQuery(Closure $queryFactory, string $color = 'warning'): ?string
    {
        return self::colorWhenPositive($queryFactory()->count(), $color);
    }
}
