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.HandleFunc("/", GetHome) // Redirects to /search if auth'd

	/* Start Web Server */
	go func() {
		log.Println("Server is running!")
		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)
	}

	/* IMG */
	ui.Bind("img_open", ImgOpen)
	ui.Bind("img_read_item", ImgReadItem)

	defer ui.Close()
	<-ui.Done()
}
