package dev_handlers

import (
	"fmt"
	"strings"

	"strconv"
	"time"

	"cpone/component/pagination"
	tablecomponent "cpone/component/table"
	"cpone/models"
	"cpone/utils"
	mastermenuusergroup "cpone/views/dev/mastermenuusergroup"
	"cpone/views/dev/mastermenuusergrouptryandy"

	globalservices "cpone/services"
	services "cpone/services/dev"

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

	breadcrumbadmin "cpone/component/breadcrumbadmin"
	customtextfieldsearch "cpone/component/customtextfieldsearch"
	navbarmenu "cpone/component/navbar"
	sidebaruserprofile "cpone/component/sidebar_user_profile"
	customtoastv2 "cpone/component/toastbootstrap"
)

type MasterMenuUserGroupService interface {
	GetUserGroup() ([]models.UserGroup, error)
	GetUserGroupByID(id string) (models.UserGroup, error)
	// try
	GetListMasterUserGroup() ([]models.UserGroupV1, error)
	GetListBreadCrumb(title string) (models.BreadCrumbV1, error)
	AddUserGroup(code string, name string) (models.UserGroupV1, error)
	EditUserGroup(id string, code string, name string) (models.UserGroupV1, error)
	DeleteUserGroup(id string) (models.UserGroupV1, error)
	GetListMasterUserGroupV2(search string, currentPage int, rowPerPage int) ([]models.UserGroupV1, int, error)
	GetUserGroupByIDV1(id string) (models.UserGroupV1, error)
}

func NewMasterMenuUserGroupHandler(us MasterMenuUserGroupService) *MasterMenuUserGroupHandler {
	return &MasterMenuUserGroupHandler{
		MasterMenuUserGroupService: us,
	}
}

type MasterMenuUserGroupHandler struct {
	MasterMenuUserGroupService MasterMenuUserGroupService
}

func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroup(c echo.Context) error {
	dataMenu, err := globalservices.GetMenu()
	fmt.Println(dataMenu)
	fmt.Println(err)
	if err != nil {
		fmt.Println(dataMenu)
		return err
	}
	dataUser, err := services.GetUser()
	fmt.Println(dataUser)
	fmt.Println(err)
	if err != nil {
		fmt.Println(dataUser)
		return err
	}
	dataUserGroup, err := lh.MasterMenuUserGroupService.GetUserGroup()

	if err != nil {
		fmt.Println(dataUserGroup)
		return err
	}

	contentID := utils.GenerateRandomID("tablebody")

	logger, _ := zap.NewProduction()
	defer logger.Sync()
	logger.Info("LOAD USER GROUP DEV",
		zap.String("id", contentID),
		zap.Any("data", dataUserGroup),
	)
	// si := mastermenuusergroup.ShowMasterMenuUserGroup(
	// 	"Master Menu",
	// 	mastermenuusergroup.ContentMasterMenuUserGroup(dataUserGroup, contentID),
	// 	mastermenuusergroup.CssMasterMenuUserGroup(),
	// 	mastermenuusergroup.JsMasterMenuUserGroup(),
	// 	dataMenu,
	// 	dataUser,
	// )

	si := mastermenuusergroup.ContentMasterMenuUserGroup(dataUserGroup, contentID)

	return utils.View(c, si)
}

func (lh *MasterMenuUserGroupHandler) HandleChangePage(c echo.Context) error {
	page := c.QueryParam("page")
	currPage := c.QueryParam("currentPage")
	contentID := c.QueryParam("contentID")
	dataUserGroup, err := lh.MasterMenuUserGroupService.GetUserGroup()

	if err != nil {
		fmt.Println(dataUserGroup)
		return err
	}
	pageInt, err := strconv.Atoi(page)
	if err != nil {
		fmt.Println("page err")
		return err
	}
	currPageInt, err := strconv.Atoi(currPage)
	if err != nil {
		fmt.Println("currpage err")
		return err
	}
	logger, _ := zap.NewProduction()
	defer logger.Sync()
	logger.Info("CHANGE PAGE USER GROUP DEV",
		zap.String("id", contentID),
		zap.Any("data", dataUserGroup),
	)
	time.Sleep(3 * time.Second)
	// time.Sleep(5 * time.Second)
	vw := tablecomponent.TableV1([]string{"KODE", "USERGROUP", "AKSI"},
		[]string{"40%", "40%", "20%"},
		mastermenuusergroup.TableRow(dataUserGroup),
		pagination.Pagination(pageInt, currPageInt, "dev/usergroup/pagination", contentID),
		contentID,
	)

	return utils.View(c, vw)
}

// try
func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupV1(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
	}

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

	// si := mastermenuusergroup.ListMasterUserGroupInitial(dataUserGroup)

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

	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 User Group"

	dataBreadCrumb, err := lh.MasterMenuUserGroupService.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)

	//Component modal add usergroup

	modaladdcomponent := mastermenuusergroup.UserGroupForm(models.UserGroupFormComponent{
		IDComponent: "formusergroup",
		Link:        "/dev/usergroup/add",
		HxTarget:    "#" + dialogAddBodyID,
		HxSwap:      "outerHTML",
		HxInclude:   "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID,
		ModalID:     dialogAddID,
		ModalTitle:  "New-User Group",
		DialogBody: mastermenuusergroup.DialogNewBodyV1(
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroupcode",
				Placeholder: "Kode user group",
				Type:        "text", ID: "usergroupinputname"},
			models.CustomTextFieldv2Prm{
				Label:       "Nama User Group",
				Name:        "usergroupname",
				Placeholder: "Nama user group",
				Type:        "text", ID: "usergroupinputname"},
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroupid",
				Placeholder: "Kode user group",
				Type:        "hidden", ID: "usergroupinputid"},
			dialogAddBodyID, mastermenuusergroup.HandleJSModalAddUG("")),
		DialogAction: mastermenuusergroup.DialogNewActionV1("/dev/usergrouphandlecloseform", "#"+dialogAddBodyID, "outerHTML", "#"+dialogAddID),
		ButtonCLose:  mastermenuusergroup.BtnCloseNewV1("/dev/usergrouphandlecloseform", "#"+dialogAddBodyID, "outerHTML", "#"+dialogAddID),
	})

	//Component modal edit usergroup
	modalEditcomponent := mastermenuusergroup.UserGroupForm(models.UserGroupFormComponent{
		IDComponent: "formusergroupedit",
		Link:        "/dev/usergroup/edit",
		HxTarget:    "#" + dialogEditBodyID,
		HxSwap:      "outerHTML",
		HxInclude:   "#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID,
		ModalID:     dialogEditID,
		ModalTitle:  "Edit-User Group",
		DialogBody: mastermenuusergroup.DialogNewBodyV1(
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroupcode",
				Placeholder: "Kode user group",
				Type:        "text"},
			models.CustomTextFieldv2Prm{
				Label:       "Nama User Group",
				Name:        "usergroupname",
				Placeholder: "Nama user group",
				Type:        "text"},
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroupid",
				Placeholder: "Kode user group",
				Type:        "hidden"},
			dialogEditBodyID, mastermenuusergroup.HandleJSModalAddUG("")),
		DialogAction: mastermenuusergroup.DialogNewActionV1("/dev/usergrouphandlecloseformedit", "#"+dialogEditBodyID, "outerHTML", "#"+dialogEditID),
		ButtonCLose:  mastermenuusergroup.BtnCloseNewV1("/dev/usergrouphandlecloseformedit", "#"+dialogEditBodyID, "outerHTML", "#"+dialogEditID),
	})

	//Component modal delete usergroup
	modalDeletecomponent := mastermenuusergroup.UserGroupForm(models.UserGroupFormComponent{
		IDComponent: "formusergroupdelete",
		Link:        "/dev/usergroup/delete",
		HxTarget:    "#" + dialogdeleteBodyID,
		HxSwap:      "outerHTML",
		HxInclude:   "#tableID, #paginationID, #searchID,#dialogDeleteBodyID, #dialogDeleteID, #" + searchID + ", #currpage" + paginationID,
		ModalID:     dialogdeleteID,
		ModalTitle:  "Delete-User Group",
		DialogBody: 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(""),
		),
		DialogAction: mastermenuusergroup.DialogNewActionV1("/dev/usergrouphandlecloseformdelete", "#"+dialogdeleteBodyID, "outerHTML", "#"+dialogdeleteID),
		ButtonCLose:  mastermenuusergroup.BtnCloseNewV1("/dev/usergrouphandlecloseformdelete", "#"+dialogdeleteBodyID, "outerHTML", "#"+dialogdeleteID),
	})

	//table listing user group component
	contentUserGroupComponent := mastermenuusergroup.TableUserGroup(
		dataUserGroup, tableID,
		"/dev/usergroupshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/usergroupshowdeleteform",
		"#"+dialogdeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

	//filter user group component
	usergroupFilterComponent := customtextfieldsearch.MainCustomTextFieldSearchV2(searchID,
		"search",
		"Cari Kode/Nama",
		"text",
		"/dev/searchusergroupv1",
		"input changed delay:500ms, search",
		"#"+paginationID, "", "", "outerHTML", "#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID")
	// pagination usergroup component
	userGroupPaginationComponent := pagination.PaginationV2(
		totalpage,
		1,
		"/dev/usergroupv1pagination",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "",
	)

	//Show user group screen
	si := mastermenuusergroup.ShowMasterMenuUserGroupV1x(
		"Master Menu",
		mastermenuusergroup.ContentMasterMenuUserGroupV1(
			tableID, paginationID, searchID, dialogAddID, dialogAddBodyID, dialogEditID, dialogEditBodyID, dialogdeleteID, dialogdeleteBodyID,
			breadcrumbadmin.MainBreadcrumbAdminV1(dataBreadCrumb),
			contentUserGroupComponent,
			usergroupFilterComponent,
			userGroupPaginationComponent,
			modaladdcomponent,
			modalEditcomponent,
			modalDeletecomponent,
		),

		mastermenuusergroup.CssMasterMenuUserGroupV1x(),
		mastermenuusergroup.JSkuV1(),
		navbarmenuComponent,
		navbaruserComponent,
		sidebaruserprofileComponent,
	)

	return utils.View(c, si)
}

func (lh *MasterMenuUserGroupHandler) HandlerShowBreadCrumbV1(c echo.Context) error {
	logger, _ := zap.NewProduction()
	paramTitleBreadcrumbConvert := "Master User Group"

	dataBreadCrumb, err := lh.MasterMenuUserGroupService.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
	}

	// si := mastermenuusergroup.ListMasterUserGroupInitial(dataBreadCrumb)

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

	// si := breadcrumbadmin.MainBreadcrumbAdminV1(dataBreadCrumb)

	si := mastermenuusergroup.ShowMasterMenuUserGroupV1(
		"Master Menu",
		breadcrumbadmin.MainBreadcrumbAdminV1(dataBreadCrumb),
		mastermenuusergroup.CssMasterMenuUserGroupV1(),
		mastermenuusergroup.JsMasterMenuUserGroupV1(),
	)

	return utils.View(c, si)
}
func (lh *MasterMenuUserGroupHandler) AddUserGroup(c echo.Context) error {
	logger, _ := zap.NewProduction()
	defer logger.Sync()

	//prm form addusergroup
	code := c.FormValue("usergroupcode")
	name := c.FormValue("usergroupname")
	tableID := c.FormValue("tableID")
	paginationID := c.FormValue("paginationID")
	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("code", code),
		zap.Any("nama", name),
		zap.Any("tableid", tableID),
		zap.Any("search", search),
		zap.Any("currpage", currPage),
	)
	//Form Validation
	if strings.TrimSpace(code) == "" && strings.TrimSpace(name) == "" {
		test := mastermenuusergroup.DialogNewBodyV1(
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroucode",
				Placeholder: "Kode user group",
				Type:        "text",
				Value:       code,
				ID:          "usergroupinputname",
				ErrorMsg:    "Code cannot empty"},
			models.CustomTextFieldv2Prm{
				Label:       "Nama User Group",
				Name:        "usergroupname",
				Placeholder: "Nama user group",
				Type:        "text",
				Value:       name,
				ID:          "usergroupinputname",
				ErrorMsg:    "Name cannot empty"},
			models.CustomTextFieldv2Prm{Label: "Kode User Group",
				Name:        "usergroupid",
				Placeholder: "Kode user group",
				Type:        "hidden",
				ID:          "usergroupinputid"},
			dialogAddBodyID, mastermenuusergroup.HandleJSModalAddUG(""))
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Warning", "Code and name cannot empty", "warning"),
			test})
		return coba

	}
	if strings.TrimSpace(code) == "" {
		test := mastermenuusergroup.DialogNewBodyV1(
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroupcode",
				Placeholder: "Kode user group",
				Type:        "text",
				Value:       code,
				ID:          "usergroupinputname",
				ErrorMsg:    "Code cannot empty"},
			models.CustomTextFieldv2Prm{
				Label:       "Nama User Group",
				Name:        "usergroupname",
				Placeholder: "Nama user group",
				Type:        "text",
				Value:       name,
				ID:          "usergroupinputname",
			},
			models.CustomTextFieldv2Prm{Label: "Kode User Group",
				Name:        "usergroupid",
				Placeholder: "Kode user group",
				Type:        "hidden",
				ID:          "usergroupinputid"},
			dialogAddBodyID, mastermenuusergroup.HandleJSModalAddUG(""))
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Warning", "Code cannot empty", "warning"),
			test})
		return coba

	}

	if strings.TrimSpace(name) == "" {
		test := mastermenuusergroup.DialogNewBodyV1(
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroupcode",
				Placeholder: "Kode user group",
				Type:        "text",
				Value:       code,
				ID:          "usergroupinputname",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama User Group",
				Name:        "usergroupname",
				Placeholder: "Nama user group",
				Type:        "text",
				Value:       name,
				ID:          "usergroupinputname",
				ErrorMsg:    "Name cannot empty",
			},
			models.CustomTextFieldv2Prm{Label: "Kode User Group",
				Name:        "usergroupid",
				Placeholder: "Kode user group",
				Type:        "hidden",
				ID:          "usergroupinputid"},
			dialogAddBodyID, mastermenuusergroup.HandleJSModalAddUG(""))
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Warning", "Name cannot empty", "warning"),
			test})
		return coba

	}

	//Add user group service
	dataUserGroup, err := lh.MasterMenuUserGroupService.AddUserGroup(code, name)

	if err != nil {
		logger.Info("Error",
			zap.Any("Error", err),
			zap.Any("code", code),
			zap.Any("name", name),
		)

		test := mastermenuusergroup.DialogNewBodyV1(
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroupcode",
				Placeholder: "Kode user group",
				Type:        "text",
				Value:       code,
				ID:          "usergroupinputname",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama User Group",
				Name:        "usergroupname",
				Placeholder: "Nama user group",
				Type:        "text",
				Value:       name,
				ID:          "usergroupinputname",
			},
			models.CustomTextFieldv2Prm{Label: "Kode User Group",
				Name:        "usergroupid",
				Placeholder: "Kode user group",
				Type:        "hidden",
				ID:          "usergroupinputid"},
			dialogAddBodyID, mastermenuusergroup.HandleJSModalAddUG(""))
		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("code", code),
		zap.Any("name", name),
	)

	//Get data table current page
	dataUserGroupList, totalpage, err := lh.MasterMenuUserGroupService.GetListMasterUserGroupV2(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 := mastermenuusergroup.DialogNewBodyV1(
		models.CustomTextFieldv2Prm{
			Label:       "Kode User Group",
			Name:        "usergroupcode",
			Placeholder: "Kode user group",
			Type:        "text",
			Value:       "",
			ID:          "usergroupinputname",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Nama User Group",
			Name:        "usergroupname",
			Placeholder: "Nama user group",
			Type:        "text",
			Value:       "",
			ID:          "usergroupinputname",
		},
		models.CustomTextFieldv2Prm{Label: "Kode User Group",
			Name:        "usergroupid",
			Placeholder: "Kode user group",
			Type:        "hidden",
			ID:          "usergroupinputid"},
		dialogAddBodyID, mastermenuusergroup.HandleJSModalAddUG("#"+dialogAddID))

	//new table listing
	contentUserGroupComponent := mastermenuusergroup.TableUserGroup(
		dataUserGroupList, tableID,
		"/dev/usergroupshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/usergroupshowdeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

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

	toastSuccess := customtoastv2.CustomToastV2Show("Success", "Success add user group "+name, "success")

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

	return utils.ViewMulti(c, retval)
}
func (lh *MasterMenuUserGroupHandler) EditUserGroup(c echo.Context) error {

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

	code := c.FormValue("usergroupcode")
	name := c.FormValue("usergroupname")
	id := c.FormValue("usergroupid")
	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("code", code),
		zap.Any("nama", name),
		zap.Any("tableid", tableID),
		zap.Any("search", search),
		zap.Any("currpage", currPage),
	)
	if strings.TrimSpace(code) == "" && strings.TrimSpace(name) == "" {
		test := mastermenuusergroup.DialogNewBodyV1(
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroucode",
				Placeholder: "Kode user group",
				Type:        "text",
				Value:       code,
				ID:          "usergroupinputname",
				ErrorMsg:    "Code cannot empty"},
			models.CustomTextFieldv2Prm{
				Label:       "Nama User Group",
				Name:        "usergroupname",
				Placeholder: "Nama user group",
				Type:        "text",
				Value:       name,
				ID:          "usergroupinputname",
				ErrorMsg:    "Name cannot empty"},
			models.CustomTextFieldv2Prm{Label: "Kode User Group",
				Name:        "usergroupid",
				Placeholder: "Kode user group",
				Type:        "hidden",
				Value:       id,
				ID:          "usergroupinputid"},
			dialogEditBodyID, mastermenuusergroup.HandleJSModalAddUG(""))
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Warning", "Code and name cannot empty", "warning"),
			test})
		return coba

	}
	if strings.TrimSpace(code) == "" {
		// test := mastermenuusergrouptryandy.CobaSwapOOB(code, name, "Code cannot empty", "")
		test := mastermenuusergroup.DialogNewBodyV1(
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroupcode",
				Placeholder: "Kode user group",
				Type:        "text",
				Value:       code,
				ID:          "usergroupinputname",
				ErrorMsg:    "Code cannot empty"},
			models.CustomTextFieldv2Prm{
				Label:       "Nama User Group",
				Name:        "usergroupname",
				Placeholder: "Nama user group",
				Type:        "text",
				Value:       name,
				ID:          "usergroupinputname",
			},
			models.CustomTextFieldv2Prm{Label: "Kode User Group",
				Name:        "usergroupid",
				Placeholder: "Kode user group",
				Type:        "hidden",
				Value:       id,
				ID:          "usergroupinputid"},
			dialogEditBodyID, mastermenuusergroup.HandleJSModalAddUG(""))
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Warning", "Code cannot empty", "warning"),
			test})
		return coba

	}

	if strings.TrimSpace(name) == "" {
		// test := mastermenuusergrouptryandy.DialogNewBody(code, name, "", "Name cannot empty")
		test := mastermenuusergroup.DialogNewBodyV1(
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroupcode",
				Placeholder: "Kode user group",
				Type:        "text",
				Value:       code,
				ID:          "usergroupinputname",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama User Group",
				Name:        "usergroupname",
				Placeholder: "Nama user group",
				Type:        "text",
				Value:       name,
				ID:          "usergroupinputname",
				ErrorMsg:    "Name cannot empty",
			},
			models.CustomTextFieldv2Prm{Label: "Kode User Group",
				Name:        "usergroupid",
				Placeholder: "Kode user group",
				Value:       id,
				Type:        "hidden",
				ID:          "usergroupinputid"},
			dialogEditBodyID, mastermenuusergroup.HandleJSModalAddUG(""))
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Warning", "Name cannot empty", "warning"),
			test})
		return coba

	}
	dataUserGroup, err := lh.MasterMenuUserGroupService.EditUserGroup(id, code, name)

	if err != nil {
		logger.Info("Error",
			zap.Any("Error", err),
			zap.Any("code", code),
			zap.Any("name", name),
		)

		test := mastermenuusergroup.DialogNewBodyV1(
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroupcode",
				Placeholder: "Kode user group",
				Type:        "text",
				Value:       code,
				ID:          "usergroupinputname",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama User Group",
				Name:        "usergroupname",
				Placeholder: "Nama user group",
				Type:        "text",
				Value:       name,
				ID:          "usergroupinputname",
			},
			models.CustomTextFieldv2Prm{Label: "Kode User Group",
				Name:        "usergroupid",
				Placeholder: "Kode user group",
				Type:        "hidden",
				Value:       id,
				ID:          "usergroupinputid"},
			dialogEditBodyID, mastermenuusergroup.HandleJSModalAddUG(""))
		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("code", code),
		zap.Any("name", name),
	)
	dataUserGroupList, totalpage, err := lh.MasterMenuUserGroupService.GetListMasterUserGroupV2(search, currPage, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET USER GROUP",
			zap.Any("error", err),
		)
		return err
	}

	newForm := mastermenuusergroup.DialogNewBodyV1(
		models.CustomTextFieldv2Prm{
			Label:       "Kode User Group",
			Name:        "usergroupcode",
			Placeholder: "Kode user group",
			Type:        "text",
			Value:       "",
			ID:          "usergroupinputname",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Nama User Group",
			Name:        "usergroupname",
			Placeholder: "Nama user group",
			Type:        "text",
			Value:       "",
			ID:          "usergroupinputname",
		},
		models.CustomTextFieldv2Prm{Label: "Kode User Group",
			Name:        "usergroupid",
			Placeholder: "Kode user group",
			Type:        "hidden",
			ID:          "usergroupinputid"},
		dialogEditBodyID, mastermenuusergroup.HandleJSModalAddUG("#"+dialogEditID))

	contentUserGroupComponent := mastermenuusergroup.TableUserGroup(
		dataUserGroupList, tableID, "/dev/usergroupshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/usergroupshowdeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

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

	toastSuccess := customtoastv2.CustomToastV2Show("Success", "Success edit user group "+name, "success")
	retval := []templ.Component{toastSuccess, contentUserGroupComponent, userGroupPaginationComponent, newForm}
	// time.Sleep(20 * time.Second)
	return utils.ViewMulti(c, retval)
}
func (lh *MasterMenuUserGroupHandler) DeleteUserGroup(c echo.Context) error {

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

	id := c.FormValue("usergroupid")
	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
	}

	dataUserGroup, err := lh.MasterMenuUserGroupService.DeleteUserGroup(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", dataUserGroup),
		zap.Any("prm", id),
	)
	dataUserGroupList, totalpage, err := lh.MasterMenuUserGroupService.GetListMasterUserGroupV2(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(dataUserGroupList) == 0 && totalpage > 1 {
		currPage = currPage - 1
		dataUserGroupList, _, err = lh.MasterMenuUserGroupService.GetListMasterUserGroupV2(search, currPage, 5)
		if err != nil {
			defer logger.Sync()
			logger.Info("ERROR GET USER GROUP",
				zap.Any("error", err),
			)
			return err
		}
	}
	contentUserGroupComponent := mastermenuusergroup.TableUserGroup(
		dataUserGroupList, tableID,
		"/dev/usergroupshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/usergroupshowdeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

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

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

func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupSearchV1(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()

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

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

	contentUserGroupComponent := mastermenuusergroup.TableUserGroup(
		dataUserGroup, tableID, "/dev/usergroupshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/usergroupshowdeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

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

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

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

func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupPaginationV1(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
	}

	dataUserGroup, totalpage, err := lh.MasterMenuUserGroupService.GetListMasterUserGroupV2(search, page, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET USER GROUP",
			zap.Any("error", err),
		)
		fmt.Println(dataUserGroup)
		return err
	}

	contentUserGroupComponent := mastermenuusergroup.TableUserGroup(
		dataUserGroup, tableID, "/dev/usergroupshoweditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/usergroupshowdeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #dialogEditID")

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

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

	return utils.ViewMulti(c, retval)
}

// Coba Anndy
func (lh *MasterMenuUserGroupHandler) HandlerShowMasterMenuUserGroupTryAndy(c echo.Context) error {
	logger, _ := zap.NewProduction()
	dataMenu, err := globalservices.GetMenu()
	fmt.Println(dataMenu)
	fmt.Println(err)
	if err != nil {
		fmt.Println(dataMenu)
		return err
	}

	dataUser, err := services.GetUser()
	fmt.Println(dataUser)
	fmt.Println(err)
	if err != nil {
		fmt.Println(dataUser)
		return err
	}

	dataUserGroup, err := lh.MasterMenuUserGroupService.GetListMasterUserGroup()
	fmt.Println(dataUserGroup)
	fmt.Println(err)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR LIST USER GROUP DEV",
			zap.Any("error", err),
		)
		fmt.Println(dataUserGroup)
		return err
	}

	// si := mastermenuusergroup.ListMasterUserGroupInitial(dataUserGroup)

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

	// si := mastermenuusergroup.ListMasterUserGroupInitial(dataUserGroup)

	// si := mastermenuusergroup.ShowMasterMenuUserGroupV1(
	// 	"Master Menu",
	// 	mastermenuusergroup.ListMasterUserGroupInitial(dataUserGroup),
	// 	mastermenuusergroup.CssMasterMenuUserGroupV1(),
	// 	mastermenuusergroup.JsMasterMenuUserGroupV1(),
	// )

	contentID := utils.GenerateRandomID("tablebody")

	paramTitleBreadcrumbConvert := "Master User Group"

	dataBreadCrumb, err := lh.MasterMenuUserGroupService.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
	}

	// si := mastermenuusergroup.ListMasterUserGroupInitial(dataBreadCrumb)

	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)

	// inputan search
	inputansearchComponent := customtextfieldsearch.MainCustomTextFieldSearch("q", "Cari User Group", "text", "", "", "", "")

	// table user group
	tabelusergroupComponent := tablecomponent.Table(
		[]string{"KODE", "USERGROUP", "AKSI"},
		[]string{"40%", "40%", "20%"},
		mastermenuusergrouptryandy.TableRowV1(dataUserGroup),
		pagination.Pagination(20, 1, "", contentID),
	)

	si := mastermenuusergrouptryandy.ShowMasterMenuUserGroupV1x(
		"Master Menu",
		mastermenuusergrouptryandy.ContentMasterMenuUserGroupV1(
			contentID,
			breadcrumbadmin.MainBreadcrumbAdminV1(dataBreadCrumb),
			tabelusergroupComponent,
			inputansearchComponent,
		),

		mastermenuusergrouptryandy.CssMasterMenuUserGroupV1x(),
		mastermenuusergrouptryandy.JSkuV1(),
		navbarmenuComponent,
		navbaruserComponent,
		sidebaruserprofileComponent,
	)

	return utils.View(c, si)
}

func (lh *MasterMenuUserGroupHandler) HandlerHideToast(c echo.Context) error {
	toastComponent := customtoastv2.CustomToastV2Hide()

	si := toastComponent

	return utils.View(c, si)
}

func (lh *MasterMenuUserGroupHandler) HandleCloseForm(c echo.Context) error {
	// #dialogAddBodyID, #dialogAddID
	dialogAddBodyID := c.FormValue("dialogAddBodyID")
	form := mastermenuusergroup.DialogNewBodyV1(
		models.CustomTextFieldv2Prm{
			Label:       "Kode User Group",
			Name:        "usergroupcode",
			Placeholder: "Kode user group",
			Type:        "text", ID: "usergroupinputname"},
		models.CustomTextFieldv2Prm{
			Label:       "Nama User Group",
			Name:        "usergroupname",
			Placeholder: "Nama user group",
			Type:        "text", ID: "usergroupinputname"},
		models.CustomTextFieldv2Prm{
			Label:       "Kode User Group",
			Name:        "usergroupid",
			Placeholder: "Kode user group",
			Type:        "hidden", ID: "usergroupinputid"},
		dialogAddBodyID, mastermenuusergroup.HandleJSModalAddUG(""))
	return utils.View(c, form)
}
func (lh *MasterMenuUserGroupHandler) HandleCloseFormEdit(c echo.Context) error {
	dialogEditBodyID := c.FormValue("dialogEditBodyID")
	form := mastermenuusergroup.DialogNewBodyV1(
		models.CustomTextFieldv2Prm{
			Label:       "Kode User Group",
			Name:        "usergroupcode",
			Placeholder: "Kode user group",
			Type:        "text", ID: "usergroupinputname"},
		models.CustomTextFieldv2Prm{
			Label:       "Nama User Group",
			Name:        "usergroupname",
			Placeholder: "Nama user group",
			Type:        "text", ID: "usergroupinputname"},
		models.CustomTextFieldv2Prm{
			Label:       "Kode User Group",
			Name:        "usergroupid",
			Placeholder: "Kode user group",
			Type:        "hidden", ID: "usergroupinputid"},
		dialogEditBodyID, mastermenuusergroup.HandleJSModalAddUG(""))
	return utils.View(c, form)
}
func (lh *MasterMenuUserGroupHandler) HandleEditForm(c echo.Context) error {
	println("Masuk change edit form")

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

	dataUserGroup, err := lh.MasterMenuUserGroupService.GetUserGroupByIDV1(id)
	if err != nil {
		// test := mastermenuusergrouptryandy.DialogNewBody(code, name, "", "Name cannot empty")
		test := mastermenuusergroup.DialogNewBodyV1(
			models.CustomTextFieldv2Prm{
				Label:       "Kode User Group",
				Name:        "usergroupcode",
				Placeholder: "Kode user group",
				Type:        "text",
				Value:       "",
				ID:          "usergroupinputname",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama User Group",
				Name:        "usergroupname",
				Placeholder: "Nama user group",
				Type:        "text",
				Value:       "",
				ID:          "usergroupinputname",
			},
			models.CustomTextFieldv2Prm{Label: "Kode User Group",
				Name:        "usergroupid",
				Placeholder: "Kode user group",
				Type:        "hidden",
				ID:          "usergroupinputid"},
			dialogEditBodyID, mastermenuusergroup.HandleJSModalAddUGShow("#"+dialogEditID))
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
			test})
		return coba

	}

	form := mastermenuusergroup.DialogNewBodyV1(
		models.CustomTextFieldv2Prm{
			Label:       "Kode User Group",
			Name:        "usergroupcode",
			Placeholder: "Kode user group",
			Type:        "text",
			Value:       dataUserGroup.M_UserGroupCode,
		},
		models.CustomTextFieldv2Prm{
			Label:       "Nama User Group",
			Name:        "usergroupname",
			Placeholder: "Nama user group",
			Type:        "text",
			Value:       dataUserGroup.M_UserGroupName,
		},
		models.CustomTextFieldv2Prm{Label: "Kode User Group",
			Name:        "usergroupid",
			Placeholder: "Kode user group",
			Type:        "hidden",
			Value:       strconv.Itoa(dataUserGroup.M_UserGroupID),
			ID:          "usergroupinputid"},
		dialogEditBodyID, mastermenuusergroup.HandleJSModalAddUGShow("#"+dialogEditID))
	coba := utils.ViewMulti(c, []templ.Component{form})
	return coba

}
func (lh *MasterMenuUserGroupHandler) HandleDeleteForm(c echo.Context) error {
	id := c.QueryParam("id")
	dialogDeleteID := c.QueryParam("dialogDeleteID")
	dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID")
	dataUserGroup, err := lh.MasterMenuUserGroupService.GetUserGroupByIDV1(id)
	if err != nil {
		// test := mastermenuusergrouptryandy.DialogNewBody(code, name, "", "Name cannot empty")
		test := 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(""),
		)
		coba := utils.ViewMulti(c, []templ.Component{
			customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"),
			test})
		return coba

	}

	form := mastermenuusergroup.DeleteConfirmationBody(
		models.CustomTextFieldv2Prm{Type: "hidden", Value: strconv.Itoa(dataUserGroup.M_UserGroupID), Name: "usergroupid"},
		dialogDeleteBodyID, "Apakah anda yakin menghapus user group berikut ?",
		[]string{"Kode", "User Group"},
		[]string{dataUserGroup.M_UserGroupCode, dataUserGroup.M_UserGroupName},
		mastermenuusergroup.HandleJSModalAddUGShow("#"+dialogDeleteID),
	)
	coba := utils.ViewMulti(c, []templ.Component{form})
	return coba
}
func (lh *MasterMenuUserGroupHandler) HandleCloseFormDelete(c echo.Context) error {
	dialogDeleteID := c.FormValue("dialogDeleteID")
	dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
	form := 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))
	return utils.View(c, form)
}
