package common

import (
	"fmt"
	"strconv"

	"github.com/gdamore/tcell/v2"
)

type FormatOptions struct {
	Color tcell.Color

	Bold,
	Italic,
	Underline,
	StrikeThrough bool
}

func Format(s string, opts FormatOptions) string {
	var boldTag, italicTag, underlineTag, strikeThroughTag string

	switch {
	case opts.Bold:
		boldTag = "b"
	case opts.Italic:
		italicTag = "i"
	case opts.Underline:
		underlineTag = "u"
	case opts.StrikeThrough:
		strikeThroughTag = "s"
	}

	attrs := fmt.Sprintf(
		"%s%s%s%s", boldTag, italicTag, underlineTag, strikeThroughTag,
	)
	color := strconv.FormatInt(int64(opts.Color.Hex()), 16)

	return fmt.Sprintf("[#%06s::%s]%s[-::-]", color, attrs, s)
}

func FormatSimple(s string, c tcell.Color) string {
	return Format(s, FormatOptions{Color: c})
}