package catalog

import "slices"

type Example struct {
	Title       string
	Description string
	Preview     anyComponent
	Snippet     string
}

type Page struct {
	Slug        string
	Title       string
	Description string
	Examples    []Example
}

func Pages() []Page {
	return []Page{
		{
			Slug:        "tokens",
			Title:       "Tokens",
			Description: "Semantic colors and status roles used by the Go design system.",
			Examples:    tokenExamples(),
		},
		{
			Slug:        "buttons",
			Title:       "Buttons",
			Description: "Primary, secondary, ghost, and destructive actions built from shared templ primitives.",
			Examples:    buttonExamples(),
		},
		{
			Slug:        "badges",
			Title:       "Badges",
			Description: "Semantic status labels for todo, in-progress, success, and destructive states.",
			Examples:    badgeExamples(),
		},
		{
			Slug:        "icon-buttons",
			Title:       "Icon Buttons",
			Description: "Compact icon-only actions for destructive and neutral controls.",
			Examples:    iconButtonExamples(),
		},
		{
			Slug:        "inputs",
			Title:       "Inputs",
			Description: "Shared single-line and multiline text controls.",
			Examples:    inputExamples(),
		},
		{
			Slug:        "selects",
			Title:       "Selects",
			Description: "Single and multi-value select controls with a shared server-rendered shell.",
			Examples:    selectExamples(),
		},
		{
			Slug:        "form-fields",
			Title:       "Form Fields",
			Description: "Labeled controls with optional hint and error messaging.",
			Examples:    formFieldExamples(),
		},
		{
			Slug:        "modals",
			Title:       "Modals",
			Description: "Shared modal shell for focused create, edit, and confirm flows.",
			Examples:    modalExamples(),
		},
		{
			Slug:        "spacing",
			Title:       "Spacing",
			Description: "Fixed horizontal and vertical spacer primitives for composing gaps between UI components.",
			Examples:    spacingExamples(),
		},
		{
			Slug:        "tables",
			Title:       "Tables",
			Description: "Shared table shell for server-rendered list views.",
			Examples:    tableExamples(),
		},
		{
			Slug:        "empty-states",
			Title:       "Empty States",
			Description: "Centered fallback messaging with optional icon and action.",
			Examples:    emptyStateExamples(),
		},
		{
			Slug:        "cards",
			Title:       "Cards",
			Description: "Reusable bordered surfaces with optional header, body, and footer regions.",
			Examples:    cardExamples(),
		},
	}
}

func FindPage(slug string) (Page, bool) {
	index := slices.IndexFunc(Pages(), func(page Page) bool {
		return page.Slug == slug
	})
	if index == -1 {
		return Page{}, false
	}
	return Pages()[index], true
}

func catalogNavLinkClass(active bool) string {
	if active {
		return "catalog-nav-link is-active"
	}
	return "catalog-nav-link"
}
