package gui

import clay "clay:."
import "core:fmt"

// ─── Clay UI Primitives ───────────────────────────────────────────
declare_nav_chip :: proc(id: string, label: string, active: bool) {
	bg: clay.Color = clay.Color{0, 0, 0, 0}
	if active { bg = CLAY_NAV_HOVER_BG }
	if clay.UI(clay.ID(id))({
		layout = {sizing = {width = clay.SizingFit({min = 70, max = 34}), height = clay.SizingFixed(34)}, padding = {top = 4, right = 12, bottom = 4, left = 12}, childAlignment = {x = .Center, y = .Center}},
		backgroundColor = bg,
		cornerRadius = clay.CornerRadiusAll(CLAY_RADIUS_SM),
	}) {
		text_color: clay.Color = CLAY_TEXT_SECONDARY
		if active { text_color = CLAY_TEXT_BRIGHT }
		clay_body_text(label, color = text_color)
	}
}

declare_button :: proc(id: string, label: string, bg, hover_bg: clay.Color) {
	is_hovered := clay.Hovered()
 current_bg: clay.Color = bg
 if is_hovered { current_bg = hover_bg }
	if clay.UI(clay.ID(id))({
		layout = clay_button_layout(),
		backgroundColor = current_bg,
		cornerRadius = clay.CornerRadiusAll(CLAY_RADIUS_FRAC_BTN),
	}) {
		clay_body_text(label, color = CLAY_TEXT_PRIMARY)
	}
}

declare_button_default :: proc(id: string, label: string) {
	declare_button(id, label, CLAY_BTN_DEFAULT, CLAY_BTN_DEFAULT_HOVER)
}

declare_button_danger :: proc(id: string, label: string) {
	declare_button(id, label, CLAY_BTN_DANGER, CLAY_BTN_DANGER_HOVER)
}

declare_button_soft :: proc(id: string, label: string) {
	declare_button(id, label, CLAY_BTN_SOFT, CLAY_BTN_SOFT_HOVER)
}

declare_button_primary :: proc(id: string, label: string) {
	declare_button(id, label, CLAY_ACCENT, CLAY_ACCENT_HOVER)
}

declare_button_small :: proc(id: string, label: string) {
	if clay.UI(clay.ID(id))({
		layout = {sizing = {width = clay.SizingFit({min = 40, max = 24}), height = clay.SizingFixed(24)}, padding = {top = 2, right = 8, bottom = 2, left = 8}, childAlignment = {x = .Center, y = .Center}},
		backgroundColor = CLAY_BTN_DEFAULT,
		cornerRadius = clay.CornerRadiusAll(CLAY_RADIUS_SM),
	}) {
		clay.Text(label, {fontId = CLAY_FONT_BODY, fontSize = CLAY_FONT_SIZE_SM, textColor = CLAY_TEXT_SECONDARY})
	}
}

declare_button_recommended :: proc(id: string, label: string) {
	if clay.UI(clay.ID(id))({
		layout = clay_button_layout(),
		backgroundColor = CLAY_ACCENT,
		cornerRadius = clay.CornerRadiusAll(CLAY_RADIUS_FRAC_BTN),
		border = {color = CLAY_ACCENT_GLOW, width = clay.BorderOutside(2)},
	}) {
		clay_body_text(label, color = CLAY_TEXT_BRIGHT)
	}
}

declare_status_badge :: proc(id: string, label: string, ok: bool) {
	badge_color: clay.Color = CLAY_ERROR
	if ok { badge_color = CLAY_SUCCESS }
	badge_bg: clay.Color = CLAY_ERROR_DIM
	if ok { badge_bg = CLAY_SUCCESS_DIM }
	if clay.UI(clay.ID(id))({
		layout = {sizing = {width = clay.SizingFit({min = 70, max = 28}), height = clay.SizingFixed(26)}, padding = {top = 2, right = 8, bottom = 2, left = 8}, childAlignment = {x = .Center, y = .Center}},
		backgroundColor = badge_bg,
		cornerRadius = clay.CornerRadiusAll(CLAY_RADIUS_MD),
		border = {color = badge_color, width = clay.BorderOutside(1)},
	}) {
		clay.Text(label, {fontId = CLAY_FONT_BODY, fontSize = CLAY_FONT_SIZE_SM, textColor = badge_color})
	}
}


// ─── Stat Chip (Clay) ──────────────────────────────────────────────
// ─── Stat Chip (Clay) ──────────────────────────────────────────────
declare_stat_chip :: proc(id: string, label: string, value: int) {
	value_text := fmt.tprintf("%d", value)
	if clay.UI(clay.ID(id))({
		layout = {sizing = {width = clay.SizingFixed(90), height = clay.SizingFixed(34)}, padding = {top = 4, right = 8, bottom = 4, left = 8}, childAlignment = {x = .Center, y = .Center}},
		backgroundColor = clay.Color{40, 40, 55, 255},
		cornerRadius = clay.CornerRadiusAll(CLAY_RADIUS_SM),
		border = {color = clay.Color{55, 55, 75, 255}, width = clay.BorderOutside(1)},
	}) {
		clay_muted_text(label)
		clay_body_text(value_text, color = CLAY_TEXT_PRIMARY, size = CLAY_FONT_SIZE_SM)
	}
}

