package dev_handlers

import (
	breadcrumadmin "cpone/component/breadcrumbadmin"
	customtextfieldsearch "cpone/component/customtextfieldsearch"
	navbarmenu "cpone/component/navbar"
	"cpone/component/pagination"
	sidebaruserprofile "cpone/component/sidebar_user_profile"
	customtoastv2 "cpone/component/toastbootstrap"
	"cpone/models"
	"cpone/services"
	"cpone/utils"
	dev_mdgroupresultview "cpone/views/dev/mdgroupresult"
	"fmt"
	"strconv"
	"strings"

	"github.com/a-h/templ"
	"github.com/labstack/echo/v4"
	"go.uber.org/zap"
)

type MdGroupResultServices interface {
	GetListMdGroupResult(search string, currentPage int, rowPerPage int) ([]models.GroupResult, int, error)
	GetMdGroupResultByID(id string) (models.GroupResult, error)
	AddMdGroupResult(groupresultname string, groupresultflagpertest string, groupresultflagnonlab string, groupresultresumemcu string) (models.GroupResult, error)
	EditMdGroupResult(id string, groupresultname string, groupresultflagpertest string, groupresultflagnonlab string, groupresultresumemcu string) (models.GroupResult, error)
	DeleteMdGroupResult(id string) (models.GroupResult, error)
	GetMdGroupResultBreadcrumb(title string) (models.BreadCrumbV1, error)
	GetMdGroupResultResumeMcu() ([]models.GroupResultResumeMcu, error)
}

func NewMdGroupResultHandler(us MdGroupResultServices) *MdGroupResultHandler {
	return &MdGroupResultHandler{
		MdGroupResultServices: us,
	}
}

type MdGroupResultHandler struct {
	MdGroupResultServices MdGroupResultServices
}

// INITIAL
func (lh *MdGroupResultHandler) HandleShowMdGroupResultScreen(c echo.Context) error {
	logger, _ := zap.NewProduction()
	//get sidebarmenu
	tableID := utils.GenerateRandomID("tablebody")
	paginationID := utils.GenerateRandomID("paginationid")
	searchID := utils.GenerateRandomID("searchid")
	dialogAddID := utils.GenerateRandomID("dialogaddID")
	dialogAddBodyID := utils.GenerateRandomID("dialogaddbodyID")
	dialogEditID := utils.GenerateRandomID("dialogEditID")
	dialogEditBodyID := utils.GenerateRandomID("dialogEditbodyID")
	dialogDeleteID := utils.GenerateRandomID("dialogDeleteID")
	dialogDeleteBodyID := utils.GenerateRandomID("dialogDeletebodyID")
	dataMenu, err := services.GetMenu()
	fmt.Println(dataMenu)
	fmt.Println(err)
	if err != nil {
		fmt.Println(dataMenu)
		return err
	}

	//get user login
	dataUser, err := services.GetUserLogin()
	fmt.Println(dataUser)
	fmt.Println(err)
	if err != nil {
		fmt.Println(dataUser)
		return err
	}
	defer logger.Sync()
	logger.Info("LOAD USER DEV",
		zap.Any("data", dataUser),
	)

	title := "Master Group Result"

	dataBreadCrumb, err := lh.MdGroupResultServices.GetMdGroupResultBreadcrumb(title)
	fmt.Println(dataBreadCrumb)
	fmt.Println(err)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR BREADCRUMB DEV",
			zap.Any("error", err),
		)
		fmt.Println(dataBreadCrumb)
		return err
	}

	defer logger.Sync()
	logger.Info("LOAD BREADCRUMB DEV",
		zap.Any("data", dataBreadCrumb),
	)
	//Breadcrumb component
	breadcrumbComponent := breadcrumadmin.MainBreadcrumbAdminV1(dataBreadCrumb)
	// navbar menu
	navbarmenuComponent := navbarmenu.NavbarMenu(dataMenu)

	// navbar user
	navbaruserComponent := navbarmenu.Navbar(dataUser)

	// sidebar
	sidebaruserprofileComponent := sidebaruserprofile.Navbaruserprofile(dataUser)

	//Table component
	dataGroupResult, totalPage, err := lh.MdGroupResultServices.GetListMdGroupResult("", 1, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET GROUP RESULT",
			zap.Any("error", err),
		)
		fmt.Println(dataGroupResult)
		return err
	}

	tableComponent := dev_mdgroupresultview.TableGroupResult(dataGroupResult,
		tableID,
		"/dev/md/groupresultv2/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/groupresultv2/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
	)

	//filter user group component
	usergroupFilterComponent := customtextfieldsearch.MainCustomTextFieldSearchV3(searchID,
		"search",
		"Cari Group Result Name / Result Resume MCU",
		"text",
		"/dev/md/groupresultv2/filter",
		"input changed delay:500ms, search",
		"#"+paginationID, "#loadingcontent", "", "outerHTML", "#tableID, #paginationID, #searchID,#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		dev_mdgroupresultview.BeforeRequestContentMdGroupResult(),
		dev_mdgroupresultview.AfterRequestContentMdGroupResult())
	//Pagination
	userGroupPaginationComponent := pagination.PaginationV3(
		totalPage,
		1,
		"/dev/md/groupresultv2/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "",
		dev_mdgroupresultview.BeforeRequestContentMdGroupResult(),
		dev_mdgroupresultview.AfterRequestContentMdGroupResult(),
	)

	// listItem
	dataResultMcu, err := lh.MdGroupResultServices.GetMdGroupResultResumeMcu()
	fmt.Println(dataResultMcu)
	fmt.Println(err)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR BREADCRUMB DEV",
			zap.Any("error", err),
		)
		fmt.Println(dataResultMcu)
		return err
	}

	defer logger.Sync()
	logger.Info("LOAD BREADCRUMB DEV",
		zap.Any("data", dataBreadCrumb),
	)

	// Component Dropdown MCU
	listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, 0)

	//modal add form
	dialogAddBodyCmp := dev_mdgroupresultview.BodyFormGroupResult(
		models.CustomTextFieldv2Prm{
			Label:       "Group Result name",
			Name:        "groupresultid",
			Placeholder: "Group Result name",
			Type:        "hidden",
			ID:          "groupresultid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Group Result Name",
			Name:        "groupresultname",
			Placeholder: "Group Result Name",
			Type:        "text", ID: "groupresultname"},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
			Name:  "groupresultflagpertest",
			ID:    "groupresultflagpertest",
			Value: "N",
		},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
			Name:  "groupresultflagnonlab",
			ID:    "groupresultflagnonlab",
			Value: "N",
		},
		models.CustomDropdownv1Prm{
			Label: "Group Result Resume MCU",
			Name:  "groupresultresumemcu",
			ID:    "groupresultresumemcu",
		},
		listItemResultMcuComponent,
		dialogAddBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))

	modalActioAddCmp := dev_mdgroupresultview.ActionFormGroupResult(
		"/dev/md/groupresultv2/closeaddform",
		"#"+dialogAddBodyID,
		"outerHTML",
		"#"+dialogAddID)
	btnCloaseModalAdd := dev_mdgroupresultview.BtnCloseFormGroupResult(
		"/dev/md/groupresultv2/closeaddform",
		"#"+dialogAddBodyID,
		"outerHTML",
		"#"+dialogAddID)

	// add
	modalAddFormComponent := dev_mdgroupresultview.GroupResultForm(
		models.GroupResultFormComponent{
			IDComponent:  "formgroupresult",
			Link:         "/dev/md/groupresultv2/add",
			HxTarget:     "#" + dialogAddBodyID,
			HxSwap:       "outerHTML",
			HxInclude:    "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #dialogDeleteBodyID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID,
			ModalID:      dialogAddID,
			ModalTitle:   "New-Group Result",
			DialogBody:   dialogAddBodyCmp,
			DialogAction: modalActioAddCmp,
			ButtonCLose:  btnCloaseModalAdd,
		},
	)

	//modal edit form
	dialogEditBodyCmp := dev_mdgroupresultview.BodyFormGroupResult(
		models.CustomTextFieldv2Prm{
			Label:       "Group Result name",
			Name:        "groupresultid",
			Placeholder: "Group Result name",
			Type:        "hidden",
			ID:          "groupresultid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Group Result Name",
			Name:        "groupresultname",
			Placeholder: "Group Result Name",
			Type:        "text", ID: "groupresultname"},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
			Name:  "groupresultflagpertest",
			ID:    "groupresultflagpertest",
			Value: "N",
		},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
			Name:  "groupresultflagnonlab",
			ID:    "groupresultflagnonlab",
			Value: "N",
		},
		models.CustomDropdownv1Prm{
			Label: "Group Result Resume MCU",
			Name:  "groupresultresumemcu",
			ID:    "groupresultresumemcu",
		},
		listItemResultMcuComponent,
		dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
	modalActioEditCmp := dev_mdgroupresultview.ActionFormGroupResult(
		"/dev/md/groupresultv2/closeeditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#"+dialogEditID)
	btnCloaseModalEdit := dev_mdgroupresultview.BtnCloseFormGroupResult(
		"/dev/md/groupresultv2/closeeditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#"+dialogEditID)

	modalEditFormComponent := dev_mdgroupresultview.GroupResultForm(
		models.GroupResultFormComponent{
			IDComponent:  "formgroupresult",
			Link:         "/dev/md/groupresultv2/edit",
			HxTarget:     "#" + dialogEditBodyID,
			HxSwap:       "outerHTML",
			HxInclude:    "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID,
			ModalID:      dialogEditID,
			ModalTitle:   "New-Group Result",
			DialogBody:   dialogEditBodyCmp,
			DialogAction: modalActioEditCmp,
			ButtonCLose:  btnCloaseModalEdit,
		},
	)
	//modal delete form
	dialogDeleteBodyCmp := dev_mdgroupresultview.BodyFormGroupResult(
		models.CustomTextFieldv2Prm{
			Label:       "Group Result name",
			Name:        "groupresultid",
			Placeholder: "Group Result name",
			Type:        "hidden",
			ID:          "groupresultid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Group Result Name",
			Name:        "groupresultname",
			Placeholder: "Group Result Name",
			Type:        "text", ID: "groupresultname"},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
			Name:  "groupresultflagpertest",
			ID:    "groupresultflagpertest",
			Value: "N",
		},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
			Name:  "groupresultflagnonlab",
			ID:    "groupresultflagnonlab",
			Value: "N",
		},
		models.CustomDropdownv1Prm{
			Label: "Group Result Resume MCU",
			Name:  "groupresultresumemcu",
			ID:    "groupresultresumemcu",
		},
		listItemResultMcuComponent,
		dialogDeleteBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
	modalActioDeleteCmp := dev_mdgroupresultview.ActionFormGroupResultDelete(
		"/dev/md/groupresultv2/closedeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#"+dialogDeleteID)
	btnCloaseModalDelete := dev_mdgroupresultview.BtnCloseFormGroupResult(
		"/dev/md/groupresultv2/closedeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#"+dialogDeleteID)
	modalDeleteFormComponent := dev_mdgroupresultview.GroupResultForm(
		models.GroupResultFormComponent{
			IDComponent:  "formgroupresult",
			Link:         "/dev/md/groupresultv2/delete",
			HxTarget:     "#" + dialogDeleteBodyID,
			HxSwap:       "outerHTML",
			HxInclude:    "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID,
			ModalID:      dialogDeleteID,
			ModalTitle:   "New-Group Result",
			DialogBody:   dialogDeleteBodyCmp,
			DialogAction: modalActioDeleteCmp,
			ButtonCLose:  btnCloaseModalDelete,
		},
	)

	//content js & css
	content := dev_mdgroupresultview.MdGroupResultScreen(
		tableID,
		paginationID,
		searchID,
		dialogAddID,
		dialogAddBodyID,
		dialogEditID,
		dialogEditBodyID,
		dialogDeleteID,
		dialogDeleteBodyID,
		breadcrumbComponent,
		tableComponent,
		usergroupFilterComponent,
		userGroupPaginationComponent,
		modalAddFormComponent,
		modalEditFormComponent,
		modalDeleteFormComponent)
	css := dev_mdgroupresultview.CssMdGroupResult()
	js := dev_mdgroupresultview.JsMdGroupResult()

	view := dev_mdgroupresultview.ShowMdGroupResultScreen(title,
		content,
		css,
		js,
		navbarmenuComponent,
		navbaruserComponent,
		sidebaruserprofileComponent)
	return utils.View(c, view)
}

// SEARCHING
func (lh *MdGroupResultHandler) HandleFilterMdGroupResult(c echo.Context) error {
	search := c.QueryParam("search")
	searchID := c.QueryParam("searchID")
	tableID := c.QueryParam("tableID")
	paginationID := c.QueryParam("paginationID")
	dialogEditBodyID := c.QueryParam("dialogEditBodyID")
	dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID")
	var retval []templ.Component
	logger, _ := zap.NewProduction()

	dataGroupResult, totalpage, err := lh.MdGroupResultServices.GetListMdGroupResult(search, 1, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET GROUP RESULT",
			zap.Any("error", err),
		)
		fmt.Println(dataGroupResult)
		return err
	}
	tableComponent := dev_mdgroupresultview.TableGroupResult(dataGroupResult,
		tableID,
		"/dev/md/groupresultv2/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/groupresultv2/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID")
	userGroupPaginationComponent := pagination.PaginationV3(
		totalpage,
		1,
		"/dev/md/groupresultv2/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID,  #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "",
		dev_mdgroupresultview.BeforeRequestContentMdGroupResult(),
		dev_mdgroupresultview.AfterRequestContentMdGroupResult(),
	)
	retval = append(retval, tableComponent)
	retval = append(retval, userGroupPaginationComponent)
	return utils.ViewMulti(c, retval)
}

// PAGINATION
func (lh *MdGroupResultHandler) HandleChangePageMdGroupResult(c echo.Context) error {
	search := c.QueryParam("search")
	pageparam := c.QueryParam("page")
	tableID := c.QueryParam("tableID")
	searchID := c.QueryParam("searchID")
	paginationID := c.QueryParam("paginationID")
	dialogEditBodyID := c.QueryParam("dialogEditBodyID")
	dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID")
	var retval []templ.Component
	logger, _ := zap.NewProduction()
	page, err := strconv.Atoi(pageparam)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR CONVERT PAGE PARAM",
			zap.Any("page", page),
			zap.Any("error ", err),
		)
		return err
	}
	dataGroupResult, totalpage, err := lh.MdGroupResultServices.GetListMdGroupResult(search, page, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET USER GROUP",
			zap.Any("error", err),
		)
		fmt.Println(dataGroupResult)
		return err
	}
	tableComponent := dev_mdgroupresultview.TableGroupResult(dataGroupResult,
		tableID,
		"/dev/md/groupresultv2/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/groupresultv2/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
	)
	userGroupPaginationComponent := pagination.PaginationV3(
		totalpage,
		page,
		"/dev/md/groupresultv2/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "",
		dev_mdgroupresultview.BeforeRequestContentMdGroupResult(),
		dev_mdgroupresultview.AfterRequestContentMdGroupResult(),
	)
	retval = append(retval, tableComponent)
	retval = append(retval, userGroupPaginationComponent)
	return utils.ViewMulti(c, retval)
}

// CLOSE FORM
func (lh *MdGroupResultHandler) HandleCloseFormAdd(c echo.Context) error {
	logger, _ := zap.NewProduction()
	// listItem
	dataResultMcu, err := lh.MdGroupResultServices.GetMdGroupResultResumeMcu()
	fmt.Println(dataResultMcu)
	fmt.Println(err)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR RESULT RESUME MCU DEV",
			zap.Any("error", err),
		)
		fmt.Println(dataResultMcu)
		return err
	}

	// Component Dropdown MCU
	listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, 0)

	dialogAddBodyID := c.FormValue("dialogAddBodyID")
	newForm := dev_mdgroupresultview.BodyFormGroupResult(
		models.CustomTextFieldv2Prm{
			Label:       "Group Result name",
			Name:        "groupresultid",
			Placeholder: "Group Result name",
			Type:        "hidden",
			ID:          "groupresultid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Group Result Name",
			Name:        "groupresultname",
			Placeholder: "Group Result Name",
			Type:        "text", ID: "groupresultname"},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
			Name:  "groupresultflagpertest",
			ID:    "groupresultflagpertest",
			Value: "N",
		},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
			Name:  "groupresultflagnonlab",
			ID:    "groupresultflagnonlab",
			Value: "N",
		},
		models.CustomDropdownv1Prm{
			Label: "Group Result Resume MCU",
			Name:  "groupresultresumemcu",
			ID:    "groupresultresumemcu",
		},
		listItemResultMcuComponent,
		dialogAddBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
	return utils.View(c, newForm)
}

// PROSES ADD DATA
func (lh *MdGroupResultHandler) HandleAddGroupResult(c echo.Context) error {

	logger, _ := zap.NewProduction()
	defer logger.Sync()

	//prm form addusergroup
	// DARI FORM ADD NYA
	groupresultname := c.FormValue("groupresultname")
	groupresultflagpertest := c.FormValue("groupresultflagpertest")
	groupresultflagnonlab := c.FormValue("groupresultflagnonlab")
	groupresultresumemcu := c.FormValue("groupresultresumemcu")

	// setting flag test dan flagnonlab
	var flagPerTest string = "N"
	var flagNonLab string = "N"
	// var mcuResumeSelectedValue int = 0

	tableID := c.FormValue("tableID")
	paginationID := c.FormValue("paginationID")
	searchID := c.FormValue("searchID")
	search := c.FormValue("search")
	currPagePrm := c.FormValue("currpage" + paginationID)
	dialogAddBodyID := c.FormValue("dialogAddBodyID")
	dialogAddID := c.FormValue("dialogAddID")
	dialogEditBodyID := c.FormValue("dialogEditBodyID")
	dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")

	currPage, err := strconv.Atoi(currPagePrm)
	if err != nil {
		return err
	}
	logger.Info("ADD USER GROUP PARAM",
		zap.Any("groupresultname", groupresultname),
		zap.Any("groupresultflagpertest", groupresultflagpertest),
		zap.Any("groupresultflagnonlab", groupresultflagnonlab),
		zap.Any("groupresultresumemcu", groupresultresumemcu),
		zap.Any("tableid", tableID),
		zap.Any("search", search),
		zap.Any("currpage", currPage),
	)

	// listItem
	dataResultMcu, err := lh.MdGroupResultServices.GetMdGroupResultResumeMcu()
	fmt.Println(dataResultMcu)
	fmt.Println(err)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR BREADCRUMB DEV",
			zap.Any("error", err),
		)
		fmt.Println(dataResultMcu)
		return err
	}
	// Component Dropdown MCU
	listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, 0)

	// check dropdown result mcu
	var idSelectedGroupResultResumeMcu int
	idSelectedGroupResultResumeMcu, err = strconv.Atoi(groupresultresumemcu)
	if err != nil {
		// Tangani kesalahan konversi
		fmt.Println("Error converting string to int:", err)
		// return
		test := dev_mdgroupresultview.BodyFormGroupResult(
			models.CustomTextFieldv2Prm{
				Label:       "Group Result name",
				Name:        "groupresultid",
				Placeholder: "Group Result name",
				Type:        "hidden",
				ID:          "groupresultid",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Group Result Name",
				Name:        "groupresultname",
				Placeholder: "Group Result Name",
				Type:        "text", ID: "groupresultname"},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
				Name:  "groupresultflagpertest",
				ID:    "groupresultflagpertest",
			},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
				Name:  "groupresultflagnonlab",
				ID:    "groupresultflagnonlab",
			},
			models.CustomDropdownv1Prm{
				Label: "Group Result Resume MCU",
				Name:  "groupresultresumemcu",
				ID:    "groupresultresumemcu",
			},
			listItemResultMcuComponent,
			dialogAddBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""),
		)
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", "Error converting string to int", "danger"),
			test})
		return coba
	}

	var groupresultresumemcuNew string
	for _, x := range dataResultMcu {
		if x.ID == idSelectedGroupResultResumeMcu {
			groupresultresumemcuNew = x.Text
			// mcuResumeSelectedValue = x.ID
		}
	}

	// check group result flag per test
	if groupresultflagpertest == "on" {
		flagPerTest = "Y"
	}

	// check group result flag non lab
	if groupresultflagnonlab == "on" {
		flagNonLab = "Y"
	}

	formValidation := ""
	nameValidation := ""

	if strings.TrimSpace(groupresultname) == "" {
		formValidation = "Group Result Name tidak boleh kosong"
		nameValidation = "Group Result Name tidak boleh kosong"
	}

	if formValidation != "" || nameValidation != "" {
		newForm := dev_mdgroupresultview.BodyFormGroupResult(
			models.CustomTextFieldv2Prm{
				Label:       "Group Result name",
				Name:        "groupresultid",
				Placeholder: "Group Result name",
				Type:        "hidden",
				ID:          "groupresultid",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Group Result Name",
				Name:        "groupresultname",
				Placeholder: "Group Result Name",
				Value:       groupresultname,
				ErrorMsg:    "Group Result Name Kosong",
				Type:        "text", ID: "groupresultname"},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
				Name:  "groupresultflagpertest",
				ID:    "groupresultflagpertest",
				Value: groupresultflagpertest,
			},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
				Name:  "groupresultflagnonlab",
				ID:    "groupresultflagnonlab",
				Value: groupresultflagnonlab,
			},
			models.CustomDropdownv1Prm{
				Label: "Group Result Resume MCU",
				Name:  "groupresultresumemcu",
				ID:    "groupresultresumemcu",
			},
			listItemResultMcuComponent,
			dialogAddBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm})
	}
	//Add user group service
	dataGroupResultAdd, err := lh.MdGroupResultServices.AddMdGroupResult(groupresultname, flagPerTest, flagNonLab, groupresultresumemcuNew)

	if err != nil {
		logger.Info("Error",
			zap.Any("Error", err),
			zap.Any("groupresultname", groupresultname),
			zap.Any("groupresultflagpertest", groupresultflagpertest),
			zap.Any("groupresultflagnonlab", groupresultflagnonlab),
			zap.Any("groupresultresumemcu", groupresultresumemcu),
		)
		newForm := dev_mdgroupresultview.BodyFormGroupResult(
			models.CustomTextFieldv2Prm{
				Label:       "Group Result name",
				Name:        "groupresultid",
				Placeholder: "Group Result name",
				Type:        "hidden",
				ID:          "groupresultid",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Group Result Name",
				Name:        "groupresultname",
				Placeholder: "Group Result Name",
				Value:       groupresultname,
				Type:        "text", ID: "groupresultname"},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
				Name:  "groupresultflagpertest",
				ID:    "groupresultflagpertest",
				Value: groupresultflagpertest,
			},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
				Name:  "groupresultflagnonlab",
				ID:    "groupresultflagnonlab",
				Value: groupresultflagnonlab,
			},
			models.CustomDropdownv1Prm{
				Label: "Group Result Resume MCU",
				Name:  "groupresultresumemcu",
				ID:    "groupresultresumemcu",
			},
			listItemResultMcuComponent,
			dialogAddBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
		return utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
			newForm})

	}
	logger.Info("ADD USER GROUP",
		zap.Any("return", dataGroupResultAdd),
		zap.Any("groupresultname", groupresultname),
		zap.Any("groupresultflagpertest", groupresultflagpertest),
		zap.Any("groupresultflagnonlab", groupresultflagnonlab),
		zap.Any("groupresultresumemcu", groupresultresumemcu),
	)
	//get list user group for table
	dataUserGroupList, totalPage, err := lh.MdGroupResultServices.GetListMdGroupResult(search, currPage, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET GROUP RESULT",
			zap.Any("error", err),
		)
		fmt.Println(dataUserGroupList)
		return err
	}
	//table component
	tableComponent := dev_mdgroupresultview.TableGroupResult(dataUserGroupList,
		tableID,
		"/dev/md/groupresultv2/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/groupresultv2/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID")

	//pagination component
	//Pagination
	userGroupPaginationComponent := pagination.PaginationV3(
		totalPage,
		currPage,
		"/dev/md/groupresultv2/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "true",
		dev_mdgroupresultview.BeforeRequestContentMdGroupResult(),
		dev_mdgroupresultview.AfterRequestContentMdGroupResult(),
	)

	newForm := dev_mdgroupresultview.BodyFormGroupResult(
		models.CustomTextFieldv2Prm{
			Label:       "Group Result name",
			Name:        "groupresultid",
			Placeholder: "Group Result name",
			Type:        "hidden",
			ID:          "groupresultid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Group Result Name",
			Name:        "groupresultname",
			Placeholder: "Group Result Name",
			Type:        "text", ID: "groupresultname"},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
			Name:  "groupresultflagpertest",
			ID:    "groupresultflagpertest",
		},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
			Name:  "groupresultflagnonlab",
			ID:    "groupresultflagnonlab",
		},
		models.CustomDropdownv1Prm{
			Label: "Group Result Resume MCU",
			Name:  "groupresultresumemcu",
			ID:    "groupresultresumemcu",
		},
		listItemResultMcuComponent,
		dialogAddBodyID, dev_mdgroupresultview.JsHideModalGroupResult("#"+dialogAddID))
	toastSuccess := customtoastv2.CustomToastV2Show("Success", "Success add group result "+groupresultname, "success")

	return utils.ViewMulti(c, []templ.Component{
		toastSuccess,
		tableComponent,
		userGroupPaginationComponent,
		newForm})
}

// SHOW EDIT
func (lh *MdGroupResultHandler) HandleOpenEditForm(c echo.Context) error {
	logger, _ := zap.NewProduction()
	defer logger.Sync()

	id := c.QueryParam("id")
	dialogEditID := c.QueryParam("dialogEditID")
	dialogEditBodyID := c.QueryParam("dialogEditBodyID")

	// listItem
	dataResultMcu, err := lh.MdGroupResultServices.GetMdGroupResultResumeMcu()
	fmt.Println(dataResultMcu)
	fmt.Println(err)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR BREADCRUMB DEV",
			zap.Any("error", err),
		)
		fmt.Println(dataResultMcu)
		return err
	}
	// Component Dropdown MCU default
	listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, 0)

	// get data by id
	dataGroupList, err := lh.MdGroupResultServices.GetMdGroupResultByID(id)
	if err != nil {
		newForm := dev_mdgroupresultview.BodyFormGroupResult(
			models.CustomTextFieldv2Prm{
				Label:       "Group Result name",
				Name:        "groupresultid",
				Placeholder: "Group Result name",
				Type:        "hidden",
				ID:          "groupresultid",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Group Result Name",
				Name:        "groupresultname",
				Placeholder: "Group Result Name",
				Type:        "text", ID: "groupresultname"},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
				Name:  "groupresultflagpertest",
				ID:    "groupresultflagpertest",
			},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
				Name:  "groupresultflagnonlab",
				ID:    "groupresultflagnonlab",
			},
			models.CustomDropdownv1Prm{
				Label: "Group Result Resume MCU",
				Name:  "groupresultresumemcu",
				ID:    "groupresultresumemcu",
			},
			listItemResultMcuComponent,
			dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", "Get group result error", "danger"), newForm})
	}

	// Component Dropdown MCU
	var idSelectedGroupResultResumeMcu int = 0
	for _, x := range dataResultMcu {
		if x.Text == dataGroupList.Group_ResultResumeMcu {
			idSelectedGroupResultResumeMcu = x.ID
		}
	}

	listItemResultMcuComponentPopulate := dev_mdgroupresultview.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)

	newForm := dev_mdgroupresultview.BodyFormGroupResult(
		models.CustomTextFieldv2Prm{
			Label:       "Group Result name",
			Name:        "groupresultid",
			Placeholder: "Group Result name",
			Type:        "hidden",
			ID:          "groupresultid",
			Value:       strconv.Itoa(dataGroupList.Group_ResultID),
		},
		models.CustomTextFieldv2Prm{
			Label:       "Group Result Name",
			Name:        "groupresultname",
			Placeholder: "Group Result Name",
			Type:        "text", ID: "groupresultname",
			Value: dataGroupList.Group_ResultName,
		},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
			Name:  "groupresultflagpertest",
			ID:    "groupresultflagpertest",
			Value: dataGroupList.Group_ResultFlagPerTest,
		},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
			Name:  "groupresultflagnonlab",
			ID:    "groupresultflagnonlab",
			Value: dataGroupList.Group_ResultFlagNonLab,
		},
		models.CustomDropdownv1Prm{
			Label: "Group Result Resume MCU",
			Name:  "groupresultresumemcu",
			ID:    "groupresultresumemcu",
		},
		listItemResultMcuComponentPopulate,
		dialogEditBodyID, dev_mdgroupresultview.JsShowModalGroupResult("#"+dialogEditID))
	return utils.View(c, newForm)
}

// CLOSE EDIT FORM
func (lh *MdGroupResultHandler) HandleCloseFormEdit(c echo.Context) error {
	dialogEditBodyID := c.FormValue("dialogEditBodyID")

	logger, _ := zap.NewProduction()
	// listItem
	dataResultMcu, err := lh.MdGroupResultServices.GetMdGroupResultResumeMcu()
	fmt.Println(dataResultMcu)
	fmt.Println(err)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR RESULT RESUME MCU DEV",
			zap.Any("error", err),
		)
		fmt.Println(dataResultMcu)
		return err
	}

	// Component Dropdown MCU
	listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, 0)

	newForm := dev_mdgroupresultview.BodyFormGroupResult(
		models.CustomTextFieldv2Prm{
			Label:       "Group Result name",
			Name:        "groupresultid",
			Placeholder: "Group Result name",
			Type:        "hidden",
			ID:          "groupresultid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Group Result Name",
			Name:        "groupresultname",
			Placeholder: "Group Result Name",
			Type:        "text", ID: "groupresultname"},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
			Name:  "groupresultflagpertest",
			ID:    "groupresultflagpertest",
			Value: "N",
		},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
			Name:  "groupresultflagnonlab",
			ID:    "groupresultflagnonlab",
			Value: "N",
		},
		models.CustomDropdownv1Prm{
			Label: "Group Result Resume MCU",
			Name:  "groupresultresumemcu",
			ID:    "groupresultresumemcu",
		},
		listItemResultMcuComponent,
		dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
	return utils.View(c, newForm)
}

// PROSES EDIT DATA
func (lh *MdGroupResultHandler) HandleEditGroupResult(c echo.Context) error {

	logger, _ := zap.NewProduction()
	defer logger.Sync()

	//prm form addusergroup
	// DARI FORM ADD NYA
	groupresultname := c.FormValue("groupresultname")
	groupresultflagpertest := c.FormValue("groupresultflagpertest")
	groupresultflagnonlab := c.FormValue("groupresultflagnonlab")
	groupresultresumemcu := c.FormValue("groupresultresumemcu")

	// setting flag test dan flagnonlab
	var flagPerTest string = "N"
	var flagNonLab string = "N"

	id := c.FormValue("groupresultid")
	tableID := c.FormValue("tableID")
	paginationID := c.FormValue("paginationID")
	searchID := c.FormValue("searchID")
	search := c.FormValue("search")
	currPagePrm := c.FormValue("currpage" + paginationID)
	// dialogAddBodyID := c.FormValue("dialogAddBodyID")
	dialogEditID := c.FormValue("dialogEditID")
	dialogEditBodyID := c.FormValue("dialogEditBodyID")
	dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")

	currPage, err := strconv.Atoi(currPagePrm)
	if err != nil {
		return err
	}
	logger.Info("ADD USER GROUP PARAM",
		zap.Any("groupresultname", groupresultname),
		zap.Any("groupresultflagpertest", groupresultflagpertest),
		zap.Any("groupresultflagnonlab", groupresultflagnonlab),
		zap.Any("groupresultresumemcu", groupresultresumemcu),
		zap.Any("tableid", tableID),
		zap.Any("search", search),
		zap.Any("currpage", currPage),
	)

	// listItem
	dataResultMcu, err := lh.MdGroupResultServices.GetMdGroupResultResumeMcu()
	fmt.Println(dataResultMcu)
	fmt.Println(err)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR BREADCRUMB DEV",
			zap.Any("error", err),
		)
		fmt.Println(dataResultMcu)
		return err
	}

	// Component Dropdown MCU
	listItemResultMcuComponentInitial := dev_mdgroupresultview.ItemDropdown(dataResultMcu, 0)

	// check dropdown result mcu
	var idSelectedGroupResultResumeMcu int
	idSelectedGroupResultResumeMcu, err = strconv.Atoi(groupresultresumemcu)
	if err != nil {
		newForm := dev_mdgroupresultview.BodyFormGroupResult(
			models.CustomTextFieldv2Prm{
				Label:       "Group Result name",
				Name:        "groupresultid",
				Placeholder: "Group Result name",
				Type:        "hidden",
				ID:          "groupresultid",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Group Result Name",
				Name:        "groupresultname",
				Placeholder: "Group Result Name",
				Type:        "text", ID: "groupresultname"},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
				Name:  "groupresultflagpertest",
				ID:    "groupresultflagpertest",
			},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
				Name:  "groupresultflagnonlab",
				ID:    "groupresultflagnonlab",
			},
			models.CustomDropdownv1Prm{
				Label: "Group Result Resume MCU",
				Name:  "groupresultresumemcu",
				ID:    "groupresultresumemcu",
			},
			listItemResultMcuComponentInitial,
			dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", "Error converting string to int", "error"), newForm})

	}

	var groupresultresumemcuNew string
	for _, x := range dataResultMcu {
		if x.ID == idSelectedGroupResultResumeMcu {
			groupresultresumemcuNew = x.Text
		}
	}

	// check group result flag per test
	if groupresultflagpertest == "on" {
		flagPerTest = "Y"
	}

	// check group result flag non lab
	if groupresultflagnonlab == "on" {
		flagNonLab = "Y"
	}

	formValidation := ""
	nameValidation := ""

	if strings.TrimSpace(groupresultname) == "" {
		formValidation = "Group Result Name tidak boleh kosong"
		nameValidation = "Group Result Name tidak boleh kosong"
	}

	if formValidation != "" || nameValidation != "" {
		listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)
		newForm := dev_mdgroupresultview.BodyFormGroupResult(
			models.CustomTextFieldv2Prm{
				Label:       "Group Result name",
				Name:        "groupresultid",
				Placeholder: "Group Result name",
				Type:        "hidden",
				ID:          "groupresultid",
				// Value:       id,
			},
			models.CustomTextFieldv2Prm{
				Label:       "Group Result Name",
				Name:        "groupresultname",
				Placeholder: "Group Result Name",
				ErrorMsg:    "Group Result Name Kosong",
				Value:       groupresultname,
				Type:        "text", ID: "groupresultname"},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
				Name:  "groupresultflagpertest",
				ID:    "groupresultflagpertest",
				Value: groupresultflagpertest,
			},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
				Name:  "groupresultflagnonlab",
				ID:    "groupresultflagnonlab",
				Value: groupresultflagnonlab,
			},
			models.CustomDropdownv1Prm{
				Label: "Group Result Resume MCU",
				Name:  "groupresultresumemcu",
				ID:    "groupresultresumemcu",
			},
			listItemResultMcuComponent,
			dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm})
	}

	//edit user group service
	dataGroupList, err := lh.MdGroupResultServices.EditMdGroupResult(id, groupresultname, flagPerTest, flagNonLab, groupresultresumemcuNew)
	if err != nil {
		listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)
		logger.Info("Error",
			zap.Any("Error", err),
			zap.Any("groupresultname", groupresultname),
			zap.Any("groupresultflagpertest", groupresultflagpertest),
			zap.Any("groupresultflagnonlab", groupresultflagnonlab),
			zap.Any("groupresultresumemcu", groupresultresumemcu),
		)
		newForm := dev_mdgroupresultview.BodyFormGroupResult(
			models.CustomTextFieldv2Prm{
				Label:       "Group Result name",
				Name:        "groupresultid",
				Placeholder: "Group Result name",
				Type:        "hidden",
				ID:          "groupresultid",
				Value:       id,
			},
			models.CustomTextFieldv2Prm{
				Label:       "Group Result Name",
				Name:        "groupresultname",
				Placeholder: "Group Result Name",
				Value:       groupresultname,
				Type:        "text", ID: "groupresultname"},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
				Name:  "groupresultflagpertest",
				ID:    "groupresultflagpertest",
				Value: groupresultflagpertest,
			},
			models.CustomCheckboxv1Prm{
				Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
				Name:  "groupresultflagnonlab",
				ID:    "groupresultflagnonlab",
				Value: groupresultflagnonlab,
			},
			models.CustomDropdownv1Prm{
				Label: "Group Result Resume MCU",
				Name:  "groupresultresumemcu",
				ID:    "groupresultresumemcu",
			},
			listItemResultMcuComponent,
			dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult(""))
		return utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
			newForm})

	}
	logger.Info("ADD USER GROUP",
		zap.Any("return", dataGroupList),
		zap.Any("groupresultname", groupresultname),
		zap.Any("groupresultflagpertest", groupresultflagpertest),
		zap.Any("groupresultflagnonlab", groupresultflagnonlab),
		zap.Any("groupresultresumemcu", groupresultresumemcu),
	)
	//get list user group for table
	dataUserGroupList, totalPage, err := lh.MdGroupResultServices.GetListMdGroupResult(search, currPage, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET USER GROUP",
			zap.Any("error", err),
		)
		fmt.Println(dataGroupList)
		return err
	}
	//table component
	tableComponent := dev_mdgroupresultview.TableGroupResult(dataUserGroupList,
		tableID,
		"/dev/md/groupresultv2/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/groupresultv2/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID")

	//pagination component
	//Pagination
	userGroupPaginationComponent := pagination.PaginationV3(
		totalPage,
		currPage,
		"/dev/md/groupresultv2/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "true",
		dev_mdgroupresultview.BeforeRequestContentMdGroupResult(),
		dev_mdgroupresultview.AfterRequestContentMdGroupResult(),
	)

	listItemResultMcuComponent := dev_mdgroupresultview.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)

	var retVal []templ.Component
	newForm := dev_mdgroupresultview.BodyFormGroupResult(
		models.CustomTextFieldv2Prm{
			Label:       "Group Result name",
			Name:        "groupresultid",
			Placeholder: "Group Result name",
			Type:        "hidden",
			ID:          "groupresultid",
			Value:       id,
		},
		models.CustomTextFieldv2Prm{
			Label:       "Group Result Name",
			Name:        "groupresultname",
			Placeholder: "Group Result Name",
			Value:       groupresultname,
			Type:        "text", ID: "groupresultname"},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Per Test (Dicentang Maka Ya)",
			Name:  "groupresultflagpertest",
			ID:    "groupresultflagpertest",
			Value: groupresultflagpertest,
		},
		models.CustomCheckboxv1Prm{
			Label: "Group Result Flag Non Lab (Dicentang Maka Ya)",
			Name:  "groupresultflagnonlab",
			ID:    "groupresultflagnonlab",
			Value: groupresultflagnonlab,
		},
		models.CustomDropdownv1Prm{
			Label: "Group Result Resume MCU",
			Name:  "groupresultresumemcu",
			ID:    "groupresultresumemcu",
		},
		listItemResultMcuComponent,
		dialogEditBodyID, dev_mdgroupresultview.JsHideModalGroupResult("#"+dialogEditID))
	toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil edit Group Result  "+groupresultname, "success")
	retVal = append(retVal, toastSuccess)
	retVal = append(retVal, tableComponent)
	retVal = append(retVal, userGroupPaginationComponent)
	retVal = append(retVal, newForm)
	return utils.ViewMulti(c, retVal)
}

// SHOW DELETE FORM
func (lh *MdGroupResultHandler) HandleOpenDeleteForm(c echo.Context) error {
	id := c.QueryParam("id")
	dialogDeleteID := c.QueryParam("dialogDeleteID")
	dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID")

	dataGroupList, err := lh.MdGroupResultServices.GetMdGroupResultByID(id)

	var flagPerTest string = "N"
	var flagNonLab string = "N"

	if dataGroupList.Group_ResultFlagPerTest == "on" {
		flagPerTest = "Y"
	}

	if dataGroupList.Group_ResultFlagNonLab == "on" {
		flagNonLab = "Y"
	}

	if err != nil {
		newForm := dev_mdgroupresultview.DeleteConfirmationBodyGroupResult(
			models.CustomTextFieldv2Prm{Type: "hidden", Value: "0", Name: "groupresultid"},
			dialogDeleteBodyID, "Apakah anda yakin menghapus group result berikut ?",
			[]string{"GROUP RESULT NAME", "RESULT FLAG PER TEST", "RESULT FLAG NON LAB", "RESULT RESUME MCU"},
			[]string{"", "", "", ""},
			dev_mdgroupresultview.JsHideModalGroupResult(""))
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", "Get group result error", "danger"), newForm})
	}
	newForm := dev_mdgroupresultview.DeleteConfirmationBodyGroupResult(
		models.CustomTextFieldv2Prm{Type: "hidden", Value: strconv.Itoa(dataGroupList.Group_ResultID), Name: "groupresultid"},
		dialogDeleteBodyID, "Apakah anda yakin menghapus group result berikut ?",
		[]string{"GROUP RESULT NAME", "RESULT FLAG PER TEST", "RESULT FLAG NON LAB", "RESULT RESUME MCU"},
		[]string{dataGroupList.Group_ResultName, flagPerTest, flagNonLab, dataGroupList.Group_ResultResumeMcu},
		dev_mdgroupresultview.JsShowModalGroupResult("#"+dialogDeleteID))
	return utils.View(c, newForm)
}

// CLOSE DELETE FORM
func (lh *MdGroupResultHandler) HandleCloseFormDelete(c echo.Context) error {
	dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
	newForm := dev_mdgroupresultview.DeleteConfirmationBodyGroupResult(
		models.CustomTextFieldv2Prm{Type: "hidden", Value: "0", Name: "groupresultid"},
		dialogDeleteBodyID, "Apakah anda yakin menghapus group result berikut ?",
		[]string{"GROUP RESULT NAME", "RESULT FLAG PER TEST", "RESULT FLAG NON LAB", "RESULT RESUME MCU"},
		[]string{"", "", "", ""},
		dev_mdgroupresultview.JsHideModalGroupResult(""))
	return utils.View(c, newForm)
}

// PROSES DELETE
func (lh *MdGroupResultHandler) HandleDeleteUserGroup(c echo.Context) error {

	logger, _ := zap.NewProduction()
	defer logger.Sync()

	//prm form addusergroup

	id := c.FormValue("groupresultid")
	tableID := c.FormValue("tableID")
	paginationID := c.FormValue("paginationID")
	searchID := c.FormValue("searchID")
	search := c.FormValue("search")
	currPagePrm := c.FormValue("currpage" + paginationID)
	// dialogAddBodyID := c.FormValue("dialogAddBodyID")
	dialogDeleteID := c.FormValue("dialogDeleteID")
	dialogEditBodyID := c.FormValue("dialogEditBodyID")
	dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")

	currPage, err := strconv.Atoi(currPagePrm)
	if err != nil {
		return err
	}
	logger.Info("ADD USER GROUP PARAM",

		zap.Any("tableid", tableID),
		zap.Any("search", search),
		zap.Any("currpage", currPage),
	)

	//edit user group service
	dataUserGroup, err := lh.MdGroupResultServices.DeleteMdGroupResult(id)
	if err != nil {
		logger.Info("Error",
			zap.Any("Error", err),
		)
		newForm := dev_mdgroupresultview.DeleteConfirmationBodyGroupResult(
			models.CustomTextFieldv2Prm{Name: "groupresultid", Type: "hidden", Value: ""},
			dialogDeleteBodyID,
			"Apakah anda yakin menghapus group result berikut ?",
			[]string{"GROUP RESULT NAME", "RESULT FLAG PER TEST", "RESULT FLAG NON LAB", "RESULT RESUME MCU"},
			[]string{"", "", "", ""},
			dev_mdgroupresultview.JsHideModalGroupResult(""))
		return utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
			newForm})

	}
	logger.Info("ADD USER GROUP",
		zap.Any("return", dataUserGroup),
	)
	//get list user group for table
	dataUserGroupList, totalPage, err := lh.MdGroupResultServices.GetListMdGroupResult(search, currPage, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET USER GROUP",
			zap.Any("error", err),
		)
		fmt.Println(dataUserGroup)
		return err
	}
	if len(dataUserGroupList) == 0 && totalPage > 1 {
		currPage = currPage - 1
		dataUserGroupList, _, err = lh.MdGroupResultServices.GetListMdGroupResult(search, currPage, 5)
		if err != nil {
			defer logger.Sync()
			logger.Info("ERROR GET USER GROUP",
				zap.Any("error", err),
			)
			return err
		}
	}
	//table component
	tableComponent := dev_mdgroupresultview.TableGroupResult(dataUserGroupList,
		tableID,
		"/dev/md/groupresultv2/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/groupresultv2/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID")

	//pagination component
	//Pagination
	userGroupPaginationComponent := pagination.PaginationV3(
		totalPage,
		currPage,
		"/dev/md/groupresultv2/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "true",
		dev_mdgroupresultview.BeforeRequestContentMdGroupResult(),
		dev_mdgroupresultview.AfterRequestContentMdGroupResult(),
	)
	var retVal []templ.Component
	newForm := dev_mdgroupresultview.DeleteConfirmationBodyGroupResult(
		models.CustomTextFieldv2Prm{Name: "groupresultid", Type: "hidden", Value: ""},
		dialogDeleteBodyID,
		"Apakah anda yakin menghapus group result berikut ?",
		[]string{"GROUP RESULT NAME", "RESULT FLAG PER TEST", "RESULT FLAG NON LAB", "RESULT RESUME MCU"},
		[]string{"", "", "", ""},
		dev_mdgroupresultview.JsHideModalGroupResult("#"+dialogDeleteID))
	toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil delete group result ", "success")
	retVal = append(retVal, toastSuccess)
	retVal = append(retVal, tableComponent)
	retVal = append(retVal, userGroupPaginationComponent)
	retVal = append(retVal, newForm)
	return utils.ViewMulti(c, retVal)
}
