package handlers

import "net/http"

// Server-rendered page endpoints for the Phase E Deadlines UI.
// HTML is generated at build time by frontend/build.ts; the per-page
// client TS bundles call /api/deadlines* to populate the DOM and read
// id/project_id from window.location.

// handleDeadlinesListRedirect 301-redirects the legacy /deadlines list URL
// to the canonical /events?type=deadline (t-paliad-115). Detail page
// /deadlines/{id} stays type-specific. Drop this redirect once we're
// confident no caches / bookmarks / external links still hit the old URL.
//
// Preserves the incoming query string so filter params (e.g. status=this_week
// from the dashboard summary cards) survive the redirect.
func handleDeadlinesListRedirect(w http.ResponseWriter, r *http.Request) {
	target := "/events?type=deadline"
	if r.URL.RawQuery != "" {
		target += "&" + r.URL.RawQuery
	}
	http.Redirect(w, r, target, http.StatusMovedPermanently)
}

func handleDeadlinesNewPage(w http.ResponseWriter, r *http.Request) {
	http.ServeFile(w, r, "dist/deadlines-new.html")
}

func handleDeadlinesDetailPage(w http.ResponseWriter, r *http.Request) {
	http.ServeFile(w, r, "dist/deadlines-detail.html")
}

// handleDeadlinesCalendarPage 301-redirects the legacy standalone
// calendar route to the canonical /events Kalender tab (t-paliad-224 /
// m/paliad#55). The standalone page was orphaned in navigation since
// t-paliad-110 — Sidebar/BottomNav already point at /events?type=…, and
// the canonical calendar lives inside that page's view chip. The
// redirect preserves bookmarks and external links without a duplicate
// rendering pipeline.
func handleDeadlinesCalendarPage(w http.ResponseWriter, r *http.Request) {
	http.Redirect(w, r, "/events?type=deadline&view=calendar", http.StatusMovedPermanently)
}
