package static

import (
	"embed"
	"log"
	"net/http"
	"strings"

	"github.com/labstack/echo/v4"
)

// GetStatic returns static file content
func GetStatic(staticfiles *embed.FS, c echo.Context) (err error) {
	name := c.Param("*")
	content, err := staticfiles.ReadFile(name)
	if err != nil {
		log.Println(err)
	}

	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, string(content))
}

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