package handler

import (
	"github.com/gin-gonic/gin"
	"github.com/jackc/pgx/v4/pgxpool"
	"net/http"
	"trikotwaschliste/database"
	"trikotwaschliste/logbuffer"
)

func AdminMainPage(pool *pgxpool.Pool) gin.HandlerFunc {
	return func(c *gin.Context) {
		c.HTML(http.StatusAccepted, "adminindex.html", database.DbAdminMainpage(pool))
	}
}

func ChangeName(pool *pgxpool.Pool) gin.HandlerFunc {
	return func(c *gin.Context) {
		selectedID := c.PostForm("names")
		personID := c.PostForm("personid")

		database.ChangeName(pool, selectedID, personID)
		c.Redirect(302, "/admin")
	}
}

func Logs(queue *logbuffer.Queue) gin.HandlerFunc {
	return func(c *gin.Context) {
		c.HTML(http.StatusAccepted, "adminlogs.html", database.Logs(queue))
	}
}