// Shared colour-string helpers. Tamagui exposes resolved tokens as plain
// hex strings (`theme.accent.val === '#3A52FF'`), so any "stripe at depth N
// uses accent at alpha A" pattern needs a way to turn a hex into rgba
// without going through CSS string concat at every call site.
//
// `tamagui.config.ts` has a near-identical `alphaHex` helper for the
// per-account accent sub-themes; that one is intentionally private to the
// config module (it ships baked alpha variants like `accentMuted`).
// This helper is the same shape, exposed for runtime use.

// Accepts `#RRGGBB` (the only shape Tamagui's accent tokens produce) and,
// defensively, an already-rgba string — returning the input unchanged in
// the latter case keeps the contract total for future callers that pass
// already-alpha-fied colours.
export function withAlpha(color: string, alpha: number): string {
  const m = color.match(/^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i)
  if (!m) return color
  const r = parseInt(m[1], 16)
  const g = parseInt(m[2], 16)
  const b = parseInt(m[3], 16)
  return `rgba(${r},${g},${b},${alpha})`
}
