<?php

namespace App\Support;

class UrlExtractor
{
    public static function firstUrl(string $text): ?string
    {
        if (preg_match('/\bhttps?:\/\/[^\s<>"\']+/i', $text, $m)) {
            return rtrim($m[0], '.,)');
        }

        if (preg_match('/\b(?:[a-z0-9-]+\.)+[a-z]{2,}\b/i', $text, $m)) {
            return 'https://'.$m[0];
        }

        return null;
    }
}
