package spindles

import (
	"log/slog"
	"net/http"

	"github.com/go-chi/chi/v5"
	"tangled.org/core/appview/config"
	"tangled.org/core/appview/db"
	"tangled.org/core/appview/middleware"
	"tangled.org/core/appview/oauth"
	"tangled.org/core/appview/pages"
	"tangled.org/core/idresolver"
	"tangled.org/core/rbac"
)

type Spindles struct {
	Db         *db.DB
	OAuth      *oauth.OAuth
	Pages      *pages.Pages
	Config     *config.Config
	Enforcer   *rbac.Enforcer
	IdResolver *idresolver.Resolver
	Logger     *slog.Logger
}

func (s *Spindles) Router() http.Handler {
	r := chi.NewRouter()

	r.With(middleware.AuthMiddleware(s.OAuth)).Get("/", s.spindles)

	return r
}

func (s *Spindles) spindles(w http.ResponseWriter, r *http.Request) {
	s.Pages.Spindles(w, pages.SpindlesParams{
		BaseParams: pages.BaseParamsFromContext(r.Context()),
		Tab:        "spindles",
	})
}
