package views

import (
	"context"
	"strings"
	"testing"
)

func TestPlanningShowDaySeparator(t *testing.T) {
	events := []PlanningEventRow{
		{DateLabel: "May 17, 2026", TimeRange: "09:00", Title: "A"},
		{DateLabel: "May 17, 2026", TimeRange: "11:00", Title: "B"},
		{DateLabel: "May 18, 2026", TimeRange: "10:00", Title: "C"},
	}

	tests := []struct {
		name  string
		index int
		want  bool
	}{
		{"first event always shows separator", 0, true},
		{"same date as previous — no separator", 1, false},
		{"different date from previous — show separator", 2, true},
	}

	for _, tc := range tests {
		t.Run(tc.name, func(t *testing.T) {
			got := PlanningShowDaySeparator(events, tc.index)
			if got != tc.want {
				t.Fatalf("PlanningShowDaySeparator(events, %d) = %v; want %v", tc.index, got, tc.want)
			}
		})
	}
}

func TestPlanningMainContentRendersOverviewSection(t *testing.T) {
	data := PlanningTabData{
		DateRange: "May 17 – May 18, 2026",
		Events: []PlanningEventRow{
			{DateLabel: "May 17, 2026", TimeRange: "09:00", Title: "Alpha"},
			{DateLabel: "May 17, 2026", TimeRange: "11:00", Title: "Beta"},
			{DateLabel: "May 18, 2026", TimeRange: "10:00", Title: "Gamma"},
		},
	}

	_ = context.Background() // ensure import is used
	html := renderViewToString(t, PlanningMainContent(data))

	for _, want := range []string{"overview-section", "overview-section-heading", "data-day-separator"} {
		if !strings.Contains(html, want) {
			t.Fatalf("PlanningMainContent rendered HTML missing %q; html: %.1500s", want, html)
		}
	}
}
