package main

import (
	"testing"

	udp "hamlog/internal/integrations/udp"
)

// The text colour is derived from the background, never stored: an operator who
// picks a dark blue must not end up with black text on it in somebody else's
// window and conclude the feature is broken.
func TestHighlightForegroundFollowsTheBackground(t *testing.T) {
	var a App
	for _, tc := range []struct {
		bg   string
		want udp.RGB
	}{
		{"#111827", hlWhite}, // near-black
		{"#16823C", hlWhite}, // the new-DXCC green
		{"#F472B6", hlBlack}, // the watchlist pink
		{"#FFFFFF", hlBlack},
		{"#E27A18", hlBlack}, // orange
	} {
		bg, fg := a.colourFor("", tc.bg)
		if got, ok := parseHexRGB(tc.bg); !ok || got != bg {
			t.Errorf("%s: background came back as %v", tc.bg, bg)
		}
		if fg != tc.want {
			t.Errorf("%s: foreground %v, want %v", tc.bg, fg, tc.want)
		}
	}
}

// A colour that cannot be read is refused rather than half-read: silently
// becoming black is worse than keeping the default.
func TestHighlightColourParsing(t *testing.T) {
	for _, s := range []string{"#F472B6", "f472b6", " #F472B6 "} {
		if c, ok := parseHexRGB(s); !ok || c != (udp.RGB{R: 244, G: 114, B: 182}) {
			t.Errorf("%q → %v ok=%v", s, c, ok)
		}
	}
	for _, s := range []string{"", "#FFF", "pink", "#GGGGGG", "#F472B6F"} {
		if _, ok := parseHexRGB(s); ok {
			t.Errorf("%q was accepted", s)
		}
	}
}
