package backbeat

import "errors"

// PhaseFor returns the phase name for a given beat index (1-indexed).
func PhaseFor(phases map[string]int, beatIndex int) (string, error) {
	acc := 0
	for name, n := range phases {
		acc += n
		if beatIndex <= acc {
			return name, nil
		}
	}
	return "", errors.New("beat index out of range")
}
