package debugger

import (
	
	
	
	
	

	

	

	
)

type Focusable struct {
	cview.Primitive
	*cview.Box
}

type toolbarItem struct {
	id          ToolName
	label       string
	icon        string
	active      func() bool
	activeLabel func() string
}

// TODO migrate to Provide-Delivered
func ( *Debugger) func(string) any {
	// TODO make it panic-safe (check states and nils)
	return func( string) any {
		switch  {

		case server.GetCursorTx.Encode():
			return .C.CursorTx1

		case server.GetCursorStep.Encode():
			return .C.CursorStep1

		case server.GetMsgCount.Encode():
			return len(.C.MsgTxs)

		case server.GetClientCount.Encode():
			return len(.Clients)

		case server.GetOpts.Encode():
			return .Opts

		case server.GetSelectedState.Encode():
			return .C.SelectedState

		}

		return nil
	}
}

func formatTxBarTitle( string) string {
	return "[::u]" +  + "[::-]"
}

var digitsRe = regexp.MustCompile(`[0-9]+`)

func humanSort( []string) {
	sort.Slice(, func(,  int) bool {
		// skip overlapping parts
		 := min(len([]), len([]))
		 := 0
		for  := 0;  < ; ++ {
			if [][] != [][] {
				break
			}
			++
		}

		// if the diff is a letter, compare as strings
		if !unicode.IsDigit(getRuneAt([], )) ||
			!unicode.IsDigit(getRuneAt([], )) {
			return [] < []
		}

		// if contains numbers - sort by numbers
		 := digitsRe.FindAllString([][:], -1)
		 := digitsRe.FindAllString([][:], -1)
		,  := strconv.Atoi([0])
		,  := strconv.Atoi([0])

		if  !=  {
			// If the numbers are different, order by the numbers
			return  < 
		}

		// If the numbers are the same, order lexicographically
		return [] < []
	})
}

func getRuneAt( string,  int) rune {
	if  < 0 ||  >= len() {
		return 0 // or handle the error as needed
	}
	return []rune()[]
}

func matrixCellVal( string) string {
	switch len() {
	case 1:
		 = " " +  + " "
	case 2:
		 = " " + 
	}
	return 
}

func matrixEmptyRow( *Debugger, , ,  int) {
	// empty row
	for  := 0;  < ; ++ {
		.matrix.SetCellSimple(, , "   ")
		if  ==  {
			.matrix.GetCell(, ).SetBackgroundColor(colorHighlight3)
		}
	}
}

// findFirstDiff returns the index of the first differing character between two
// strings. If the strings are identical, it returns -1.
func findFirstDiff(,  string) int {
	 := len()
	if len() <  {
		 = len()
	}

	for  := 0;  < ; ++ {
		if [] != [] {
			return 
		}
	}

	if len() != len() {
		return 
	}

	return -1
}

func tickStrToTime( *machine.Machine,  []string) machine.Time {
	 := make(machine.Time, len())
	for ,  := range  {
		,  := strconv.Atoi()
		if  != nil {
			.AddErr(, nil)
			continue
		}
		[] = uint64()
	}

	return 
}

func () uint64 {
	var  runtime.MemStats
	runtime.ReadMemStats(&)
	return .Alloc
}