// Package tokens defines the canonical turbo-12f Obsidian + Plum + Electric Orchid
// palette and terminal styling constants for Go CLI and backend renderers.
// Standard library only; zero external dependencies.
package tokens

import "fmt"

// Palette holds exact hex colors for a single theme polarity.
type Palette struct {
	Background        string
	Foreground        string
	MutedForeground   string
	Card              string
	Popover           string
	Muted             string
	Secondary         string
	BorderHex         string
	PlumRule          string
	Primary           string
	PrimaryForeground string
	Info              string
	Success           string
	Warning           string
	Danger            string
}

// Dark is the default Obsidian + Plum + Electric Orchid palette.
var Dark = Palette{
	Background:        "#0c0c0c",
	Foreground:        "#ffffff",
	MutedForeground:   "#c2c2c2",
	Card:              "#131014",
	Popover:           "#161217",
	Muted:             "#18131a",
	Secondary:         "#1e1620",
	BorderHex:         "#543554",
	PlumRule:          "#543554",
	Primary:           "#ff96ff",
	PrimaryForeground: "#0c0c0c",
	Info:              "#60a5fa",
	Success:           "#4ade80",
	Warning:           "#fbbf24",
	Danger:            "#fb7185",
}

// Light is the daytime companion palette.
var Light = Palette{
	Background:        "#faf8fa",
	Foreground:        "#141016",
	MutedForeground:   "#554a59",
	Card:              "#f3eef4",
	Popover:           "#ffffff",
	Muted:             "#efe9f0",
	Secondary:         "#ede4ef",
	BorderHex:         "#dfd3e2",
	PlumRule:          "#b88fbc",
	Primary:           "#9e219e",
	PrimaryForeground: "#ffffff",
	Info:              "#2563eb",
	Success:           "#15803d",
	Warning:           "#b45309",
	Danger:            "#be123c",
}

// RGB represents a 24-bit color tuple for TrueColor ANSI output.
type RGB struct {
	R, G, B uint8
}

// TrueColor returns the ANSI 24-bit foreground SGR sequence for this RGB value.
func (c RGB) TrueColor() string {
	return fmt.Sprintf("\x1b[38;2;%d;%d;%dm", c.R, c.G, c.B)
}

// CLI terminal palette tuples and 256-color fallback indices.
var (
	RGBObsidian = RGB{12, 12, 12}
	RGBWhite    = RGB{255, 255, 255}
	RGBMuted    = RGB{194, 194, 194}
	RGBPlum     = RGB{84, 53, 84}
	RGBOrchid   = RGB{255, 150, 255}
	RGBInfo     = RGB{96, 165, 250}
	RGBSuccess  = RGB{74, 222, 128}
	RGBWarning  = RGB{251, 191, 36}
	RGBDanger   = RGB{251, 113, 133}
)

const (
	ANSIReset       = "\x1b[0m"
	ANSIBold        = "\x1b[1m"
	ANSI256Orchid   = "\x1b[38;5;213m"
	ANSI256Plum     = "\x1b[38;5;53m"
	ANSI256Muted    = "\x1b[38;5;250m"
	ANSI256Success  = "\x1b[38;5;77m"
	ANSI256Warning  = "\x1b[38;5;221m"
	ANSI256Danger   = "\x1b[38;5;210m"
)
