package formview

import (
	"go_dreamfactory/cmd/v2/model"
	"go_dreamfactory/cmd/v2/service"
	"go_dreamfactory/pb"
	"strings"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/widget"
	"github.com/sirupsen/logrus"
)

type HeroInfoView struct {
	BaseformView
}

func (this *HeroInfoView) CreateView(t *model.TestCase) fyne.CanvasObject {
	uidEntry := widget.NewEntry()
	uidEntry.PlaceHolder = "玩家ID"

	heroIdEntry := widget.NewEntry()
	heroIdEntry.PlaceHolder = "英雄ObjID,多个用逗号分隔"

	this.form.AppendItem(widget.NewFormItem("UID", uidEntry))
	this.form.AppendItem(widget.NewFormItem("HeroObjID", heroIdEntry))

	heroIds := strings.Split(heroIdEntry.Text, ",")
	this.form.OnSubmit = func() {
		if err := service.GetPttService().SendToClient(
			t.MainType,
			t.SubType,
			&pb.HeroInfoReq{
				Uid:    uidEntry.Text,
				HeroId: heroIds,
			},
		); err != nil {
			logrus.Error(err)
			return
		}

	}
	return this.form
}
