// ui_repo_trend.go — htmx fragment endpoint for the repo-page
// trend chart. Returns just the chart partial wrapped in
// <div id="repo-trend-chart"> so htmx can outerHTML-swap it.
//
//	GET /hosts/{id}/repo/trend?range=30d|90d|1y
package http

import (
	stdhttp "net/http"

	"github.com/go-chi/chi/v5"
)

func (s *Server) handleUIRepoTrend(w stdhttp.ResponseWriter, r *stdhttp.Request) {
	u := s.requireUIUser(w, r)
	if u == nil {
		return
	}
	hostID := chi.URLParam(r, "id")
	view := s.baseView(r, u)
	view.Page = s.buildRepoTrendView(r.Context(), hostID, r.URL.Query().Get("range"))
	if err := s.deps.UI.RenderPartial(w, "repo_size_chart", view); err != nil {
		stdhttp.Error(w, "internal", stdhttp.StatusInternalServerError)
	}
}
