package controllers

import (
	"github.com/unrolled/render"
	"log"
	"moretcgshop/app/models"
	"net/http"
)

func (server *Server) Home(w http.ResponseWriter, r *http.Request) {
	renderer := render.New(render.Options{
		Layout:     "layout",
		Extensions: []string{".html", ".tmpl"},
	})

	sectionen, err := models.GetSection(server.DB)

	if err != nil {
		log.Fatal(err.Error())
	}

	user := server.CurrentUser(w, r)

	_ = renderer.HTML(w, http.StatusOK, "home", map[string]interface{}{
		"user":      user,
		"sectionen": sectionen,
	})
}
