// Pick a legible foreground (#0A0A0A or #F4F3EE) for a given background colour
// using YIQ luminance. Used wherever we paint UI with a customer's brand
// colour (sidebar workspace mark, Branding live preview) so the text/marks
// stay readable for any accent — bright or dark. Auto-imported by Nuxt.
export function readableOn(hex: string): string {
  let h = hex.replace('#', '').trim()
  if (h.length === 3) h = h.split('').map((c) => c + c).join('')
  if (h.length !== 6) return '#0A0A0A'
  const r = parseInt(h.slice(0, 2), 16)
  const g = parseInt(h.slice(2, 4), 16)
  const b = parseInt(h.slice(4, 6), 16)
  const yiq = (r * 299 + g * 587 + b * 114) / 1000
  return yiq >= 140 ? '#0A0A0A' : '#F4F3EE'
}
