package web

import (
	"html/template"
	"net/http"

	"pool-stats/database"
	"pool-stats/stats"
)

func (h database.Handlers) IndexHandler(w http.ResponseWriter, r *http.Request) {
	shareStats, err := stats.GetStats(h.DB)
	if err != nil {
		http.Error(w, "Failed to load stats", 500)
		return
	}

	tmpl := template.Must(template.ParseFiles("templates/index.html"))
	tmpl.Execute(w, shareStats)
}