<?php

declare(strict_types=1);

namespace App\Filament\Support;

use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Support\HtmlString;

final class DberpFilamentSubheading
{
    public static function prependBusinessHint(string|Htmlable|null $existing, ?string $translationKey): string|Htmlable|null
    {
        if ($translationKey === null || $translationKey === '') {
            return $existing;
        }

        $text = e((string) __($translationKey));
        $block = '<p class="text-sm text-gray-600 dark:text-gray-400">'.$text.'</p>';

        if ($existing === null || $existing === '') {
            return new HtmlString($block);
        }

        if ($existing instanceof Htmlable) {
            return new HtmlString($block.$existing->toHtml());
        }

        return new HtmlString($block.e($existing));
    }
}
