package ansi

import (
	
	

	
)

// HexColor is a [color.Color] that can be formatted as a hex string.
type HexColor string

// RGBA returns the RGBA values of the color.
func ( HexColor) () (, , ,  uint32) {
	 := .color()
	if  == nil {
		return 0, 0, 0, 0
	}
	return .RGBA()
}

// Hex returns the hex representation of the color. If the color is invalid, it
// returns an empty string.
func ( HexColor) () string {
	 := .color()
	if  == nil {
		return ""
	}
	return .Hex()
}

// String returns the color as a hex string. If the color is nil, an empty
// string is returned.
func ( HexColor) () string {
	return .Hex()
}

// color returns the underlying color of the HexColor.
func ( HexColor) () *colorful.Color {
	,  := colorful.Hex(string())
	if  != nil {
		return nil
	}
	return &
}

// XRGBColor is a [color.Color] that can be formatted as an XParseColor
// rgb: string.
//
// See: https://linux.die.net/man/3/xparsecolor
type XRGBColor struct {
	color.Color
}

// RGBA returns the RGBA values of the color.
func ( XRGBColor) () (, , ,  uint32) {
	if .Color == nil {
		return 0, 0, 0, 0
	}
	return .Color.RGBA()
}

// String returns the color as an XParseColor rgb: string. If the color is nil,
// an empty string is returned.
func ( XRGBColor) () string {
	if .Color == nil {
		return ""
	}
	, , ,  := .Color.RGBA()
	// Get the lower 8 bits
	return fmt.Sprintf("rgb:%04x/%04x/%04x", , , )
}

// XRGBAColor is a [color.Color] that can be formatted as an XParseColor
// rgba: string.
//
// See: https://linux.die.net/man/3/xparsecolor
type XRGBAColor struct {
	color.Color
}

// RGBA returns the RGBA values of the color.
func ( XRGBAColor) () (, , ,  uint32) {
	if .Color == nil {
		return 0, 0, 0, 0
	}
	return .Color.RGBA()
}

// String returns the color as an XParseColor rgba: string. If the color is nil,
// an empty string is returned.
func ( XRGBAColor) () string {
	if .Color == nil {
		return ""
	}
	, , ,  := .RGBA()
	// Get the lower 8 bits
	return fmt.Sprintf("rgba:%04x/%04x/%04x/%04x", , , , )
}

// SetForegroundColor returns a sequence that sets the default terminal
// foreground color.
//
//	OSC 10 ; color ST
//	OSC 10 ; color BEL
//
// Where color is the encoded color number. Most terminals support hex,
// XParseColor rgb: and rgba: strings. You could use [HexColor], [XRGBColor],
// or [XRGBAColor] to format the color.
//
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
func ( string) string {
	return "\x1b]10;" +  + "\x07"
}

// RequestForegroundColor is a sequence that requests the current default
// terminal foreground color.
//
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
const RequestForegroundColor = "\x1b]10;?\x07"

// ResetForegroundColor is a sequence that resets the default terminal
// foreground color.
//
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
const ResetForegroundColor = "\x1b]110\x07"

// SetBackgroundColor returns a sequence that sets the default terminal
// background color.
//
//	OSC 11 ; color ST
//	OSC 11 ; color BEL
//
// Where color is the encoded color number. Most terminals support hex,
// XParseColor rgb: and rgba: strings. You could use [HexColor], [XRGBColor],
// or [XRGBAColor] to format the color.
//
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
func ( string) string {
	return "\x1b]11;" +  + "\x07"
}

// RequestBackgroundColor is a sequence that requests the current default
// terminal background color.
//
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
const RequestBackgroundColor = "\x1b]11;?\x07"

// ResetBackgroundColor is a sequence that resets the default terminal
// background color.
//
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
const ResetBackgroundColor = "\x1b]111\x07"

// SetCursorColor returns a sequence that sets the terminal cursor color.
//
//	OSC 12 ; color ST
//	OSC 12 ; color BEL
//
// Where color is the encoded color number. Most terminals support hex,
// XParseColor rgb: and rgba: strings. You could use [HexColor], [XRGBColor],
// or [XRGBAColor] to format the color.
//
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
func ( string) string {
	return "\x1b]12;" +  + "\x07"
}

// RequestCursorColor is a sequence that requests the current terminal cursor
// color.
//
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
const RequestCursorColor = "\x1b]12;?\x07"

// ResetCursorColor is a sequence that resets the terminal cursor color.
//
// See: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html#h3-Operating-System-Commands
const ResetCursorColor = "\x1b]112\x07"