package templates

import (
	"strconv"
	"strings"

	pscatalog "git.ma-al.com/goc_marek/ps_shop/internal/prestashop/catalog"
)

func menuListClass(depth int) string {
	if depth == 0 {
		return "flex min-w-0 flex-col gap-2 text-sm"
	}
	return "mt-2 space-y-2 border-l border-stone-200 pl-4 text-sm"
}

func menuLinkClass(depth int) string {
	if depth == 0 {
		return "inline-flex items-center gap-2 px-2 py-2 text-[1.02rem] font-medium text-stone-900 transition hover:text-amber-600"
	}
	return "inline-flex items-center gap-2 text-stone-700 transition hover:text-amber-600"
}

func menuItemClass(depth int, hasChildren bool) string {
	if depth == 0 && hasChildren {
		return "min-w-0"
	}
	return "min-w-0"
}

func desktopNavItemClass(hasChildren bool) string {
	if hasChildren {
		return "desktop-nav__entry desktop-nav__entry--has-children"
	}
	return "desktop-nav__entry"
}

func desktopNavLinkClass() string {
	return "desktop-nav__link"
}

func hasHeaderLocale(locale pscatalog.HeaderLocaleData) bool {
	return len(locale.Languages) > 0 || len(locale.Countries) > 0
}

func pageLanguage(locale pscatalog.HeaderLocaleData) string {
	code := strings.TrimSpace(locale.CurrentLanguage.Code)
	if code == "" {
		return "en"
	}
	return strings.ToLower(code)
}

func localeOptionClass(option pscatalog.LocaleOption, current pscatalog.LocaleOption) string {
	base := "locale-picker__item"
	if option.ID != 0 && option.ID == current.ID {
		return base + " locale-picker__item--active"
	}
	if option.Code != "" && option.Code == current.Code {
		return base + " locale-picker__item--active"
	}
	return base
}

func productInitial(name string) string {
	name = strings.TrimSpace(name)
	if name == "" {
		return "P"
	}
	return strings.ToUpper(name[:1])
}

func menuPanelID(id int64) string {
	if id <= 0 {
		return "mega-menu-panel"
	}
	return "mega-menu-panel-" + strconv.FormatInt(id, 10)
}
