// Copyright © 2023 Mastodon gGmbH. All rights reserved.

import UIKit

extension UIColor {
    public var hexValue: String {
        let components = cgColor.components

        let red: CGFloat = components?[0] ?? 0.0
        let green: CGFloat = components?[1] ?? 0.0
        let blue: CGFloat = components?[2] ?? 0.0

        return String(
            format: "#%02lX%02lX%02lX",
            lroundf(Float(red * 255)),
            lroundf(Float(green * 255)),
            lroundf(Float(blue * 255))
        )
    }
}
