<?php

declare(strict_types=1);

namespace App\Shared\Support;

final class Html
{
    public static function escape(mixed $value): string
    {
        if ($value === null) {
            return '';
        }

        if (is_bool($value)) {
            $value = $value ? '1' : '0';
        } elseif (is_int($value) || is_float($value)) {
            $value = (string) $value;
        } elseif (!is_string($value)) {
            $value = json_encode($value, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
            if ($value === false) {
                $value = '';
            }
        }

        return htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
    }
}
