package pkg

import (
	"encoding/json"
	"net/http"
)

const (
	HxLocation           = "HX-Location"
	HxRefresh            = "HX-Refresh"
	HxRequest            = "HX-Request"
	HxTrigger            = "HX-Trigger"
	HxTriggerAfterSettle = "HX-Trigger-After-Settle"
)

type HTMxLocation struct {
	Path   string `json:"path"`
	Target string `json:"target"`
}

func IsHTMxRequest(r *http.Request) bool {
	return r.Header.Get(HxRequest) == "true"
}

func MustMarshalHTMxLocation(location *HTMxLocation) string {
	data, err := json.Marshal(location)
	if err != nil {
		panic(err)
	}
	return string(data)
}
