1package footer
 2
 3import (
 4	"strings"
 5
 6	"github.com/charmbracelet/bubbles/help"
 7	"github.com/charmbracelet/bubbles/key"
 8	tea "github.com/charmbracelet/bubbletea"
 9	"github.com/charmbracelet/lipgloss"
10	"github.com/charmbracelet/soft-serve/ui/common"
11)
12
13// Footer is a Bubble Tea model that displays help and other info.
14type Footer struct {
15	common common.Common
16	help   help.Model
17	keymap help.KeyMap
18}
19
20// New creates a new Footer.
21func New(c common.Common, keymap help.KeyMap) *Footer {
22	h := help.New()
23	h.Styles.ShortKey = c.Styles.HelpKey
24	h.Styles.ShortDesc = c.Styles.HelpValue
25	h.Styles.FullKey = c.Styles.HelpKey
26	h.Styles.FullDesc = c.Styles.HelpValue
27	f := &Footer{
28		common: c,
29		help:   h,
30		keymap: keymap,
31	}
32	f.SetSize(c.Width, c.Height)
33	return f
34}
35
36// SetSize implements common.Component.
37func (f *Footer) SetSize(width, height int) {
38	f.common.SetSize(width, height)
39	f.help.Width = width
40}
41
42// Init implements tea.Model.
43func (f *Footer) Init() tea.Cmd {
44	return nil
45}
46
47// Update implements tea.Model.
48func (f *Footer) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
49	return f, nil
50}
51
52// View implements tea.Model.
53func (f *Footer) View() string {
54	if f.keymap == nil {
55		return ""
56	}
57	s := f.common.Styles.Footer.Copy().Width(f.common.Width)
58	helpView := f.help.View(f.keymap)
59	return s.Render(strings.TrimSpace(helpView))
60}
61
62// ShortHelp returns the short help key bindings.
63func (f *Footer) ShortHelp() []key.Binding {
64	return f.keymap.ShortHelp()
65}
66
67// FullHelp returns the full help key bindings.
68func (f *Footer) FullHelp() [][]key.Binding {
69	return f.keymap.FullHelp()
70}
71
72// ShowAll returns whether the full help is shown.
73func (f *Footer) ShowAll() bool {
74	return f.help.ShowAll
75}
76
77// SetShowAll sets whether the full help is shown.
78func (f *Footer) SetShowAll(show bool) {
79	f.help.ShowAll = show
80}
81
82// Height returns the height of the footer.
83func (f *Footer) Height() int {
84	return lipgloss.Height(f.View())
85}