package handlers

import (
	"html/template"
	"net/http"
)

type OryRedirectData struct {
	Title      string
	ActivePage string
	Flow       string
	Message    string
	Type       string
}

func OryRedirectHandler(tmpl *template.Template) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		flow := r.URL.Query().Get("flow")
		
		var message string
		var msgType string
		
		switch flow {
		case "login":
			message = "Successfully logged in!"
			msgType = "success"
		case "registration":
			message = "Account created successfully!"
			msgType = "success"
		case "settings":
			message = "Settings updated successfully!"
			msgType = "success"
		case "verification":
			message = "Email verified successfully!"
			msgType = "success"
		case "recovery":
			message = "Password recovered successfully!"
			msgType = "success"
		case "logout":
			message = "Successfully logged out!"
			msgType = "info"
		default:
			message = "Action completed successfully!"
			msgType = "success"
		}
		
		data := OryRedirectData{
			Title:      "Redirect",
			ActivePage: "",
			Flow:       flow,
			Message:    message,
			Type:       msgType,
		}
		
		if err := tmpl.ExecuteTemplate(w, "ory_redirect.tmpl", data); err != nil {
			http.Error(w, "Failed to render page", http.StatusInternalServerError)
		}
	}
}
