'use client'; import { ColorInfo as ColorInfoType } from '@/lib/color/api/types'; import { Copy } from 'lucide-react'; import { toast } from 'sonner'; import { cn } from '@/lib/utils/cn'; interface ColorInfoProps { info: ColorInfoType; className?: string; } export function ColorInfo({ info, className }: ColorInfoProps) { const copy = (value: string, label: string) => { navigator.clipboard.writeText(value); toast.success(`Copied ${label}`); }; const formatRgb = (rgb: { r: number; g: number; b: number; a?: number }) => rgb.a !== undefined && rgb.a < 1 ? `rgba(${rgb.r}, ${rgb.g}, ${rgb.b}, ${rgb.a})` : `rgb(${rgb.r}, ${rgb.g}, ${rgb.b})`; const formatHsl = (hsl: { h: number; s: number; l: number; a?: number }) => hsl.a !== undefined && hsl.a < 1 ? `hsla(${Math.round(hsl.h)}°, ${Math.round(hsl.s * 100)}%, ${Math.round(hsl.l * 100)}%, ${hsl.a})` : `hsl(${Math.round(hsl.h)}°, ${Math.round(hsl.s * 100)}%, ${Math.round(hsl.l * 100)}%)`; const formats = [ { label: 'HEX', value: info.hex }, { label: 'RGB', value: formatRgb(info.rgb) }, { label: 'HSL', value: formatHsl(info.hsl) }, { label: 'Lab', value: `lab(${info.lab.l.toFixed(1)} ${info.lab.a.toFixed(1)} ${info.lab.b.toFixed(1)})` }, { label: 'OkLab', value: `oklab(${(info.oklab.l * 100).toFixed(1)}% ${info.oklab.a.toFixed(3)} ${info.oklab.b.toFixed(3)})` }, ]; return (