package handlers

import (
	"net/http"

	"erp_system/internal/models"
)

func (h *Handler) Dashboard(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{}{
		"Title":             "Dashboard",
		"Username":          h.getUsername(r),
		"ActivePage":        "dashboard",
		"CustomerCount":     models.CustomerCount(h.DB),
		"OpenOrderCount":    models.OrderCountByStatus(h.DB, "draft") + models.OrderCountByStatus(h.DB, "confirmed"),
		"PendingInvoices":   models.InvoiceCountByStatus(h.DB, "pending"),
		"OutstandingAmount": models.InvoiceTotalOutstanding(h.DB),
		"RevenueThisMonth":  models.RevenueThisMonth(h.DB),
		"FulfilledOrders":   models.OrderCountByStatus(h.DB, "fulfilled"),
	}

	h.render(w, []string{"layout.html", "dashboard.html"}, data)
}
