summaryrefslogtreecommitdiff
path: root/ui/views/play.go
blob: 0c09d2ab1d182c2750be8faa63c7c7f111d490b2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package views

import (
	"github.com/charmbracelet/bubbles/textinput"
	tea "github.com/charmbracelet/bubbletea"
	"github.com/charmbracelet/lipgloss"
)

type PlayModel struct {
	width  int
	height int
}

func NewPlayModel(width, height int) PlayModel {

	return PlayModel{
		width:  width,
		height: height,
	}
}

func (m PlayModel) Init() tea.Cmd {
	ClearScreen()
	return textinput.Blink
}

func (m PlayModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	if exit := handleExit(msg); exit != nil {
		return m, exit
	}

	switch msg := msg.(type) {
	case tea.KeyMsg:
		switch msg.String() {
		case "q":
			return m, SwitchModelCmd(NewAuthModel(m.width, m.height))

		}
	}
	return m, nil
}

func (m PlayModel) View() string {
	width, height := m.width, m.height

	// Create the window with tab content
	ui := lipgloss.JoinVertical(lipgloss.Center,
		windowStyle.Width(getFormWidth(width)).Render("New Play"),
	)

	// Center logo and form in available space
	contentHeight := lipgloss.Height(logo) + lipgloss.Height(ui) + 2
	paddingTop := (height - contentHeight) / 2
	if paddingTop < 0 {
		paddingTop = 0
	}

	// Combine logo and tabs with vertical centering
	output := lipgloss.NewStyle().
		MarginTop(paddingTop).
		Render(
			lipgloss.JoinVertical(lipgloss.Center,
				getLogo(m.width),
				lipgloss.PlaceHorizontal(width, lipgloss.Center, ui),
			),
		)

	return output
}