<?php

namespace App\Support;

class ColorHelper
{
    public static function hslToHex($h, $s, $l): string
    {
        $s /= 100;
        $l /= 100;
        $a = $s * min($l, 1 - $l);

        $f = function($n) use ($h, $l, $a) {
            $k = ($n + $h / 30) % 12;
            $color = $l - $a * max(min($k - 3, 9 - $k, 1), -1);
            $hex = dechex((int)round(255 * $color));
            return str_pad($hex, 2, '0', STR_PAD_LEFT);
        };

        return '#' . $f(0) . $f(8) . $f(4);
    }
}
