package static

import (
	"net/http"
	"strings"

	"github.com/gobuffalo/packr/v2"
	"github.com/labstack/echo/v4"
)

// GetStatic returns static file content
func GetStatic(box *packr.Box, c echo.Context) (err error) {
	name := c.Param("*")
	cnt, _ := box.FindString(name)

	if strings.HasSuffix(name, ".js") {
		c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScript)
	} else if strings.HasSuffix(name, ".css") {
		c.Response().Header().Set(echo.HeaderContentType, "text/css")
	}
	return c.String(http.StatusOK, cnt)
}

// Static defines static file
type Static struct {
	Name    string
	Content string
}
