// SPDX-License-Identifier: GPL-3.0-or-later

// Package output provides color handling utilities.
package output

import "fmt"

// Colors handles colored output.
type Colors struct {
	enabled bool
}

// NewColors creates a new Colors instance.
func NewColors(enabled bool) *Colors {
	return &Colors{enabled: enabled}
}

// Enabled returns true if colors are enabled.
func (c *Colors) Enabled() bool {
	return c.enabled
}

// ANSI color codes
const (
	reset   = "\033[0m"
	bold    = "\033[1m"
	dim     = "\033[2m"
	red     = "\033[31m"
	green   = "\033[32m"
	yellow  = "\033[33m"
	blue    = "\033[34m"
	magenta = "\033[35m"
	cyan    = "\033[36m"
	white   = "\033[37m"
)

// Success returns green text.
func (c *Colors) Success(s string) string {
	if !c.enabled {
		return s
	}
	return green + s + reset
}

// Error returns red text.
func (c *Colors) Error(s string) string {
	if !c.enabled {
		return s
	}
	return red + s + reset
}

// Warning returns yellow text.
func (c *Colors) Warning(s string) string {
	if !c.enabled {
		return s
	}
	return yellow + s + reset
}

// Info returns blue text.
func (c *Colors) Info(s string) string {
	if !c.enabled {
		return s
	}
	return blue + s + reset
}

// Bold returns bold text.
func (c *Colors) Bold(s string) string {
	if !c.enabled {
		return s
	}
	return bold + s + reset
}

// Muted returns muted/dimmed text (alias for Dim).
func (c *Colors) Muted(s string) string {
	return c.Dim(s)
}

// Dim returns dimmed text.
func (c *Colors) Dim(s string) string {
	if !c.enabled {
		return s
	}
	return dim + s + reset
}

// Cyan returns cyan text.
func (c *Colors) Cyan(s string) string {
	if !c.enabled {
		return s
	}
	return cyan + s + reset
}

// Magenta returns magenta text.
func (c *Colors) Magenta(s string) string {
	if !c.enabled {
		return s
	}
	return magenta + s + reset
}

// White returns white text.
func (c *Colors) White(s string) string {
	if !c.enabled {
		return s
	}
	return white + s + reset
}

// Successf returns formatted green text.
func (c *Colors) Successf(format string, a ...interface{}) string {
	return c.Success(fmt.Sprintf(format, a...))
}

// Errorf returns formatted red text.
func (c *Colors) Errorf(format string, a ...interface{}) string {
	return c.Error(fmt.Sprintf(format, a...))
}

// Warningf returns formatted yellow text.
func (c *Colors) Warningf(format string, a ...interface{}) string {
	return c.Warning(fmt.Sprintf(format, a...))
}

// Infof returns formatted blue text.
func (c *Colors) Infof(format string, a ...interface{}) string {
	return c.Info(fmt.Sprintf(format, a...))
}

// Boldf returns formatted bold text.
func (c *Colors) Boldf(format string, a ...interface{}) string {
	return c.Bold(fmt.Sprintf(format, a...))
}
