package formview

import (
	"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"
	"github.com/spf13/cast"
)

// 修改形象
type UserModifyfigureView struct {
	BaseformView
}

func (this *UserModifyfigureView) CreateView(t *model.TestCase) fyne.CanvasObject {
	figureId := widget.NewEntry()
	this.form.AppendItem(widget.NewFormItem("形象", figureId))

	this.form.OnSubmit = func() {
		if err := service.GetPttService().SendToClient(
			t.MainType,
			t.SubType,
			&pb.UserModifyfigureReq{FigureId: cast.ToInt32(figureId.Text)},
		); err != nil {
			logrus.Error(err)
			return
		}
	}

	return this.form
}
