package models

import (
	"fmt"
	"strings"
	"<%= moduleName %>/internal/styles"

	tea "github.com/charmbracelet/bubbletea"
)

type Model struct {
	choices []string
	cursor  int
}

func NewModel() Model {
	return Model{
		choices: []string{
			"Start",
			"Settings", 
			"Exit",
		},
	}
}

func (m Model) Init() tea.Cmd {
	return nil
}

func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
	switch msg := msg.(type) {
	case tea.KeyMsg:
		switch msg.String() {
		case "ctrl+c", "q":
			return m, tea.Quit
		case "up", "k":
			if m.cursor > 0 {
				m.cursor--
			}
		case "down", "j":
			if m.cursor < len(m.choices)-1 {
				m.cursor++
			}
		case "enter":
			if m.choices[m.cursor] == "Exit" {
				return m, tea.Quit
			}
			// Handle other selections here
		}
	}
	return m, nil
}

func (m Model) View() string {
	var b strings.Builder
	
	title := fmt.Sprintf("=== %s ===", "<%= projectName %>")
	b.WriteString(styles.ApplyTitleStyle(title))
	b.WriteString("\n\n")
	
	for i, choice := range m.choices {
		cursor := "  "
		if m.cursor == i {
			cursor = "> "
		}
		
		item := fmt.Sprintf("%s%s", cursor, choice)
		b.WriteString(styles.ApplyItemStyle(item, m.cursor == i))
		b.WriteString("\n")
	}
	
	b.WriteString("\nUse ↑/↓ or j/k to navigate, Enter to select, q to quit\n")
	
	return b.String()
}
