package handlers

import (
	"html/template"
	"mc-monitor/middleware"
	"mc-monitor/models"
	"net/http"
)

type DashboardData struct {
	Username string
	Servers  []models.ServerInfo
}

func IndexHandler(w http.ResponseWriter, r *http.Request) {
	if _, ok := middleware.GetSession(r); ok {
		http.Redirect(w, r, "/dashboard", http.StatusSeeOther)
		return
	}

	tmpl := template.Must(template.ParseFiles("templates/index.html"))
	tmpl.Execute(w, nil)
}

func DashboardHandler(w http.ResponseWriter, r *http.Request) {
	session, _ := middleware.GetSession(r)
	data := DashboardData{
		Username: session.Username,
		Servers:  models.GetServers(),
	}
	
	tmpl := template.Must(template.ParseFiles("templates/dashboard.html"))
	tmpl.Execute(w, data)
}
