package tk

import (
	
	
)

// VScrollbarContainer is a Renderer consisting of content and a vertical
// scrollbar on the right.
type VScrollbarContainer struct {
	Content   Renderer
	Scrollbar VScrollbar
}

func ( VScrollbarContainer) (,  int) *term.Buffer {
	 := .Content.Render(-1, )
	.ExtendRight(.Scrollbar.Render(1, ))
	return 
}

// VScrollbar is a Renderer for a vertical scrollbar.
type VScrollbar struct {
	Total int
	Low   int
	High  int
}

var (
	vscrollbarThumb  = ui.T(" ", ui.FgMagenta, ui.Inverse)
	vscrollbarTrough = ui.T("│", ui.FgMagenta)
)

func ( VScrollbar) (,  int) *term.Buffer {
	,  := findScrollInterval(.Total, .Low, .High, )
	 := term.NewBufferBuilder(1)
	for  := 0;  < ; ++ {
		if  > 0 {
			.Newline()
		}
		if  <=  &&  <  {
			.WriteStyled(vscrollbarThumb)
		} else {
			.WriteStyled(vscrollbarTrough)
		}
	}
	return .Buffer()
}

// HScrollbar is a Renderer for a horizontal scrollbar.
type HScrollbar struct {
	Total int
	Low   int
	High  int
}

var (
	hscrollbarThumb  = ui.T(" ", ui.FgMagenta, ui.Inverse)
	hscrollbarTrough = ui.T("━", ui.FgMagenta)
)

func ( HScrollbar) (,  int) *term.Buffer {
	,  := findScrollInterval(.Total, .Low, .High, )
	 := term.NewBufferBuilder()
	for  := 0;  < ; ++ {
		if  <=  &&  <  {
			.WriteStyled(hscrollbarThumb)
		} else {
			.WriteStyled(hscrollbarTrough)
		}
	}
	return .Buffer()
}

func (, , ,  int) (int, int) {
	 := func( int) int {
		return int(float64()/float64()*float64() + 0.5)
	}
	 := ()
	// We use the following instead of f(high), so that the size of the
	// scrollbar remains the same as long as the window size remains the same.
	 :=  + (-)

	if  ==  {
		if  ==  {
			--
		} else {
			++
		}
	}
	return , 
}