package main

import (
	"net/http"
	"strings"
)

func HomePage(w http.ResponseWriter, r *http.Request) {
	cfg := LoadConfig()
	var items strings.Builder
	for _, n := range visibleNavItems(cfg.BetaToolsEnabled) {
		if n.Path == "/" {
			continue
		}
		badge := ""
		if n.Beta {
			badge = ` <span class="beta-pill">Beta</span>`
		}
		items.WriteString(`<button type="button" class="home-tool" data-path="` + n.Path + `"><span class="home-tool-title">` + n.Label + badge + `</span><span class="home-tool-desc">` + n.Description + `</span></button>`)
	}

	body := `
<header class="tool-header">
  <h2 class="tool-title">HPL Toolbox</h2>
  <p class="tool-description">Standalone build. Pick a tool to open.</p>
</header>
<div class="home-tools">
` + items.String() + `
</div>
<style>
  .home-tools { display:flex; flex-direction:column; gap:8px; max-width:620px; }
  .home-tool {
    display:block;
    width:100%;
    min-height:52px;
    padding:9px 11px;
    color:#ddd;
    text-align:left;
    background:#2a2d2e;
    border:1px solid #333;
    border-radius:5px;
    cursor:pointer;
    font:inherit;
  }
  .home-tool:hover { background:#33373a; border-color:#007fd4; }
  .home-tool-title { display:flex; align-items:center; justify-content:space-between; gap:8px; font-size:12px; font-weight:600; }
  .home-tool-desc { display:block; margin-top:4px; color:#a7a7a7; font-size:11px; line-height:1.35; }
</style>
`
	w.Header().Set("Content-Type", "text/html; charset=utf-8")
	_, _ = w.Write([]byte(Page("/", "Home", body)))
}
