package styles

import "github.com/charmbracelet/lipgloss"

var (
	Primary   = lipgloss.Color("#7aa2f7")
	Secondary = lipgloss.Color("#bb9af7")
	Success   = lipgloss.Color("#9ece6a")
	Warning   = lipgloss.Color("#e0af68")
	Error     = lipgloss.Color("#f7768e")
	Muted     = lipgloss.Color("#565f89")
	Text      = lipgloss.Color("#c0caf5")
	Subtle    = lipgloss.Color("#414868")
	Border    = lipgloss.Color("#7aa2f7")
)

var (
	AppStyle = lipgloss.NewStyle().
			Padding(1, 2)

	TitleStyle = lipgloss.NewStyle().
			Foreground(Primary).
			Bold(true).
			MarginBottom(1).
			MarginTop(1)

	LogoStyle = lipgloss.NewStyle().
			Foreground(Secondary).
			Bold(true).
			Align(lipgloss.Center)

	SubtitleStyle = lipgloss.NewStyle().
			Foreground(Muted).
			Italic(true)

	BoxStyle = lipgloss.NewStyle().
			Border(lipgloss.RoundedBorder()).
			BorderForeground(Border).
			Padding(1, 2).
			MarginTop(1).
			MarginBottom(1)

	ActiveBoxStyle = lipgloss.NewStyle().
			Border(lipgloss.ThickBorder()).
			BorderForeground(Primary).
			Padding(1, 2).
			MarginTop(1).
			MarginBottom(1)

	InfoBoxStyle = lipgloss.NewStyle().
			Border(lipgloss.RoundedBorder()).
			BorderForeground(Secondary).
			Padding(0, 1).
			MarginTop(1)

	WarningBoxStyle = lipgloss.NewStyle().
			Border(lipgloss.RoundedBorder()).
			BorderForeground(Warning).
			Padding(0, 1).
			MarginTop(1)

	ErrorBoxStyle = lipgloss.NewStyle().
			Border(lipgloss.RoundedBorder()).
			BorderForeground(Error).
			Padding(0, 1).
			MarginTop(1)

	HelpStyle = lipgloss.NewStyle().
			Foreground(Muted).
			MarginTop(1)

	KeyStyle = lipgloss.NewStyle().
			Foreground(Primary).
			Bold(true)

	ValueStyle = lipgloss.NewStyle().
			Foreground(Text)

	ActiveItemStyle = lipgloss.NewStyle().
			Foreground(Primary).
			Bold(true).
			PaddingLeft(2)

	InactiveItemStyle = lipgloss.NewStyle().
			Foreground(Muted).
			PaddingLeft(2)

	SelectedItemStyle = lipgloss.NewStyle().
			Foreground(Success).
			Bold(true)

	LabelStyle = lipgloss.NewStyle().
			Foreground(Secondary).
			Bold(true).
			MarginRight(1)

	InputStyle = lipgloss.NewStyle().
			Foreground(Text).
			Border(lipgloss.RoundedBorder()).
			BorderForeground(Subtle).
			Padding(0, 1)

	FocusedInputStyle = lipgloss.NewStyle().
			Foreground(Text).
			Border(lipgloss.RoundedBorder()).
			BorderForeground(Primary).
			Padding(0, 1)

	ProgressBarStyle = lipgloss.NewStyle().
				Foreground(Primary)

	ProgressTextStyle = lipgloss.NewStyle().
				Foreground(Muted)

	SuccessStyle = lipgloss.NewStyle().
			Foreground(Success).
			Bold(true)

	ErrorStyle = lipgloss.NewStyle().
			Foreground(Error).
			Bold(true)

	SpinnerStyle = lipgloss.NewStyle().
			Foreground(Primary)
)

func RenderKeyValue(key, value string) string {
	return KeyStyle.Render(key+":") + " " + ValueStyle.Render(value)
}

func RenderHelp(keys ...string) string {
	var parts []string
	for i := 0; i < len(keys); i += 2 {
		if i+1 < len(keys) {
			parts = append(parts, KeyStyle.Render(keys[i])+" "+HelpStyle.Render(keys[i+1]))
		}
	}
	return HelpStyle.Render(lipgloss.JoinHorizontal(lipgloss.Left, parts...))
}
