package uv

// NormalBorder returns a standard-type border with a normal weight and 90
// degree corners.
func () Border {
	return Border{
		Top:         Side{Content: "─"},
		Bottom:      Side{Content: "─"},
		Left:        Side{Content: "│"},
		Right:       Side{Content: "│"},
		TopLeft:     Side{Content: "┌"},
		TopRight:    Side{Content: "┐"},
		BottomLeft:  Side{Content: "└"},
		BottomRight: Side{Content: "┘"},
	}
}

// RoundedBorder returns a border with rounded corners.
func () Border {
	return Border{
		Top:         Side{Content: "─"},
		Bottom:      Side{Content: "─"},
		Left:        Side{Content: "│"},
		Right:       Side{Content: "│"},
		TopLeft:     Side{Content: "╭"},
		TopRight:    Side{Content: "╮"},
		BottomLeft:  Side{Content: "╰"},
		BottomRight: Side{Content: "╯"},
	}
}

// BlockBorder returns a border that takes the whole block.
func () Border {
	return Border{
		Top:         Side{Content: "█"},
		Bottom:      Side{Content: "█"},
		Left:        Side{Content: "█"},
		Right:       Side{Content: "█"},
		TopLeft:     Side{Content: "█"},
		TopRight:    Side{Content: "█"},
		BottomLeft:  Side{Content: "█"},
		BottomRight: Side{Content: "█"},
	}
}

// OuterHalfBlockBorder returns a half-block border that sits outside the frame.
func () Border {
	return Border{
		Top:         Side{Content: "▀"},
		Bottom:      Side{Content: "▄"},
		Left:        Side{Content: "▌"},
		Right:       Side{Content: "▐"},
		TopLeft:     Side{Content: "▛"},
		TopRight:    Side{Content: "▜"},
		BottomLeft:  Side{Content: "▙"},
		BottomRight: Side{Content: "▟"},
	}
}

// InnerHalfBlockBorder returns a half-block border that sits inside the frame.
func () Border {
	return Border{
		Top:         Side{Content: "▄"},
		Bottom:      Side{Content: "▀"},
		Left:        Side{Content: "▐"},
		Right:       Side{Content: "▌"},
		TopLeft:     Side{Content: "▗"},
		TopRight:    Side{Content: "▖"},
		BottomLeft:  Side{Content: "▝"},
		BottomRight: Side{Content: "▘"},
	}
}

// ThickBorder returns a border that's thicker than the one returned by
// NormalBorder.
func () Border {
	return Border{
		Top:         Side{Content: "━"},
		Bottom:      Side{Content: "━"},
		Left:        Side{Content: "┃"},
		Right:       Side{Content: "┃"},
		TopLeft:     Side{Content: "┏"},
		TopRight:    Side{Content: "┓"},
		BottomLeft:  Side{Content: "┗"},
		BottomRight: Side{Content: "┛"},
	}
}

// DoubleBorder returns a border comprised of two thin strokes.
func () Border {
	return Border{
		Top:         Side{Content: "═"},
		Bottom:      Side{Content: "═"},
		Left:        Side{Content: "║"},
		Right:       Side{Content: "║"},
		TopLeft:     Side{Content: "╔"},
		TopRight:    Side{Content: "╗"},
		BottomLeft:  Side{Content: "╚"},
		BottomRight: Side{Content: "╝"},
	}
}

// HiddenBorder returns a border that renders as a series of single-cell
// spaces. It's useful for cases when you want to remove a standard border but
// maintain layout positioning. This said, you can still apply a background
// color to a hidden border.
func () Border {
	return Border{
		Top:         Side{Content: " "},
		Bottom:      Side{Content: " "},
		Left:        Side{Content: " "},
		Right:       Side{Content: " "},
		TopLeft:     Side{Content: " "},
		TopRight:    Side{Content: " "},
		BottomLeft:  Side{Content: " "},
		BottomRight: Side{Content: " "},
	}
}

// MarkdownBorder return a table border in markdown style.
func () Border {
	return Border{
		Left:        Side{Content: "|"},
		Right:       Side{Content: "|"},
		TopLeft:     Side{Content: "|"},
		TopRight:    Side{Content: "|"},
		BottomLeft:  Side{Content: "|"},
		BottomRight: Side{Content: "|"},
	}
}

// ASCIIBorder returns a table border with ASCII characters.
func () Border {
	return Border{
		Top:         Side{Content: "-"},
		Bottom:      Side{Content: "-"},
		Left:        Side{Content: "|"},
		Right:       Side{Content: "|"},
		TopLeft:     Side{Content: "+"},
		TopRight:    Side{Content: "+"},
		BottomLeft:  Side{Content: "+"},
		BottomRight: Side{Content: "+"},
	}
}

// Side represents a single border side with its properties.
type Side struct {
	Content string
	Style
	Link
}

// Border represents a border with its properties.
type Border struct {
	Top         Side
	Bottom      Side
	Left        Side
	Right       Side
	TopLeft     Side
	TopRight    Side
	BottomLeft  Side
	BottomRight Side
}

// Style returns a new [Border] with the given style applied to all [Side]s.
func ( Border) ( Style) Border {
	.Top.Style = 
	.Bottom.Style = 
	.Left.Style = 
	.Right.Style = 
	.TopLeft.Style = 
	.TopRight.Style = 
	.BottomLeft.Style = 
	.BottomRight.Style = 
	return 
}

// Link returns a new [Border] with the given link applied to all [Side]s.
func ( Border) ( Link) Border {
	.Top.Link = 
	.Bottom.Link = 
	.Left.Link = 
	.Right.Link = 
	.TopLeft.Link = 
	.TopRight.Link = 
	.BottomLeft.Link = 
	.BottomRight.Link = 
	return 
}

// Draw draws the border around the given component.
func ( *Border) ( Screen,  Rectangle) {
	for  := .Min.Y;  < .Max.Y; ++ {
		for  := .Min.X;  < .Max.X; ++ {
			var  *Cell
			switch {
			case  == .Min.Y &&  == .Min.X:
				 = borderCell(, &.TopLeft)
			case  == .Min.Y &&  == .Max.X-1:
				 = borderCell(, &.TopRight)
			case  == .Max.Y-1 &&  == .Min.X:
				 = borderCell(, &.BottomLeft)
			case  == .Max.Y-1 &&  == .Max.X-1:
				 = borderCell(, &.BottomRight)
			case  == .Min.Y:
				 = borderCell(, &.Top)
			case  == .Max.Y-1:
				 = borderCell(, &.Bottom)
			case  == .Min.X:
				 = borderCell(, &.Left)
			case  == .Max.X-1:
				 = borderCell(, &.Right)
			default:
				continue
			}
			if  == nil {
				continue
			}
			.SetCell(, , )
		}
	}
}

func ( Screen,  *Side) *Cell {
	 := NewCell(.WidthMethod(), .Content)
	if  != nil {
		.Style = .Style
		.Link = .Link
	}
	return 
}