package formview

import (
	"go_dreamfactory/cmd/v2/model"
	"go_dreamfactory/cmd/v2/service"
	// "go_dreamfactory/comm"
	// "go_dreamfactory/modules/sociaty"
	"go_dreamfactory/pb"

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

type SociatyCreateView struct {
	BaseformView
}

func (app *SociatyCreateView) CreateView(t *model.TestCase) fyne.CanvasObject {
	sociatyName := widget.NewEntry()
	notice := widget.NewMultiLineEntry()
	icon := widget.NewEntry()

	isApplyCheck := widget.NewCheck("审批", nil)
	applyLv := widget.NewEntry()
	applyLv.Text = "1" //默认

	app.form.AppendItem(widget.NewFormItem("公会名称", sociatyName))
	app.form.AppendItem(widget.NewFormItem("公告", notice))
	app.form.AppendItem(widget.NewFormItem("图标", icon))
	app.form.AppendItem(widget.NewFormItem("审批", isApplyCheck))
	app.form.AppendItem(widget.NewFormItem("入会等级", applyLv))

	app.form.OnSubmit = func() {
		req := &pb.SociatyCreateReq{
			Name:         sociatyName.Text,
			Icon:         icon.Text,
			Notice:       notice.Text,
			IsApplyCheck: isApplyCheck.Checked,
			ApplyLv:      cast.ToInt32(applyLv.Text),
		}
		if err := service.GetPttService().SendToClient(
			"sociaty",
			"create",
			req,
		); err != nil {
			logrus.Error(err)
		}
		logrus.WithFields(logrus.Fields{"mainType": string("sociaty"), "subType": "", "params": req}).Info("创建工会")
	}
	app.form.SubmitText = "创建"
	return app.form
}
