package resthome

import (
	"context"
	"io"
	"net/http"

	"git.schreifuchs.ch/schreifuchs/schreifuchs.ch/internal/components/page"
	"github.com/a-h/templ"
)

type Handler struct {
	http.Handler
	src pageService
	r   renderer
}

func New(renderer renderer, srv pageService) *Handler {
	mux := http.NewServeMux()
	h := &Handler{
		Handler: mux,
		src:     srv,
		r:       renderer,
	}

	mux.HandleFunc("GET /{$}", h.home)
	mux.HandleFunc("GET /{uid}", h.page)
	return h
}

type pageService interface {
	GetPages(ctx context.Context) ([]page.PageHeader, error)
	GetPage(ctx context.Context, uid string) (page.Page, error)
}
type renderer interface {
	Render(ctx context.Context, w io.Writer, r *http.Request, component templ.Component)
}
