Files
ps_shop/templates/layout_helpers.go
T
2026-05-12 11:25:32 +02:00

99 lines
2.3 KiB
Go

package templates
import (
"sort"
"strconv"
"strings"
pscatalog "git.ma-al.com/goc_marek/ps_shop/internal/prestashop/catalog"
pscookie "git.ma-al.com/goc_marek/ps_shop/internal/prestashop/cookie"
)
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)
}
func sessionCookieLines(session *pscookie.SessionContext) []string {
if session == nil || len(session.Values) == 0 {
return nil
}
keys := make([]string, 0, len(session.Values))
for key := range session.Values {
keys = append(keys, key)
}
sort.Strings(keys)
lines := make([]string, 0, len(keys))
for _, key := range keys {
lines = append(lines, key+"="+session.Values[key])
}
return lines
}