package lipgloss

import (
	

	
)

// Perform text alignment. If the string is multi-lined, we also make all lines
// the same width by padding them with spaces. If a style is passed, use that
// to style the spaces added.
func ( string,  Position,  int,  *ansi.Style) string {
	,  := getLines()
	var  strings.Builder

	for ,  := range  {
		 := ansi.StringWidth()

		 :=  -                 // difference from the widest line
		 += max(0, -(+)) // difference from the total width, if set

		if  > 0 {
			switch  {
			case Right:
				 := strings.Repeat(" ", )
				if  != nil {
					 = .Styled()
				}
				 =  + 
			case Center:
				// Note: remainder goes on the right.
				 :=  / 2       //nolint:mnd
				 :=  + %2 //nolint:mnd

				 := strings.Repeat(" ", )
				 := strings.Repeat(" ", )

				if  != nil {
					 = .Styled()
					 = .Styled()
				}
				 =  +  + 
			default: // Left
				 := strings.Repeat(" ", )
				if  != nil {
					 = .Styled()
				}
				 += 
			}
		}

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

	return .String()
}

func ( string,  Position,  int,  *ansi.Style) string {
	 := strings.Count(, "\n") + 1
	if  <  {
		return 
	}

	switch  {
	case Top:
		return  + strings.Repeat("\n", -)
	case Center:
		,  := (-)/2, (-)/2 //nolint:mnd
		if ++ >  {
			--
		} else if ++ <  {
			++
		}
		return strings.Repeat("\n", ) +  + strings.Repeat("\n", )
	case Bottom:
		return strings.Repeat("\n", -) + 
	}
	return 
}