package fbdraw_test

import (
	"testing"

	"git.eeqj.de/sneak/hdmistat/internal/fbdraw"
)

// SimpleGenerator is a test generator
type SimpleGenerator struct {
	width, height int
}

func (s *SimpleGenerator) Init(width, height int) error {
	s.width = width
	s.height = height
	return nil
}

func (s *SimpleGenerator) GenerateFrame(grid *fbdraw.CharGrid) error {
	writer := fbdraw.NewGridWriter(grid)
	writer.MoveAbs(s.width/2-5, s.height/2)
	writer.SetColor(fbdraw.White)
	writer.Write("Test Content")
	return nil
}

func (s *SimpleGenerator) FramesPerSecond() float64 {
	return 1.0
}

func TestHeaderWrapper(t *testing.T) {
	// Create a simple generator
	simple := &SimpleGenerator{}

	// Wrap it with header
	wrapped := fbdraw.NewHeaderWrapper(simple)

	// Initialize with some dimensions
	if err := wrapped.Init(80, 25); err != nil {
		t.Fatalf("Failed to init: %v", err)
	}

	// Generate a frame
	grid := fbdraw.NewCharGrid(80, 25)
	if err := wrapped.GenerateFrame(grid); err != nil {
		t.Fatalf("Failed to generate frame: %v", err)
	}

	// Check that header exists (line 3 should have horizontal rule)
	hasRule := false
	for x := 0; x < 80; x++ {
		if grid.Cells[2][x].Rune == '─' {
			hasRule = true
			break
		}
	}

	if !hasRule {
		t.Error("Expected horizontal rule on line 3")
	}

	// Log the output for visual inspection
	t.Logf("Generated frame with header:\n%s", grid.String())
}
