package ui

import (
	
	
)

// Style specifies how something (mostly a string) shall be displayed.
type Style struct {
	Foreground Color
	Background Color
	Bold       bool
	Dim        bool
	Italic     bool
	Underlined bool
	Blink      bool
	Inverse    bool
}

// SGR returns SGR sequence for the style.
func ( Style) () string {
	var  []string

	 := func( bool,  string) {
		if  {
			 = append(, )
		}
	}
	(.Bold, "1")
	(.Dim, "2")
	(.Italic, "3")
	(.Underlined, "4")
	(.Blink, "5")
	(.Inverse, "7")
	if .Foreground != nil {
		 = append(, .Foreground.fgSGR())
	}
	if .Background != nil {
		 = append(, .Background.bgSGR())
	}

	return strings.Join(, ";")
}

// MergeFromOptions merges all recognized values from a map to the current
// Style.
func ( *Style) ( map[string]interface{}) error {
	 := func( interface{},  *Color) string {
		if  == "default" {
			* = nil
			return ""
		} else if ,  := .(string);  {
			 := parseColor()
			if  != nil {
				* = 
				return ""
			}
		}
		return "valid color string"
	}
	 := func( interface{},  *bool) string {
		if ,  := .(bool);  {
			* = 
		} else {
			return "bool value"
		}
		return ""
	}

	for ,  := range  {
		var  string

		switch  {
		case "fg-color":
			 = (, &.Foreground)
		case "bg-color":
			 = (, &.Background)
		case "bold":
			 = (, &.Bold)
		case "dim":
			 = (, &.Dim)
		case "italic":
			 = (, &.Italic)
		case "underlined":
			 = (, &.Underlined)
		case "blink":
			 = (, &.Blink)
		case "inverse":
			 = (, &.Inverse)

		default:
			return fmt.Errorf("unrecognized option '%s'", )
		}

		if  != "" {
			return fmt.Errorf("value for option '%s' must be a %s", , )
		}
	}

	return nil
}