package main

import (
	"fmt"

	"github.com/charmbracelet/lipgloss"
)

func main() {
	// Basic styling
	style := lipgloss.NewStyle().
		Bold(true).
		Foreground(lipgloss.Color("205")). // Pink
		Background(lipgloss.Color("63")).  // Purple
		Padding(1, 2)

	fmt.Println(style.Render("Hello, Gopher!"))

	// Color formats
	_ = lipgloss.Color("205")             // ANSI 256 color
	_ = lipgloss.Color("#FF6B6B")         // Hex color
	_ = lipgloss.Color("63")              // ANSI color
	_ = lipgloss.AdaptiveColor{           // Light/dark mode
		Light: "#000000",
		Dark:  "#FFFFFF",
	}

	// Text styling
	textStyle := lipgloss.NewStyle().
		Bold(true).
		Italic(true).
		Underline(true).
		Strikethrough(true).
		Faint(true)
	fmt.Println(textStyle.Render("Styled text"))

	// Borders
	borderStyle := lipgloss.NewStyle().
		Border(lipgloss.RoundedBorder()).
		BorderForeground(lipgloss.Color("63")).
		Padding(1, 2)
	fmt.Println(borderStyle.Render("Rounded border"))

	// Different border types
	_ = lipgloss.NormalBorder()
	_ = lipgloss.RoundedBorder()
	_ = lipgloss.ThickBorder()
	_ = lipgloss.DoubleBorder()
	_ = lipgloss.HiddenBorder()

	// Layout - Width and Height
	boxStyle := lipgloss.NewStyle().
		Width(40).
		Height(3).
		Align(lipgloss.Center, lipgloss.Center).
		Border(lipgloss.NormalBorder())
	fmt.Println(boxStyle.Render("Centered in a box"))

	// Alignment
	leftStyle := lipgloss.NewStyle().Width(20).Align(lipgloss.Left)
	centerStyle := lipgloss.NewStyle().Width(20).Align(lipgloss.Center)
	rightStyle := lipgloss.NewStyle().Width(20).Align(lipgloss.Right)

	fmt.Println(leftStyle.Render("Left"))
	fmt.Println(centerStyle.Render("Center"))
	fmt.Println(rightStyle.Render("Right"))

	// Margin and Padding
	spacedStyle := lipgloss.NewStyle().
		Margin(1, 2).       // top/bottom, left/right
		Padding(1, 2, 1, 2) // top, right, bottom, left
	fmt.Println(spacedStyle.Render("Spaced"))

	// Joining elements horizontally
	left := lipgloss.NewStyle().
		Width(20).
		Align(lipgloss.Center).
		Background(lipgloss.Color("62")).
		Render("Left Panel")

	right := lipgloss.NewStyle().
		Width(20).
		Align(lipgloss.Center).
		Background(lipgloss.Color("63")).
		Render("Right Panel")

	row := lipgloss.JoinHorizontal(lipgloss.Top, left, right)
	fmt.Println(row)

	// Joining elements vertically
	header := lipgloss.NewStyle().
		Width(40).
		Align(lipgloss.Center).
		Background(lipgloss.Color("63")).
		Render("Header")

	body := lipgloss.NewStyle().
		Width(40).
		Height(3).
		Align(lipgloss.Center, lipgloss.Center).
		Render("Body content")

	column := lipgloss.JoinVertical(lipgloss.Center, header, body)
	fmt.Println(column)

	// Copy and inherit styles
	baseStyle := lipgloss.NewStyle().
		Foreground(lipgloss.Color("205"))

	// Create variant by copying and modifying
	boldVariant := baseStyle.Bold(true)
	italicVariant := baseStyle.Italic(true)

	fmt.Println(boldVariant.Render("Bold variant"))
	fmt.Println(italicVariant.Render("Italic variant"))

	// Get rendered size
	rendered := boxStyle.Render("Hello")
	width := lipgloss.Width(rendered)
	height := lipgloss.Height(rendered)
	fmt.Printf("Size: %dx%d\n", width, height)

	// Place content at position
	placed := lipgloss.Place(40, 5, lipgloss.Center, lipgloss.Center, "Centered")
	fmt.Println(placed)
}
