package lipgloss

import (
	
	

	
)

// Position represents a position along a horizontal or vertical axis. It's in
// situations where an axis is involved, like alignment, joining, placement and
// so on.
//
// A value of 0 represents the start (the left or top) and 1 represents the end
// (the right or bottom). 0.5 represents the center.
//
// There are constants Top, Bottom, Center, Left and Right in this package that
// can be used to aid readability.
type Position float64

func ( Position) () float64 {
	return math.Min(1, math.Max(0, float64()))
}

// Position aliases.
const (
	Top    Position = 0.0
	Bottom Position = 1.0
	Center Position = 0.5
	Left   Position = 0.0
	Right  Position = 1.0
)

// Place places a string or text block vertically in an unstyled box of a given
// width or height.
func (,  int, ,  Position,  string,  ...WhitespaceOption) string {
	return PlaceVertical(, , PlaceHorizontal(, , , ...), ...)
}

// PlaceHorizontal places a string or text block horizontally in an unstyled
// block of a given width. If the given width is shorter than the max width of
// the string (measured by its longest line) this will be a noöp.
func ( int,  Position,  string,  ...WhitespaceOption) string {
	,  := getLines()
	 :=  - 

	if  <= 0 {
		return 
	}

	 := newWhitespace(...)

	var  strings.Builder
	for ,  := range  {
		// Is this line shorter than the longest line?
		 := max(0, -ansi.StringWidth())

		switch  {
		case Left:
			.WriteString()
			.WriteString(.render( + ))

		case Right:
			.WriteString(.render( + ))
			.WriteString()

		default: // somewhere in the middle
			 :=  + 

			 := int(math.Round(float64() * .value()))
			 :=  - 
			 :=  - 

			.WriteString(.render())
			.WriteString()
			.WriteString(.render())
		}

		if  < len()-1 {
			.WriteRune('\n')
		}
	}

	return .String()
}

// PlaceVertical places a string or text block vertically in an unstyled block
// of a given height. If the given height is shorter than the height of the
// string (measured by its newlines) then this will be a noöp.
func ( int,  Position,  string,  ...WhitespaceOption) string {
	 := strings.Count(, "\n") + 1
	 :=  - 

	if  <= 0 {
		return 
	}

	 := newWhitespace(...)

	,  := getLines()
	 := .render()
	 := strings.Builder{}

	switch  {
	case Top:
		.WriteString()
		.WriteRune('\n')
		for  := range  {
			.WriteString()
			if  < -1 {
				.WriteRune('\n')
			}
		}

	case Bottom:
		.WriteString(strings.Repeat(+"\n", ))
		.WriteString()

	default: // Somewhere in the middle
		 := int(math.Round(float64() * .value()))
		 :=  - 
		 :=  - 

		.WriteString(strings.Repeat(+"\n", ))
		.WriteString()

		for range  {
			.WriteRune('\n')
			.WriteString()
		}
	}

	return .String()
}