package web
import (
"context"
"net/url"
"sourcecraft.dev/bigbes/sr-ht-dolt/beads"
"sourcecraft.dev/bigbes/sr-ht-dolt/browse"
"sourcecraft.dev/bigbes/sr-ht-dolt/core"
)
// milestonesView groups a beads issue DB by its "milestone:<name>" labels and
// shows per-milestone progress with the issues under each. It shares the beads
// fingerprint, so it appears as a companion tab wherever the Beads view does.
// The grouping itself lives in the beads package; this type is the View adapter.
type milestonesView struct{}
func init() { RegisterView(&milestonesView{}) }
func (*milestonesView) Name() string { return "milestones" }
func (*milestonesView) Label() string { return "Milestones" }
func (*milestonesView) Template() string { return "milestones.html" }
// Applies mirrors the beads fingerprint so Milestones and Beads pair up. A
// beads DB that happens to use no milestone labels still gets the tab; it just
// renders an empty state.
func (*milestonesView) Applies(tables []browse.TableInfo) bool { return beads.Applies(tables) }
// Build groups the issues by milestone label; the result is a
// *beads.MilestoneView, handed to milestones.html as its .Data. The view takes
// no query parameters — the board is where filtering happens.
func (*milestonesView) Build(ctx context.Context, sess BrowseSession, _ *core.Repo, ref string, _ url.Values) (any, error) {
data, err := beads.BuildMilestones(ctx, sess, ref)
if err != nil {
return nil, err
}
return data, nil
}