package rybkaos

import (
	"embed"
	_ "embed"
	"net/http"
)

//go:embed main.js
var mainJS []byte

//go:embed main.css
var mainCSS []byte

//go:embed home.html
var homeHTML []byte

//go:embed icons
var icons embed.FS

type Server struct{}

func (s *Server) Handler() http.Handler {
	mux := http.NewServeMux()
	mux.HandleFunc("/", s.handleHomeView)
	mux.HandleFunc("/main.js", s.handleMainJS)
	mux.HandleFunc("/main.css", s.handleMainCSS)
	mux.Handle("/icons/", http.FileServer(http.FS(icons)))
	return mux
}

func (s *Server) handleHomeView(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/html")
	w.Write(homeHTML)
}

func (s *Server) handleMainJS(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/javascript")
	w.Write(mainJS)
}

func (s *Server) handleMainCSS(w http.ResponseWriter, r *http.Request) {
	w.Header().Set("Content-Type", "text/css")
	w.Write(mainCSS)
}
