package ui

import (
	"go_dreamfactory/cmd/v2/lib/common"
	"go_dreamfactory/cmd/v2/service"
	"go_dreamfactory/cmd/v2/service/observer"

	them "go_dreamfactory/cmd/v2/theme"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/canvas"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/driver/desktop"
	"fyne.io/fyne/v2/theme"
	"fyne.io/fyne/v2/widget"
)

type appWelcome struct {
	appAdapter
}

func (a *appWelcome) LazyInit(service service.PttService, obs observer.Observer) error {
	logo := canvas.NewImageFromResource(them.ResourceLogoPng)
	logo.FillMode = canvas.ImageFillContain
	logo.SetMinSize(fyne.NewSize(362*0.8, 192*0.8))

	a.tabItem = container.NewTabItemWithIcon(common.TOOLBAR_WEL, theme.InfoIcon(), nil)

	wel := widget.NewRichTextFromMarkdown("# " + common.WELCOME_MSG)
	for i := range wel.Segments {
		if seg, ok := wel.Segments[i].(*widget.TextSegment); ok {
			seg.Style.Alignment = fyne.TextAlignCenter
		}
	}

	a.tabItem.Content = container.NewCenter(
		container.NewVBox(
			wel,
			logo,
			// shortCuts,
		))
	return nil
}

func (a *appWelcome) GetAppName() string {
	return common.TOOLBAR_WEL
}

func (a *appWelcome) OpenDefault() string {
	return common.TOOLBAR_WEL
}

func (a *appWelcome) ShortCut() fyne.Shortcut {
	return &desktop.CustomShortcut{KeyName: fyne.Key1, Modifier: fyne.KeyModifierAlt}
}

func (a *appWelcome) Icon() fyne.Resource {
	return theme.InfoIcon()
}

func (a *appWelcome) OnClose() bool {
	return false
}
