package day import "strings" // ActivityType is the CLI-side view of a Dots activity type. type ActivityType struct { ID string `json:"id"` Name string `json:"name"` Color string `json:"color"` } // MatchActivity finds candidate types for a query: exact (case-insensitive) // wins outright; if multiple names match exactly, the first wins; otherwise all // prefix matches; otherwise all substring matches. Empty or whitespace-only queries // return no results. func MatchActivity(query string, types []ActivityType) []ActivityType { q := strings.TrimSpace(query) if q == "" { return []ActivityType{} } q = strings.ToLower(q) var prefix, substr []ActivityType for _, t := range types { n := strings.ToLower(t.Name) if n == q { return []ActivityType{t} } if strings.HasPrefix(n, q) { prefix = append(prefix, t) } else if strings.Contains(n, q) { substr = append(substr, t) } } if len(prefix) > 0 { return prefix } if substr == nil { return []ActivityType{} } return substr }