package formview

import (
	"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/dialog"
	"fyne.io/fyne/v2/widget"
	"github.com/sirupsen/logrus"
	"github.com/spf13/cast"
)

type PracticeView struct {
	BaseformView
}

func (this *PracticeView) CreateView(t *model.TestCase) fyne.CanvasObject {

	//英雄ID
	heroId := widget.NewEntry()
	//位置ID
	index := widget.NewEntry()
	form := widget.NewForm(
		widget.NewFormItem("位置", index),
		widget.NewFormItem("英雄", heroId),
	)

	form.OnSubmit = func() {
		if err := service.GetPttService().SendToClient(
			t.MainType,
			"practice",
			&pb.PracticePracticeReq{
				Index: cast.ToInt32(index.Text),
				Hero:  heroId.Text,
			},
		); err != nil {
			logrus.Error(err)
			return
		}
	}
	liangongBtn := widget.NewButton("练功", func() {
		paiWin := dialog.NewCustom("练功", "关闭", form, this.w)
		paiWin.Resize(fyne.NewSize(600, 300))
		paiWin.Show()
	})
	layout := container.NewBorder(container.NewHBox(liangongBtn), nil, nil, nil)
	return layout
}
