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/widget"
	"github.com/sirupsen/logrus"
)

type EquipUpDownView struct {
	BaseformView
}

func (this *EquipUpDownView) CreateView(t *model.TestCase) fyne.CanvasObject {
	heroObjID := widget.NewEntry()
	heroObjID.PlaceHolder = "英雄ID"
	this.form.AppendItem(widget.NewFormItem(common.APP_TESTCASE_FORM_LABEL_HEROOBJID, heroObjID))

	equipId1 := widget.NewEntry()
	equipId1.PlaceHolder = "装备ID1"
	this.form.AppendItem(widget.NewFormItem("装备ID1", equipId1))

	equipId2 := widget.NewEntry()
	equipId2.PlaceHolder = "装备ID2"
	this.form.AppendItem(widget.NewFormItem("装备ID2", equipId2))

	equipId3 := widget.NewEntry()
	equipId3.PlaceHolder = "装备ID3"
	this.form.AppendItem(widget.NewFormItem("装备ID3", equipId3))

	equipId4 := widget.NewEntry()
	equipId4.PlaceHolder = "装备ID4"
	this.form.AppendItem(widget.NewFormItem("装备ID5", equipId4))

	equipId5 := widget.NewEntry()
	equipId5.PlaceHolder = "装备ID5"
	this.form.AppendItem(widget.NewFormItem("装备ID5", equipId5))

	equipIds := []string{
		equipId1.Text, equipId2.Text, equipId3.Text, equipId4.Text, equipId5.Text,
	}

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

	return this.form
}
