<?php

namespace App\Support;

final class MacroColorConverter
{
    public static function fromRgba(?array $rgba): ?string
    {
        if ($rgba === null) {
            return null;
        }

        return sprintf(
            '#%02X%02X%02X',
            (int) round(max(0.0, min(1.0, $rgba['r'])) * 255),
            (int) round(max(0.0, min(1.0, $rgba['g'])) * 255),
            (int) round(max(0.0, min(1.0, $rgba['b'])) * 255),
        );
    }
}
