package debugger

import (
	
	

	
	
)

// ///// ///// /////

// ///// THEMES

// ///// ///// /////

var themeDark = map[string]string{
	"active":     "yellow",
	"active2":    "greenyellow",
	"inactive":   "limegreen",
	"highlight":  "darkslategrey",
	"highlight2": "dimgrey",
	"highlight3": tcell.Color233.CSS(),
	"err":        "red",
	"errBg":      "indianred",
	"errRecent":  "#FF5FAF",
	"grey":       "darkgrey",
	"white":      "white",
	"yellow":     "yellow",
	"darkGrey":   "darkgrey",
	"green":      "green",
	"lightGrey":  "darkgrey",

	// defaults

	"title":    tcell.ColorWhite.CSS(),
	"border":   tcell.ColorGrey.CSS(),
	"graphics": tcell.ColorWhite.CSS(),

	"fgPrimary":         tcell.ColorWhite.CSS(),
	"fgSecondary":       tcell.ColorYellow.CSS(),
	"tertiary":          tcell.ColorLimeGreen.CSS(),
	"inverse":           tcell.ColorBlack.CSS(),
	"contrastPrimary":   tcell.ColorBlack.CSS(),
	"contrastSecondary": tcell.ColorLightSlateGray.CSS(),

	"bgPrimary":      tcell.ColorBlack.CSS(),
	"bgContrast":     tcell.ColorGreen.CSS(),
	"bgMoreContrast": tcell.ColorDarkGreen.CSS(),

	"scrollBar": tcell.ColorWhite.CSS(),
}

// TODO fix scollbars, log colors
var themeLight = map[string]string{
	"active":            "#7B6200",
	"active2":           "#005500",
	"inactive":          "#007700",
	"highlight":         "#C8DCE0",
	"highlight2":        "#B0B8BB",
	"highlight3":        "#EBEBEB",
	"err":               "#CC0000",
	"errBg":             "#B03030",
	"errRecent":         "#C7006B",
	"grey":              "#555555",
	"white":             "#111111",
	"yellow":            "#8B7500",
	"darkGrey":          "#888888",
	"green":             "#006400",
	"bgPrimary":         tcell.ColorWhite.CSS(),
	"bgContrast":        tcell.ColorOldLace.CSS(),
	"bgMoreContrast":    tcell.ColorLightGrey.CSS(),
	"fgPrimary":         tcell.ColorBlack.CSS(),
	"fgSecondary":       tcell.ColorDimGrey.CSS(),
	"border":            tcell.ColorGrey.CSS(),
	"title":             tcell.ColorBlack.CSS(),
	"graphics":          tcell.ColorBlack.CSS(),
	"tertiary":          tcell.ColorDarkGreen.CSS(),
	"inverse":           tcell.ColorWhite.CSS(),
	"contrastPrimary":   tcell.ColorWhite.CSS(),
	"contrastSecondary": tcell.ColorDarkGrey.CSS(),
	"scrollBar":         tcell.ColorBlack.CSS(),

	// TODO
	"lightGrey": "darkgrey",
}

// TODO move to types
type Theme struct {
	// primary active/selected state color
	Active string
	// secondary active color (changed states)
	Active2 string
	// inactive/default state color
	Inactive string
	// background highlight (selected items)
	Highlight string
	// secondary highlight (scrollbars, selections)
	Highlight2 string
	// tertiary highlight (table/matrix cells)
	Highlight3 string
	// error color
	Err string
	// error background color (accepted tx with exception state)
	ErrBg string
	// recent error indicator
	ErrRecent string
	// inline tview markup grey text
	Grey string
	// inline tview markup white/bright text
	White string
	// log prefix brackets
	Yellow string
	// faded/extern content
	DarkGrey string
	// accepted gutter, relation start
	Green string
	// addr button background
	LightGrey string

	// style overrides (cview.Styles)
	// title text color
	Title string
	// border color
	Border string
	// graphics color
	Graphics string

	// primitive background color
	BgPrimary string
	// contrast background color
	BgContrast string
	// more contrast background color
	BgMoreContrast string

	// primary text color
	FgPrimary string
	// secondary text color
	FgSecondary string
	// tertiary text color
	Tertiary string
	// inverse text color
	Inverse string
	// contrast primary text color
	ContrastPrimary string
	// contrast secondary text color
	ContrastSecondary string

	// scroll bar color
	ScrollBar string
}

// mapToTheme converts a string map into a Theme struct.
func mapToTheme( map[string]string,  bool) (Theme, error) {
	var  error
	// AI add safety fallback
	 := func( string) string {
		,  := []
		if  {
			return 
		}

		 = errors.Join(, fmt.Errorf("missing theme key: %s", ))
		// fallback TODO log err
		if  {
			return "white"
		}
		return "black"
	}

	return Theme{
		Active:     ("active"),
		Active2:    ("active2"),
		Inactive:   ("inactive"),
		Highlight:  ("highlight"),
		Highlight2: ("highlight2"),
		Highlight3: ("highlight3"),
		Err:        ("err"),
		ErrBg:      ("errBg"),
		ErrRecent:  ("errRecent"),
		Grey:       ("grey"),
		White:      ("white"),
		Yellow:     ("yellow"),
		DarkGrey:   ("darkGrey"),
		Green:      ("green"),
		LightGrey:  ("lightGrey"),

		// defaults

		Title:             ("title"),
		Border:            ("border"),
		Graphics:          ("graphics"),
		BgPrimary:         ("bgPrimary"),
		BgContrast:        ("bgContrast"),
		BgMoreContrast:    ("bgMoreContrast"),
		FgPrimary:         ("fgPrimary"),
		FgSecondary:       ("fgSecondary"),
		Tertiary:          ("tertiary"),
		Inverse:           ("inverse"),
		ContrastPrimary:   ("contrastPrimary"),
		ContrastSecondary: ("contrastSecondary"),
		ScrollBar:         ("scrollBar"),
	}, 
}

// Apply applies the theme to cview.Styles.
func ( Theme) () {
	cview.Styles.TitleColor = tcell.GetColor(.Title)
	cview.Styles.BorderColor = tcell.GetColor(.Border)
	cview.Styles.GraphicsColor = tcell.GetColor(.Graphics)

	cview.Styles.PrimaryTextColor = tcell.GetColor(.FgPrimary)
	cview.Styles.SecondaryTextColor = tcell.GetColor(.FgSecondary)
	cview.Styles.TertiaryTextColor = tcell.GetColor(.Tertiary)
	cview.Styles.InverseTextColor = tcell.GetColor(.Inverse)
	cview.Styles.ContrastPrimaryTextColor = tcell.GetColor(.ContrastPrimary)
	cview.Styles.ContrastSecondaryTextColor = tcell.GetColor(.ContrastSecondary)

	cview.Styles.PrimitiveBackgroundColor = tcell.GetColor(.BgPrimary)
	cview.Styles.ContrastBackgroundColor = tcell.GetColor(.BgContrast)
	cview.Styles.MoreContrastBackgroundColor = tcell.GetColor(.BgMoreContrast)

	cview.Styles.ScrollBarColor = tcell.GetColor(.ScrollBar)
}