package dev_handlers

import (
	breadcrumbadmin "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"
	globalservices "cpone/services"
	"cpone/utils"
	groupresult "cpone/views/dev/groupresult"
	mastermenuusergroup "cpone/views/dev/mastermenuusergroup"
	"fmt"
	"strconv"
	"strings"

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

type GroupResultService interface {
	GetGroupResultByIDV1(id string) (models.GroupResult, error)
	GetListBreadCrumb(title string) (models.BreadCrumbV1, error)
	EditGroupResult(id string, groupresultname string, groupresultflagpertest string, groupresultflagnonlab string, groupresultresumemcu string) (models.GroupResult, error)
	DeleteGroupResult(id string) (models.GroupResult, error)
	GetListGroupResult(search string, currentPage int, rowPerPage int) ([]models.GroupResult, int, error)
	GetGroupResultResumeMcu() ([]models.GroupResultResumeMcu, error)
	AddGroupResult(groupresultname string, groupresultflagpertest string, groupresultflagnonlab string, groupresultresumemcu string) (models.GroupResult, error)
}

func NewGroupResultHandler(us GroupResultService) *GroupResultHandler {
	return &GroupResultHandler{
		GroupResultService: us,
	}
}

type GroupResultHandler struct {
	GroupResultService GroupResultService
}

// PAGINATION
func (lh *GroupResultHandler) HandlerShowGroupResultPaginationV1(c echo.Context) error {
	logger, _ := zap.NewProduction()

	search := c.QueryParam("search")
	pageparam := c.QueryParam("page")
	tableID := c.QueryParam("tableID")
	searchID := c.QueryParam("searchID")

	paginationID := c.QueryParam("paginationID")
	dialogEditBodyID := c.QueryParam("dialogEditBodyID")
	// dialogEditID := c.QueryParam("dialogEditID")
	dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID")
	// dialogDeleteID := c.QueryParam("dialogDeleteID")
	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.GroupResultService.GetListGroupResult(search, page, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET USER GROUP",
			zap.Any("error", err),
		)
		fmt.Println(dataGroupResult)
		return err
	}

	contentUserGroupComponent := groupresult.TableGroupResult(
		dataGroupResult, tableID, "/dev/groupresultshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/groupresultshowdeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

	userGroupResultPaginationComponent := pagination.PaginationV2(totalpage,
		page,
		"/dev/groupresultv1pagination",
		paginationID,
		// "#tableID, #searchID, #"+searchID+", #dropdownID, #"+dropdownID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID, [name='search'],  [name='usergroup']",
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID, "outerHTML", "", "")

	retval := []templ.Component{contentUserGroupComponent, userGroupResultPaginationComponent}

	return utils.ViewMulti(c, retval)
}

// HANDLE CLOSE BUTTON
func (lh *GroupResultHandler) HandleCloseForm(c echo.Context) error {
	// #dialogAddBodyID, #dialogAddID

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

	// listItem
	dataResultMcu, err := lh.GroupResultService.GetGroupResultResumeMcu()
	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 := groupresult.ItemDropdown(dataResultMcu, 0)

	dialogAddBodyID := c.FormValue("dialogAddBodyID")
	form := groupresult.DialogNewBodyV1(
		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, groupresult.HandleJSModalAddGR(""))
	return utils.View(c, form)
}

// CLOSE FORM EDIT
func (lh *GroupResultHandler) HandleCloseFormEdit(c echo.Context) error {
	logger, _ := zap.NewProduction()
	defer logger.Sync()

	// listItem
	dataResultMcu, err := lh.GroupResultService.GetGroupResultResumeMcu()
	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 := groupresult.ItemDropdown(dataResultMcu, 0)

	dialogEditBodyID := c.FormValue("dialogEditBodyID")
	form := groupresult.DialogNewBodyV1(
		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, groupresult.HandleJSModalAddGR(""))
	return utils.View(c, form)
}

// LISTING FUNCTION INITIAL
func (lh *GroupResultHandler) HandlerShowGroupResultV1(c echo.Context) error {

	logger, _ := zap.NewProduction()
	//get sidebarmenu

	dataMenu, err := globalservices.GetMenu()
	fmt.Println(dataMenu)
	fmt.Println(err)
	if err != nil {
		fmt.Println(dataMenu)
		return err
	}

	//get user login
	dataUser, err := globalservices.GetUserLogin()
	fmt.Println(dataUser)
	fmt.Println(err)
	if err != nil {
		fmt.Println(dataUser)
		return err
	}

	// dropdownUserGroupInitial :=

	dataGroupResult, totalpage, err := lh.GroupResultService.GetListGroupResult("", 1, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET USER GROUP",
			zap.Any("error", err),
		)
		fmt.Println(dataGroupResult)
		return err
	}

	// si := mastermenuusergroup.ListMasterUserGroupInitial(dataGroupResult)

	defer logger.Sync()
	logger.Info("LOAD USER GROUP DEV",
		zap.Any("data", dataGroupResult),
	)

	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")

	paramTitleBreadcrumbConvert := "Master Group Result"

	dataBreadCrumb, err := lh.GroupResultService.GetListBreadCrumb(paramTitleBreadcrumbConvert)
	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),
	)

	// navbar menu
	navbarmenuComponent := navbarmenu.NavbarMenu(dataMenu)

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

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

	// listItem
	dataResultMcu, err := lh.GroupResultService.GetGroupResultResumeMcu()
	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 := groupresult.ItemDropdown(dataResultMcu, 0)

	//Component modal add usergroup
	// modaladdcomponent := groupresult.EmptyDiv1()
	modaladdcomponent := groupresult.GroupResultForm(models.GroupResultFormComponent{
		IDComponent: "formgroupresult",
		Link:        "/dev/groupresult/add",
		HxTarget:    "#" + dialogAddBodyID,
		HxSwap:      "outerHTML",
		HxInclude:   "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID,
		ModalID:     dialogAddID,
		ModalTitle:  "New-Group Result",
		DialogBody: groupresult.DialogNewBodyV1(
			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, groupresult.HandleJSModalAddGR("")),
		DialogAction: groupresult.DialogNewActionV1("/dev/groupresulthandlecloseform", "#"+dialogAddBodyID, "outerHTML", "#"+dialogAddID),
		ButtonCLose:  groupresult.BtnCloseNewV1("/dev/groupresulthandlecloseform", "#"+dialogAddBodyID, "outerHTML", "#"+dialogAddID),
	})

	//Component modal edit usergroup
	// modalEditcomponent := groupresult.EmptyDiv1()
	//Component modal edit usergroup
	modalEditcomponent := groupresult.GroupResultForm(models.GroupResultFormComponent{
		IDComponent: "formgroupresultedit",
		Link:        "/dev/groupresult/edit",
		HxTarget:    "#" + dialogEditBodyID,
		HxSwap:      "outerHTML",
		// HxInclude:   "#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID,
		HxInclude:  "#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID + ", #dialogDeleteBodyID, #dialogDeleteID",
		ModalID:    dialogEditID,
		ModalTitle: "Edit-Group Result",
		DialogBody: groupresult.DialogNewBodyV1(
			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, groupresult.HandleJSModalAddGR("")),
		DialogAction: groupresult.DialogNewActionV1("/dev/groupresulthandlecloseformedit", "#"+dialogEditBodyID, "outerHTML", "#"+dialogEditID),
		ButtonCLose:  groupresult.BtnCloseNewV1("/dev/groupresulthandlecloseformedit", "#"+dialogEditBodyID, "outerHTML", "#"+dialogEditID),
	})

	//Component modal delete usergroup
	// modalDeletecomponent := groupresult.EmptyDiv1()
	//Component modal delete usergroup
	modalDeletecomponent := groupresult.GroupResultForm(models.GroupResultFormComponent{
		IDComponent: "formgroupresultdelete",
		Link:        "/dev/groupresult/delete",
		HxTarget:    "#" + dialogdeleteBodyID,
		HxSwap:      "outerHTML",
		// HxInclude:   "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogDeleteID, #" + searchID + ", #currpage" + paginationID,
		HxInclude:  "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogDeleteID, #" + searchID + ", #currpage" + paginationID + ", #dialogEditBodyID, #dialogEditID",
		ModalID:    dialogdeleteID,
		ModalTitle: "Delete-User Group",
		DialogBody: groupresult.DeleteConfirmationBody(
			models.CustomTextFieldv2Prm{Type: "hidden", Value: "0", Name: "groupresultid"},
			dialogdeleteBodyID, "Apakah anda yakin menghapus user group berikut ?",
			[]string{"GROUP RESULT NAME", "RESULT FLAG PER TEST", "RESULT FLAG NON LAB", "RESULT RESUME MCU"},
			[]string{"", "", "", ""},
			groupresult.HandleJSModalAddGR(""),
		),
		DialogAction: groupresult.DialogNewActionV1("/dev/usergrouphandlecloseformdelete", "#"+dialogdeleteBodyID, "outerHTML", "#"+dialogdeleteID),
		ButtonCLose:  groupresult.BtnCloseNewV1("/dev/usergrouphandlecloseformdelete", "#"+dialogdeleteBodyID, "outerHTML", "#"+dialogdeleteID),
	})

	//table listing user group component
	contentUserGroupComponent := groupresult.TableGroupResult(
		dataGroupResult, tableID,
		"/dev/groupresultshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/groupresultshowdeleteform",
		"#"+dialogdeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

	//filter user search component
	// customtextfieldsearch.MainCustomTextFieldSearchV1("#"+contentIDSearch, "q", "Cari Nama Staff / Email", "text", "/dev/searchgroupresultv1?"+link, "input changed delay:500ms, search", "#"+contentID, "#indicator", "", contentIDHtmxExtension, "[name='usergroup']")

	userFilterComp := customtextfieldsearch.MainCustomTextFieldSearchV2(
		searchID,
		"search",
		"Cari Group Result Name / Result Resume Mcu",
		"text",
		"/dev/searchgroupresultv1",
		"input changed delay:500ms, search",
		"#"+paginationID, "", "", "outerHTML",
		"#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID")

	// pagination usergroup component
	userGroupResultPaginationComponent := pagination.PaginationV2(
		totalpage,
		1,
		"/dev/groupresultv1pagination",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "",
	)

	//Show user group screen
	si := groupresult.ShowGroupResultV1x(
		"Group Result",
		groupresult.ContentGroupResultV1(
			tableID,
			paginationID,
			searchID,
			dialogAddID,
			dialogAddBodyID,
			dialogEditID,
			dialogEditBodyID,
			dialogdeleteID,
			dialogdeleteBodyID,
			breadcrumbadmin.MainBreadcrumbAdminV1(dataBreadCrumb),
			contentUserGroupComponent,
			userFilterComp,
			userGroupResultPaginationComponent,
			modaladdcomponent,
			modalEditcomponent,
			modalDeletecomponent,
		),

		groupresult.CssMasterGroupResultV1x(),
		groupresult.JSkuGroupResultV1(),
		navbarmenuComponent,
		navbaruserComponent,
		sidebaruserprofileComponent,
	)

	return utils.View(c, si)
}

// PROSES ADD DATA
func (lh *GroupResultHandler) AddGroupResult(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

	// OTHER
	tableID := c.FormValue("tableID")
	paginationID := c.FormValue("paginationID")

	// groupresultid := c.FormValue("groupresultid")
	searchID := c.FormValue("searchID")
	search := c.FormValue("search")
	currPagePrm := c.FormValue("currpage" + paginationID)
	// #dialogAddBodyID, #dialogAddID
	dialogAddBodyID := c.FormValue("dialogAddBodyID")
	dialogAddID := c.FormValue("dialogAddID")
	dialogEditBodyID := c.FormValue("dialogEditBodyID")
	// dialogEditID := c.FormValue("dialogEditID")
	dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
	// dialogDeleteID := c.FormValue("dialogDeleteID")

	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.GroupResultService.GetGroupResultResumeMcu()
	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 := groupresult.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 := groupresult.DialogNewBodyV1(
			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, groupresult.HandleJSModalAddGR(""),
		)
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", "Error converting string to int", "error"),
			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"
	}

	//Form Validation
	if strings.TrimSpace(groupresultname) == "" {
		// Component Dropdown MCU
		listItemResultMcuComponent := groupresult.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)
		test := groupresult.DialogNewBodyV1(
			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, groupresult.HandleJSModalAddGR(""),
		)
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Warning", "Group Result Name Kosong", "warning"),
			test})
		return coba

	}

	//Add user group service
	dataGroupResultAdd, err := lh.GroupResultService.AddGroupResult(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),
		)

		test := groupresult.DialogNewBodyV1(
			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, groupresult.HandleJSModalAddGR(""))
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
			test})
		return coba
	}
	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 data table current page
	dataGroupResultList, totalpage, err := lh.GroupResultService.GetListGroupResult(search, currPage, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET USER GROUP",
			zap.Any("error", err),
		)
		return err
	}

	//New add form
	newForm := groupresult.DialogNewBodyV1(
		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, groupresult.HandleJSModalAddGR("#"+dialogAddID))

	//new table listing
	contentUserGroupComponent := groupresult.TableGroupResult(
		dataGroupResultList, tableID,
		"/dev/usergroupshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/groupresultshowdeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

	//new pagination
	userGroupPaginationComponent := pagination.PaginationV2(totalpage,
		1,
		"/dev/groupresultv1pagination",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID, "outerHTML", "", "true")

	toastSuccess := customtoastv2.CustomToastV2Show("Success", "Success add group result "+groupresultname, "success")

	retval := []templ.Component{toastSuccess, contentUserGroupComponent, userGroupPaginationComponent, newForm}

	return utils.ViewMulti(c, retval)
}

// SEARCH PROSES
func (lh *GroupResultHandler) HandlerShowGroupResultSearchV1(c echo.Context) error {
	search := c.QueryParam("search")
	searchID := c.QueryParam("searchID")
	tableID := c.QueryParam("tableID")
	paginationID := c.QueryParam("paginationID")
	dialogEditBodyID := c.QueryParam("dialogEditBodyID")
	// dialogEditID := c.QueryParam("dialogEditID")
	dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID")
	// dialogDeleteID := c.QueryParam("dialogDeleteID")

	logger, _ := zap.NewProduction()

	dataGroupResult, totalpage, err := lh.GroupResultService.GetListGroupResult(search, 1, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET USER GROUP",
			zap.Any("error", err),
		)
		fmt.Println(dataGroupResult)
		return err
	}

	// totalPages := int(math.Ceil(float64(len(dataUserGroupFiltered)) / float64(rowPerPage)))

	contentUserGroupComponent := groupresult.TableGroupResult(
		dataGroupResult, tableID, "/dev/usergroupshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/groupresultshowdeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

	userGroupResultPaginationComponent := pagination.PaginationV2(totalpage,
		1,
		"/dev/groupresultv1pagination",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML",
		"",
		"",
	)

	// swapTable :=
	// 	mastermenuusergroup.SwapTableUserGroup(userGroupResultPaginationComponent, contentUserGroupComponent)
	retval := []templ.Component{contentUserGroupComponent, userGroupResultPaginationComponent}

	return utils.ViewMulti(c, retval)
	// return utils.View(c, si)
}

// FORM EDIT SHOW
func (lh *GroupResultHandler) HandleEditForm(c echo.Context) error {
	println("Masuk change edit form")

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

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

	// listItem
	dataResultMcu, err := lh.GroupResultService.GetGroupResultResumeMcu()
	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 := groupresult.ItemDropdown(dataResultMcu, 0)

	// get data by id
	dataGroupList, err := lh.GroupResultService.GetGroupResultByIDV1(id)
	if err != nil {
		test := groupresult.DialogNewBodyV1(
			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, groupresult.HandleJSModalAddGRShow("#"+dialogEditID))
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
			test})
		return coba

	}

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

	listItemResultMcuComponentPopulate := groupresult.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)
	form := groupresult.DialogNewBodyV1(
		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, groupresult.HandleJSModalAddGRShow("#"+dialogEditID))
	coba := utils.ViewMulti(c, []templ.Component{form})
	return coba

}

// PROSES EDIT DATA
func (lh *GroupResultHandler) EditGroupResult(c echo.Context) error {

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

	// 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")
	dialogEditBodyID := c.FormValue("dialogEditBodyID")
	dialogEditID := c.FormValue("dialogEditID")
	dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
	currPagePrm := c.FormValue("currpage" + paginationID)

	currPage, err := strconv.Atoi(currPagePrm)

	if err != nil {
		return err
	}
	logger.Info("Edit USER GROUP PARAM",
		zap.Any("id", id),
		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.GroupResultService.GetGroupResultResumeMcu()
	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 := groupresult.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 := groupresult.DialogNewBodyV1(
			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, groupresult.HandleJSModalAddGR(""),
		)
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", "Error converting string to int", "error"),
			test})
		return coba
	}

	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"
	}

	if strings.TrimSpace(groupresultname) == "" {
		listItemResultMcuComponent := groupresult.ItemDropdown(dataResultMcu, idSelectedGroupResultResumeMcu)
		test := groupresult.DialogNewBodyV1(
			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, groupresult.HandleJSModalAddGR(""))
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Warning", "Code and name cannot empty", "warning"),
			test})
		return coba
	}

	dataUserGroup, err := lh.GroupResultService.EditGroupResult(id, groupresultname, flagPerTest, flagNonLab, groupresultresumemcuNew)

	if err != nil {
		listItemResultMcuComponent := groupresult.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),
		)

		test := groupresult.DialogNewBodyV1(
			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, groupresult.HandleJSModalAddGR(""))
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
			test})
		return coba
	}
	logger.Info("ADD USER GROUP",
		zap.Any("return", dataUserGroup),
		zap.Any("groupresultname", groupresultname),
		zap.Any("groupresultflagpertest", groupresultflagpertest),
		zap.Any("groupresultflagnonlab", groupresultflagnonlab),
		zap.Any("groupresultresumemcu", groupresultresumemcu),
	)
	dataGroupList, totalpage, err := lh.GroupResultService.GetListGroupResult(search, currPage, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET GROUP RESULT",
			zap.Any("error", err),
		)
		return err
	}

	newForm := groupresult.DialogNewBodyV1(
		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, groupresult.HandleJSModalAddGR("#"+dialogEditID))

	contentUserGroupComponent := groupresult.TableGroupResult(
		dataGroupList, tableID, "/dev/groupresultshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/groupresultshowdeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

	userGroupPaginationComponent := pagination.PaginationV2(totalpage,
		currPage,
		"/dev/groupresultv1pagination",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID, "outerHTML", "", "true")

	toastSuccess := customtoastv2.CustomToastV2Show("Success", "Success edit Group Result Name : "+groupresultname, "success")
	retval := []templ.Component{toastSuccess, contentUserGroupComponent, userGroupPaginationComponent, newForm}
	// time.Sleep(20 * time.Second)
	return utils.ViewMulti(c, retval)
}

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

	dataGroupList, err := lh.GroupResultService.GetGroupResultByIDV1(id)
	if err != nil {
		// test := mastermenuusergrouptryandy.DialogNewBody(code, name, "", "Name cannot empty")
		test := groupresult.DeleteConfirmationBody(
			models.CustomTextFieldv2Prm{Type: "hidden", Value: "0", Name: "groupresultid"},
			dialogDeleteBodyID, "Apakah anda yakin menghapus user group berikut ?",
			[]string{"GROUP RESULT NAME", "RESULT FLAG PER TEST", "RESULT FLAG NON LAB", "RESULT RESUME MCU"},
			[]string{"", "", "", ""},
			groupresult.HandleJSModalAddGR(""),
		)
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
			test})
		return coba
	}

	form := groupresult.DeleteConfirmationBody(
		models.CustomTextFieldv2Prm{Type: "hidden", Value: strconv.Itoa(dataGroupList.Group_ResultID), Name: "groupresultid"},
		dialogDeleteBodyID, "Apakah anda yakin menghapus user group berikut ?",
		[]string{"GROUP RESULT NAME", "RESULT FLAG PER TEST", "RESULT FLAG NON LAB", "RESULT RESUME MCU"},
		[]string{dataGroupList.Group_ResultName, dataGroupList.Group_ResultFlagPerTest, dataGroupList.Group_ResultFlagNonLab, dataGroupList.Group_ResultResumeMcu},
		groupresult.HandleJSModalAddGRShow("#"+dialogDeleteID),
	)
	coba := utils.ViewMulti(c, []templ.Component{form})
	return coba
}

// CLOSE FORM DELETE
func (lh *GroupResultHandler) HandleCloseFormDelete(c echo.Context) error {
	dialogDeleteID := c.FormValue("dialogDeleteID")
	dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
	form := groupresult.DeleteConfirmationBody(
		models.CustomTextFieldv2Prm{Type: "hidden", Value: "0", Name: "groupresultid"},
		dialogDeleteBodyID, "Apakah anda yakin menghapus user group berikut ?",
		[]string{"GROUP RESULT NAME", "RESULT FLAG PER TEST", "RESULT FLAG NON LAB", "RESULT RESUME MCU"},
		[]string{"", "", "", ""},
		groupresult.HandleJSModalAddGR("#"+dialogDeleteID))
	return utils.View(c, form)
}

// PROSES DELETE
func (lh *GroupResultHandler) DeleteGroupResult(c echo.Context) error {

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

	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)
	dialogDeleteID := c.FormValue("dialogDeleteID")
	dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
	// dialogEditID := c.FormValue("dialogEditID")
	dialogEditBodyID := c.FormValue("dialogEditBodyID")

	currPage, err := strconv.Atoi(currPagePrm)

	if err != nil {
		return err
	}

	dataGrupResult, err := lh.GroupResultService.DeleteGroupResult(id)

	if err != nil {
		logger.Info("Error",
			zap.Any("Error", err),
			zap.Any("prm", id),
		)
		return err
	}
	logger.Info("DELETE USER GROUP handler",
		zap.Any("return", dataGrupResult),
		zap.Any("prm", id),
	)
	dataGroupList, totalpage, err := lh.GroupResultService.GetListGroupResult(search, currPage, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET USER GROUP",
			zap.Any("error", err),
		)
		return err
	}
	newForm := mastermenuusergroup.DeleteConfirmationBody(
		models.CustomTextFieldv2Prm{Type: "hidden", Value: "0", Name: "usergroupid"},
		dialogDeleteBodyID, "Apakah anda yakin menghapus user group berikut ?",
		[]string{"Kode", "User Group"},
		[]string{"", ""},
		mastermenuusergroup.HandleJSModalAddUG("#"+dialogDeleteID),
	)
	if len(dataGroupList) == 0 && totalpage > 1 {
		currPage = currPage - 1
		dataGroupList, _, err = lh.GroupResultService.GetListGroupResult(search, currPage, 5)
		if err != nil {
			defer logger.Sync()
			logger.Info("ERROR GET GROUP RESULT",
				zap.Any("error", err),
			)
			return err
		}
	}
	contentUserGroupComponent := groupresult.TableGroupResult(
		dataGroupList, tableID,
		"/dev/groupresultshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/groupresultshowdeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

	groupResultPaginationComponent := pagination.PaginationV2(totalpage,
		currPage,
		"/dev/groupresultv1pagination",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID, "outerHTML", "", "true")

	toastSuccess := customtoastv2.CustomToastV2Show("Success", "Success delete group result ", "success")
	retval := []templ.Component{toastSuccess, contentUserGroupComponent, groupResultPaginationComponent, newForm}
	// time.Sleep(20 * time.Second)
	return utils.ViewMulti(c, retval)
}
