//go:build windows

package main

import (
	"embed"
	"image/png"
	"log"

	"github.com/tailscale/walk"
)

//go:embed logos/*.png
var iconDir embed.FS

var trayIcons []*walk.Icon

type trayIconState int

const (
	iconLogo trayIconState = iota
	iconDisconnected
	iconConnected
	iconExitNode
	iconAsExitNode
	iconIssue
	iconConnecting1
	iconConnecting2
)

var trayIconName = map[trayIconState]string{
	iconLogo:         "logo",
	iconDisconnected: "disconn",
	iconConnected:    "conn",
	iconExitNode:     "exit",
	iconAsExitNode:   "asexit",
	iconIssue:        "issue",
	iconConnecting1:  "ing1",
	iconConnecting2:  "ing2",
}

func (ico trayIconState) load() (*walk.Icon, error) {
	file, err := iconDir.Open("logos/" + trayIconName[ico] + ".png")
	if err != nil {
		return nil, err
	}
	defer file.Close()

	iconImage, err := png.Decode(file)
	if err != nil {
		return nil, err
	}
	return walk.NewIconFromImage(iconImage)
}

func init() {
	trayIcons = make([]*walk.Icon, len(trayIconName))
	for i := range trayIconName {
		icon, err := trayIconState(i).load()
		if err != nil {
			log.Fatal(err)
		}
		trayIcons[i] = icon
	}
}
