package main

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

	"github.com/zserge/lorca"
)

//go:embed templates
var templatesHTML embed.FS

//go:embed static
var staticFiles embed.FS

func main() {
	log.SetFlags(log.Lshortfile)

	/* Web Server */
	http.Handle("/static/", http.FileServer(http.FS(staticFiles)))
	http.Handle("/favicon.ico", http.RedirectHandler("/static/favicon.ico", http.StatusMovedPermanently))
	http.HandleFunc("/", GetHome)

	// Start in separate goroutine
	go func() {
		log.Fatal(http.ListenAndServe(":3000", nil))
	}()

	/* GUI */
	args := []string{}
	if runtime.GOOS == "linux" {
		args = append(args, "--class=Lorca")
	}
	ui, err := lorca.New("http://localhost:3000", "", 1000, 800, args...)
	if err != nil {
		log.Fatal(err)
	}
	defer ui.Close()
	<-ui.Done()
}
