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

type TaskActiveReceiveView struct {
	BaseformView
}

func (this *TaskActiveReceiveView) CreateView(t *model.TestCase) fyne.CanvasObject {
	id := widget.NewEntry()
	tagSelect := getTaskTagSelect()

	this.form.AppendItem(widget.NewFormItem(common.APP_TESTCASE_FORM_TASK_OID, id))
	this.form.AppendItem(widget.NewFormItem(common.APP_TESTCASE_FORM_TASKTAG, tagSelect))

	this.form.OnSubmit = func() {
		if err := service.GetPttService().SendToClient(t.MainType, t.SubType, &pb.TaskActiveReceiveReq{
			Id:      cast.ToInt32(id.Text),
			TaskTag: cast.ToInt32(tagSelect.Selected),
		}); err != nil {
			logrus.Error(err)
		}

	}
	return this.form
}
