package handler

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

func MainPage(pool *pgxpool.Pool) gin.HandlerFunc {
	return func(c *gin.Context) {
		c.HTML(http.StatusAccepted, "index.html", database.DbMainpage(pool))
	}
}

func UploadName(pool *pgxpool.Pool) gin.HandlerFunc {
	return func(c *gin.Context) {
		selectedID := c.PostForm("names")
		washID := c.PostForm("washid")

		database.UploadName(pool, selectedID, washID)
		c.Redirect(302, "/")
	}
}

func Credits() gin.HandlerFunc {
	return func(c *gin.Context) {
		c.HTML(http.StatusAccepted, "credits.html", gin.H{"version":"1.1"})
	}
}
