<?php

namespace App\Helpers;

class TextFormatter
{
    public static function convertWhatsappToHtml(string $message): string
    {
        $message = preg_replace('/\*(.*?)\*/', '<strong>$1</strong>', $message);
        $message = preg_replace('/_(.*?)_/', '<em>$1</em>', $message);
        $message = preg_replace('/~(.*?)~/', '<del>$1</del>', $message);
        $message = preg_replace('/```(.*?)```/s', '<pre>$1</pre>', $message);
        $message = preg_replace('/`(.*?)`/', '<code>$1</code>', $message);
        $message = nl2br($message);

        return $message;
    }
}
