package day import ( "fmt" "strings" "time" "github.com/charmbracelet/bubbles/table" "github.com/charmbracelet/lipgloss" "ticktock/internal/store" ) var ( pink = lipgloss.Color("#D188C4") purple = lipgloss.Color("#5A2FE0") muted = lipgloss.Color("#878580") headerStyle = lipgloss.NewStyle().Foreground(pink).Bold(true) footerStyle = lipgloss.NewStyle().Foreground(muted) ) func tableStyles() table.Styles { s := table.DefaultStyles() s.Header = s.Header.Bold(true).BorderBottom(true) s.Selected = s.Selected.Foreground(lipgloss.Color("#FFFFFF")).Background(purple).Bold(false) return s } func headerLine(date string) string { t, err := time.ParseInLocation("2006-01-02", date, time.Local) label := date if err == nil { label = t.Format("Monday, 02 Jan 2006") } return headerStyle.Render("<< " + label + " >>") } func footerLine(entries []store.Entry) string { pt, grand := Totals(entries) parts := make([]string, 0, len(pt)) for _, p := range pt { parts = append(parts, fmt.Sprintf("%s %s", p.Project, fmtDur(p.Total))) } summary := "─ by project ─ " + strings.Join(parts, " ") + fmt.Sprintf(" TOTAL %s", fmtDur(grand)) return footerStyle.Render(summary) } func (m Model) View() string { if m.quit { return "" } if m.editing && m.form != nil { hint := footerStyle.Render("ctrl+s save · esc cancel") return headerLine(m.date) + "\n\n" + m.form.View() + "\n" + hint } body := m.tbl.View() if len(m.entries) == 0 { body = footerStyle.Render(" no entries") } help := footerStyle.Render("enter edit · ←/→ date · q quit") if m.status != "" { help = footerStyle.Render(m.status) } if m.err != nil { help = footerStyle.Render("error: " + m.err.Error()) } return strings.Join([]string{ headerLine(m.date), "", body, "", footerLine(m.entries), help, }, "\n") }