package formview

import (
	"go_dreamfactory/cmd/v2/lib/common"
	"go_dreamfactory/cmd/v2/model"
	"go_dreamfactory/cmd/v2/service"
	"go_dreamfactory/pb"

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

type HeroStrengthenUpStarView struct {
	BaseformView
}

func (this *HeroStrengthenUpStarView) CreateView(t *model.TestCase) fyne.CanvasObject {
	heroObjID := widget.NewEntry()
	//HeroRace
	heroRaceId := widget.NewEntry()
	heroRaceId.PlaceHolder = common.APP_TESTCASE_FORM_LABEL_OID
	heroRaceAmount := widget.NewEntry()
	heroRaceAmount.PlaceHolder = common.APP_TESTCASE_FORM_LABEL_NUM

	heroRaceId2 := widget.NewEntry()
	heroRaceId2.PlaceHolder = common.APP_TESTCASE_OPTIONS
	heroRaceAmount2 := widget.NewEntry()
	heroRaceAmount2.PlaceHolder = common.APP_TESTCASE_OPTIONS

	//Hero
	heroId := widget.NewEntry()
	heroId.PlaceHolder = common.APP_TESTCASE_FORM_LABEL_OID
	heroAmount := widget.NewEntry()
	heroAmount.PlaceHolder = common.APP_TESTCASE_FORM_LABEL_NUM

	heroId2 := widget.NewEntry()
	heroId2.PlaceHolder = common.APP_TESTCASE_OPTIONS
	heroAmount2 := widget.NewEntry()
	heroAmount2.PlaceHolder = common.APP_TESTCASE_OPTIONS

	heroRace := container.NewGridWithColumns(2, heroRaceId, heroRaceAmount, heroRaceId2, heroRaceAmount2)
	hero := container.NewGridWithColumns(2, heroId, heroAmount, heroId2, heroAmount2)

	this.form.AppendItem(widget.NewFormItem(common.APP_TESTCASE_FORM_LABEL_HEROOBJID, heroObjID))
	this.form.AppendItem(widget.NewFormItem(common.APP_TESTCASE_FORM_LABEL_RACECARD, heroRace))
	this.form.AppendItem(widget.NewFormItem(common.APP_TESTCASE_FORM_LABEL_CARD, hero))

	this.form.OnSubmit = func() {
		if err := service.GetPttService().SendToClient(t.MainType, t.SubType,
			&pb.HeroStrengthenUpStarReq{
				HeroObjID: heroObjID.Text,
			}); err != nil {
			logrus.Error(err)
			return
		}

	}
	return this.form
}
