package ui

type Size string

const (
	SizeSM Size = "sm"
	SizeMD Size = "md"
	SizeLG Size = "lg"
)

type ButtonVariant string

const (
	ButtonVariantDefault ButtonVariant = "default"
	ButtonVariantNeutral ButtonVariant = "neutral"
	ButtonVariantWarning ButtonVariant = "warning"
	ButtonVariantSuccess ButtonVariant = "success"
	ButtonVariantDanger  ButtonVariant = "danger"
)

type ButtonTone string

const (
	ButtonToneSolid ButtonTone = "solid"
	ButtonToneSoft  ButtonTone = "soft"
)

type IconButtonVariant string

const (
	IconButtonVariantNeutral IconButtonVariant = "neutral"
	IconButtonVariantWarning IconButtonVariant = "warning"
	IconButtonVariantSuccess IconButtonVariant = "success"
	IconButtonVariantDanger  IconButtonVariant = "danger"
)

type IconButtonTone string

const (
	IconButtonToneSolid IconButtonTone = "solid"
	IconButtonToneGhost IconButtonTone = "ghost"
)

type SpacingStep string

const (
	SpacingStepXS SpacingStep = "xs"
	SpacingStepSM SpacingStep = "sm"
	SpacingStepMD SpacingStep = "md"
	SpacingStepLG SpacingStep = "lg"
	SpacingStepXL SpacingStep = "xl"
)

type BadgeVariant string

const (
	BadgeVariantInfo    BadgeVariant = "info"
	BadgeVariantWarning BadgeVariant = "warning"
	BadgeVariantSuccess BadgeVariant = "success"
	BadgeVariantDanger  BadgeVariant = "danger"
)

func buttonClass(variant ButtonVariant, tone ButtonTone, size Size) string {
	return "ui-button ui-button-" + string(normalizedButtonTone(tone)) + " ui-button-" + string(normalizedButtonVariant(variant)) + " ui-button-" + string(normalizedSize(size))
}

func iconButtonClass(variant IconButtonVariant, tone IconButtonTone) string {
	normalizedVariant := normalizedIconButtonVariant(variant)

	switch normalizedIconButtonTone(tone) {
	case IconButtonToneGhost:
		return "borderless-icon-button ui-icon-button-ghost ui-icon-button-" + string(normalizedVariant)
	default:
		return "ui-icon-button ui-icon-button-solid ui-icon-button-" + string(normalizedVariant)
	}
}

func badgeClass(variant BadgeVariant) string {
	return "ui-badge ui-badge-" + string(normalizedBadgeVariant(variant))
}

func spaceXClass(step SpacingStep) string {
	return "ui-space-x ui-space-x-" + string(normalizedSpacingStep(step))
}

func spaceYClass(step SpacingStep) string {
	return "ui-space-y ui-space-y-" + string(normalizedSpacingStep(step))
}

func normalizedSize(size Size) Size {
	switch size {
	case SizeSM, SizeLG:
		return size
	default:
		return SizeMD
	}
}

func normalizedButtonVariant(variant ButtonVariant) ButtonVariant {
	switch variant {
	case ButtonVariantNeutral, ButtonVariantWarning, ButtonVariantSuccess, ButtonVariantDanger:
		return variant
	default:
		return ButtonVariantDefault
	}
}

func normalizedButtonTone(tone ButtonTone) ButtonTone {
	switch tone {
	case ButtonToneSoft:
		return tone
	default:
		return ButtonToneSolid
	}
}

func normalizedIconButtonVariant(variant IconButtonVariant) IconButtonVariant {
	switch variant {
	case IconButtonVariantWarning, IconButtonVariantSuccess, IconButtonVariantDanger:
		return variant
	default:
		return IconButtonVariantNeutral
	}
}

func normalizedIconButtonTone(tone IconButtonTone) IconButtonTone {
	switch tone {
	case IconButtonToneGhost:
		return tone
	default:
		return IconButtonToneSolid
	}
}

func normalizedSpacingStep(step SpacingStep) SpacingStep {
	switch step {
	case SpacingStepXS, SpacingStepSM, SpacingStepLG, SpacingStepXL:
		return step
	default:
		return SpacingStepMD
	}
}

func normalizedBadgeVariant(variant BadgeVariant) BadgeVariant {
	switch variant {
	case BadgeVariantWarning, BadgeVariantSuccess, BadgeVariantDanger:
		return variant
	default:
		return BadgeVariantInfo
	}
}
