package main

import (
	"dequoter/icon_asset"
	"embed"
	"log"
	"runtime"

	rt "github.com/wailsapp/wails/v2/pkg/runtime"

	"github.com/wailsapp/wails/v2"
	"github.com/wailsapp/wails/v2/pkg/menu"
	"github.com/wailsapp/wails/v2/pkg/menu/keys"
	"github.com/wailsapp/wails/v2/pkg/options"
	"github.com/wailsapp/wails/v2/pkg/options/assetserver"
	"github.com/wailsapp/wails/v2/pkg/options/mac"
)

var (
	VersionNumber = "development"
)

//go:embed all:frontend/dist
var assets embed.FS

func main() {
	store, err := NewStore()
	if err != nil {
		log.Fatal(err)
	}

	// Create an instance of the app structure
	app := NewApp(store)

	appMenu := menu.NewMenu()
	if runtime.GOOS == "darwin" {
		appMenu.Append(menu.AppMenu()) // On macOS platform, this must be done right after `NewMenu()`
	}
	fileMenu := appMenu.AddSubmenu("File")
	fileMenu.AddText("Quit", keys.CmdOrCtrl("q"), func(_ *menu.CallbackData) {
		// `rt` is an alias of "github.com/wailsapp/wails/v2/pkg/runtime" to prevent collision with standard package
		rt.Quit(app.ctx)
	})

	if runtime.GOOS == "darwin" {
		appMenu.Append(menu.EditMenu())
		appMenu.Append(menu.WindowMenu())
	}

	// Create application with options
	err = wails.Run(&options.App{
		Title:  "Dequoter",
		Width:  800,
		Height: 600,
		AssetServer: &assetserver.Options{
			Assets: assets,
		},
		BackgroundColour: &options.RGBA{R: 27, G: 38, B: 54, A: 1},
		OnStartup:        app.startup,
		Bind: []interface{}{
			app,
		},
		EnableDefaultContextMenu: true,
		Menu:                     appMenu,
		Mac: &mac.Options{
			About: &mac.AboutInfo{
				Title:   "Dequoter",
				Message: "© 2025-2026 Leon Mika\nVersion: " + VersionNumber,
				Icon:    icon_asset.AppIcon,
			},
		},
	})

	if err != nil {
		println("Error:", err.Error())
	}
}
