package templates

import "testing"

func TestGroupTunableSettings(t *testing.T) {
	entries := []SettingEntry{
		{Key: "session_duration_seconds", Group: "Session", RequiresRestart: false},
		{Key: "password_min_length", Group: "Password Quality", RequiresRestart: false},
		{Key: "password_require_upper", Group: "Password Quality", RequiresRestart: false},
		{Key: "opds_default_page_size", Group: "OPDS Catalog", RequiresRestart: false},
		{Key: "auth_rate_limit_per_min", Group: "Auth Rate Limiting", RequiresRestart: true},
		{Key: "login_max_attempts", Group: "Login Lockout", RequiresRestart: true},
		{Key: "login_lockout_minutes", Group: "Login Lockout", RequiresRestart: true},
	}

	live, restart := GroupTunableSettings(entries)

	if len(live) != 3 {
		t.Fatalf("expected 3 live groups, got %d", len(live))
	}
	if live[0].Name != "Session" || len(live[0].Entries) != 1 {
		t.Errorf("live[0] = %+v", live[0])
	}
	if live[1].Name != "Password Quality" || len(live[1].Entries) != 2 {
		t.Errorf("live[1] = %+v", live[1])
	}
	if live[2].Name != "OPDS Catalog" || len(live[2].Entries) != 1 {
		t.Errorf("live[2] = %+v", live[2])
	}

	if len(restart) != 2 {
		t.Fatalf("expected 2 restart groups, got %d", len(restart))
	}
	if restart[0].Name != "Auth Rate Limiting" || len(restart[0].Entries) != 1 {
		t.Errorf("restart[0] = %+v", restart[0])
	}
	if restart[1].Name != "Login Lockout" || len(restart[1].Entries) != 2 {
		t.Errorf("restart[1] = %+v", restart[1])
	}
}

func TestGroupTunableSettingsEmpty(t *testing.T) {
	live, restart := GroupTunableSettings(nil)
	if len(live) != 0 || len(restart) != 0 {
		t.Errorf("expected empty groups, got live=%d restart=%d", len(live), len(restart))
	}
}

func TestThemeCheckClass(t *testing.T) {
	if got := themeCheckClass("dracula", "dracula"); got != "" {
		t.Errorf("active theme should be visible, got %q", got)
	}
	if got := themeCheckClass("nord", "dracula"); got != " hidden" {
		t.Errorf("inactive theme should be hidden, got %q", got)
	}
}
