package dev_handlers

import (
	breadcrumbadmin "cpone/component/breadcrumbadmin"
	"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_mdsamplestationview "cpone/views/dev/mdsamplestation"
	"fmt"
	"strconv"
	"strings"

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

type MDSampleStationServices interface {
	GetMDSampleStationBreadcrumb() (models.BreadCrumbV1, error)
	GetListSampleStation(search string, currentPage int, rowPerPage int) ([]models.MDSampleStation, int, error)
	GetMDSampleStationByID(id string) (models.MDSampleStation, error)
	GetListGroupSampleStation() ([]models.MDSampleStationGroup, error)
	AddMDSampleStation(code string, name string, group string) (models.MDSampleStation, error)
	EditMDSampleStation(id string, code string, name string, group string) (models.MDSampleStation, error)
	DeleteMDSampleStation(id string) (models.MDSampleStation, error)
}

func NewMDSampleStationHandler(ss MDSampleStationServices) *MDSampleStationHandler {
	return &MDSampleStationHandler{
		MDSampleStationServices: ss,
	}
}

type MDSampleStationHandler struct {
	MDSampleStationServices MDSampleStationServices
}

func (mdss *MDSampleStationHandler) HandleShowMDSampleStationScreen(c echo.Context) error {
	logger, _ := zap.NewProduction()
	title := "Master Sample Station"

	tableID := utils.GenerateRandomID("tableid")
	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()
	if err != nil {
		return err
	}

	dataUser, err := services.GetUserLogin()
	if err != nil {
		return err
	}
	defer logger.Sync()
	logger.Info("ERROR LOAD DEV", zap.Any("data", dataUser))

	dataBreadcrumb, err := mdss.MDSampleStationServices.GetMDSampleStationBreadcrumb()
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR BREADCRUMB DEV", zap.Any("error", err))
		return err
	}
	defer logger.Sync()
	logger.Info("LOAD BREADCRUMB DEV", zap.Any("data", dataBreadcrumb))

	navbarmenuComp := navbarmenu.NavbarMenu(dataMenu)
	navbaruserComp := navbarmenu.Navbar(dataUser)
	breadcrumbComp := breadcrumbadmin.MainBreadcrumbAdminV1(dataBreadcrumb)
	sidebaruserprofilceComp := sidebaruserprofile.Navbaruserprofile(dataUser)

	// table content
	dataTable, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation("", 1, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET LIST SAMPLE STATION", zap.Any("error", err))
		return err
	}
	fmt.Println("data sample station", dataTable)

	tableComponent := dev_mdsamplestationview.TableSampleStation(dataTable,
		tableID,
		"/dev/md/samplestation/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/samplestation/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
	)

	tableFilter := customtextfieldsearch.MainCustomTextFieldSearchV3(searchID,
		"search",
		"Cari Kode/Nama",
		"text",
		"/dev/md/samplestation/filter",
		"input changed delay:500ms, search",
		"#"+paginationID,
		"#loadingcontent", "",
		"outerHTML",
		"#tableID, #paginationID, #searchID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		dev_mdsamplestationview.BeforeRequestContent(),
		dev_mdsamplestationview.AfterRequestContent(),
	)

	// pagination table
	paginationTable := pagination.PaginationV3(
		totalPage,
		1,
		"/dev/md/samplestation/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "",
		dev_mdsamplestationview.BeforeRequestContent(),
		dev_mdsamplestationview.AfterRequestContent(),
	)

	// list group dropdown
	listGroupSS, err := mdss.MDSampleStationServices.GetListGroupSampleStation()
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR LIST GROUP DEV", zap.Any("error", err))
		return err
	}
	dropdownGroupItem := dev_mdsamplestationview.ItemGroupDropdown(listGroupSS, 0)

	// modal add form
	dialogAddBodyCmp := dev_mdsamplestationview.BodyFormMDSampleStation(
		dialogAddBodyID,
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationid",
			Placeholder: "Kode Sample Station",
			Type:        "hidden",
			ID:          "samplestationinputid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationcode",
			Placeholder: "Kode Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Nama Sample Station",
			Name:        "samplestationname",
			Placeholder: "Nama Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomDropdownv1Prm{
			Label: "Group",
			Name:  "samplestationgroup",
			ID:    "samplestationinputgroup",
		},
		dropdownGroupItem,
		dev_mdsamplestationview.JSHideModal(""),
	)

	modalActionAddCmp := dev_mdsamplestationview.ActionFormMDSampleStation(
		"/dev/md/samplestation/closeaddform",
		"#"+dialogAddBodyID,
		"outerHTML",
		"#"+dialogAddID,
	)

	btnCloseModalAdd := dev_mdsamplestationview.BtnCloseFormMDSampleStation(
		"/dev/md/samplestation/closeaddform",
		"#"+dialogAddBodyID,
		"outerHTML",
		"#"+dialogAddID,
	)

	modalAddFormComponent := dev_mdsamplestationview.MDSampleStationForm(
		models.MDSampleStationForm{
			IDComponent:  "formsamplestation",
			Link:         "/dev/md/samplestation/add",
			HxTarget:     "#" + dialogAddBodyID,
			HxSwap:       "outerHTML",
			HxInclude:    "#tableID, #paginationID, #searchID, #dialogAddBodyID, #dialogAddID, #dialogDeleteBodyID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID,
			ModalID:      dialogAddID,
			ModalTitle:   "New-Sample Station",
			DialogBody:   dialogAddBodyCmp,
			DialogAction: modalActionAddCmp,
			ButtonClose:  btnCloseModalAdd,
		},
	)

	// modal edit form
	dialogEditFormComp := dev_mdsamplestationview.BodyFormMDSampleStation(
		dialogEditBodyID,
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationid",
			Placeholder: "Kode Sample Station",
			Type:        "hidden",
			ID:          "samplestationinputid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationcode",
			Placeholder: "Kode Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Nama Sample Station",
			Name:        "samplestationname",
			Placeholder: "Nama Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomDropdownv1Prm{
			Label: "Group",
			Name:  "samplestationgroup",
			ID:    "samplestationinputgroup",
		},
		dropdownGroupItem,
		dev_mdsamplestationview.JSHideModal(""),
	)

	modalActionEditComp := dev_mdsamplestationview.ActionFormMDSampleStation(
		"/dev/md/samplestation/closeeditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#"+dialogEditID,
	)

	btnCloseModalEdit := dev_mdsamplestationview.BtnCloseFormMDSampleStation(
		"/dev/md/samplestation/closeeditform",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#"+dialogEditID,
	)

	modalEditFormComponent := dev_mdsamplestationview.MDSampleStationForm(
		models.MDSampleStationForm{
			IDComponent:  "formsamplestation",
			Link:         "/dev/md/samplestation/edit",
			HxTarget:     "#" + dialogEditBodyID,
			HxSwap:       "outerHTML",
			HxInclude:    "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogEditBodyID, #dialogEditID, #" + searchID + ", #currpage" + paginationID,
			ModalID:      dialogEditID,
			ModalTitle:   "Edit - Sample Station",
			DialogBody:   dialogEditFormComp,
			DialogAction: modalActionEditComp,
			ButtonClose:  btnCloseModalEdit,
		},
	)

	// modal delete form
	dialogDeleteBodyComp := dev_mdsamplestationview.BodyFormMDSampleStation(
		dialogDeleteBodyID,
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationid",
			Placeholder: "Kode Sample Station",
			Type:        "hidden",
			ID:          "samplestationinputid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationcode",
			Placeholder: "Kode Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Nama Sample Station",
			Name:        "samplestationname",
			Placeholder: "Nama Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomDropdownv1Prm{
			Label: "Group",
			Name:  "samplestationgroup",
			ID:    "samplestationinputgroup",
		},
		dropdownGroupItem,
		dev_mdsamplestationview.JSHideModal(""),
	)

	modalActionDeleteCmp := dev_mdsamplestationview.ActionFormMDSampleStationDelete(
		"/dev/md/samplestation/closedeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#"+dialogDeleteID,
	)

	btnCloseModalDelete := dev_mdsamplestationview.BtnCloseFormMDSampleStation(
		"/dev/md/samplestation/closedeleteform",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#"+dialogDeleteID,
	)

	modalDeleteFormComponent := dev_mdsamplestationview.MDSampleStationForm(
		models.MDSampleStationForm{
			IDComponent:  "formsamplestation",
			Link:         "/dev/md/samplestation/delete",
			HxTarget:     "#" + dialogDeleteBodyID,
			HxSwap:       "outerHTML",
			HxInclude:    "#tableID, #paginationID, #searchID, #dialogDeleteBodyID, #dialogDeleteID, #dialogEditBodyID, #" + searchID + ", #currpage" + paginationID,
			ModalID:      dialogDeleteID,
			ModalTitle:   "Delete - Sample Station",
			DialogBody:   dialogDeleteBodyComp,
			DialogAction: modalActionDeleteCmp,
			ButtonClose:  btnCloseModalDelete,
		},
	)

	content := dev_mdsamplestationview.ContentMDSampleStation(
		tableID,
		paginationID,
		searchID,
		dialogAddID,
		dialogAddBodyID,
		dialogEditID,
		dialogEditBodyID,
		dialogDeleteID,
		dialogDeleteBodyID,
		breadcrumbComp,
		tableComponent,
		tableFilter,
		paginationTable,
		modalAddFormComponent,
		modalEditFormComponent,
		modalDeleteFormComponent,
	)
	css := dev_mdsamplestationview.CSSMDSampleStation()
	js := dev_mdsamplestationview.JSMDSampleStation()

	view := dev_mdsamplestationview.ShowMDSampleStation(title, content, css, js, navbarmenuComp, navbaruserComp, sidebaruserprofilceComp)
	return utils.View(c, view)
}

func (mdss *MDSampleStationHandler) HandleFilterMDSS(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()

	dataSS, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation(search, 1, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET SAMPLE STATION", zap.Any("error", err))
		return err
	}

	tableComp := dev_mdsamplestationview.TableSampleStation(dataSS,
		tableID,
		"/dev/md/samplestation/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/samplestation/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
	)

	tablePagination := pagination.PaginationV3(
		totalPage,
		1,
		"/dev/md/samplestation/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID,  #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "",
		dev_mdsamplestationview.BeforeRequestContent(),
		dev_mdsamplestationview.AfterRequestContent(),
	)

	retval = append(retval, tableComp)
	retval = append(retval, tablePagination)
	return utils.ViewMulti(c, retval)
}

func (mdss *MDSampleStationHandler) HandleChangePageSampleStation(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
	}

	dataSS, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation(search, page, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET DATA", zap.Any("error", err))
		return err
	}

	tableComp := dev_mdsamplestationview.TableSampleStation(dataSS,
		tableID,
		"/dev/md/samplestation/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/samplestation/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
	)
	paginationComp := pagination.PaginationV3(
		totalPage,
		page,
		"/dev/md/samplestation/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "",
		dev_mdsamplestationview.BeforeRequestContent(),
		dev_mdsamplestationview.AfterRequestContent(),
	)

	retval = append(retval, tableComp)
	retval = append(retval, paginationComp)
	return utils.ViewMulti(c, retval)
}

// Add Modal form
func (mdss *MDSampleStationHandler) HandleCloseFormAdd(c echo.Context) error {
	logger, _ := zap.NewProduction()

	dataGroupDropdown, err := mdss.MDSampleStationServices.GetListGroupSampleStation()
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET ITEM DROPDOWN", zap.Any("error", err))
		return err
	}
	itemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataGroupDropdown, 0)

	dialogAddBodyID := c.FormValue("dialogAddBodyID")
	newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
		dialogAddBodyID,
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationid",
			Placeholder: "Kode Sample Station",
			Type:        "hidden",
			ID:          "samplestationinputid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationcode",
			Placeholder: "Kode Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Nama Sample Station",
			Name:        "samplestationname",
			Placeholder: "Nama Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomDropdownv1Prm{
			Label: "Group",
			Name:  "samplestationgroup",
			ID:    "samplestationinputgroup",
		},
		itemGroupDropdown,
		dev_mdsamplestationview.JSHideModal(""),
	)
	return utils.View(c, newForm)
}

func (mdss *MDSampleStationHandler) HandleAddMDSampleStation(c echo.Context) error {
	logger, _ := zap.NewProduction()
	defer logger.Sync()

	code := c.FormValue("samplestationcode")
	name := c.FormValue("samplestationname")
	group := c.FormValue("samplestationgroup")

	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 SAMPLE STATION PARAM",
		zap.Any("code", code),
		zap.Any("nama", name),
		zap.Any("group", group),
		zap.Any("tableid", tableID),
		zap.Any("search", search),
		zap.Any("currpage", currPage),
	)

	// dropdown item
	dataItemDropdown, err := mdss.MDSampleStationServices.GetListGroupSampleStation()
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET ITEM DROPDOWN", zap.Any("error", err))
		return err
	}
	itemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataItemDropdown, 0)

	// check item dropdown
	var idSelectedGroup int
	idSelectedGroup, err = strconv.Atoi(group)
	if err != nil {
		newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
			dialogAddBodyID,
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationid",
				Placeholder: "Kode Sample Station",
				Type:        "hidden",
				ID:          "samplestationinputid",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationcode",
				Placeholder: "Kode Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama Sample Station",
				Name:        "samplestationname",
				Placeholder: "Nama Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
			},
			models.CustomDropdownv1Prm{
				Label: "Group",
				Name:  "samplestationgroup",
				ID:    "samplestationinputgroup",
			},
			itemGroupDropdown,
			dev_mdsamplestationview.JSHideModal(""),
		)
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", "error convert str to int", "warning"), newForm})
	}

	for _, x := range dataItemDropdown {
		if x.ID == idSelectedGroup {
			group = x.Group
		}
	}

	formValidation := ""
	codeValidation := ""
	nameValidation := ""
	groupValidation := ""

	if strings.TrimSpace(code) == "" {
		formValidation = "Code sample station tidak boleh kosong"
		codeValidation = "Code sample station tidak boleh kosong"
		nameValidation = ""
		groupValidation = ""
	}
	if strings.TrimSpace(name) == "" {
		formValidation = "Nama sample station tidak boleh kosong"
		codeValidation = ""
		nameValidation = "Nama sample station tidak boleh kosong"
		groupValidation = ""
	}
	if strings.TrimSpace(group) == "" {
		formValidation = "Group sample station tidak boleh kosong"
		codeValidation = ""
		nameValidation = ""
		groupValidation = "Group sample station tidak boleh kosong"
	}
	if strings.TrimSpace(code) == "" && strings.TrimSpace(name) == "" && strings.TrimSpace(group) == "" {
		formValidation = "Code, Nama, dan Group tidak boleh kosong"
		codeValidation = "Code sample station tidak boleh kosong"
		nameValidation = "Nama sample station tidak boleh kosong"
		groupValidation = "Group sample station tidak boleh kosong"
	}

	if formValidation != "" || codeValidation != "" || nameValidation != "" || groupValidation != "" {
		newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
			dialogAddBodyID,
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationid",
				Placeholder: "Kode Sample Station",
				Type:        "hidden",
				ID:          "samplestationinputid",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationcode",
				Placeholder: "Kode Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
				Value:       code,
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama Sample Station",
				Name:        "samplestationname",
				Placeholder: "Nama Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
				Value:       name,
			},
			models.CustomDropdownv1Prm{
				Label: "Group",
				Name:  "samplestationgroup",
				ID:    "samplestationinputgroup",
			},
			itemGroupDropdown,
			dev_mdsamplestationview.JSHideModal(""),
		)
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm})
	}

	// Add Data to DB
	dataResp, err := mdss.MDSampleStationServices.AddMDSampleStation(code, name, group)
	if err != nil {
		logger.Info("Error Add to DB",
			zap.Any("Error", err),
			zap.Any("code", code),
			zap.Any("name", name),
			zap.Any("group", group),
		)
		newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
			dialogAddBodyID,
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationid",
				Placeholder: "Kode Sample Station",
				Type:        "hidden",
				ID:          "samplestationinputid",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationcode",
				Placeholder: "Kode Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
				Value:       code,
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama Sample Station",
				Name:        "samplestationname",
				Placeholder: "Nama Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
				Value:       name,
			},
			models.CustomDropdownv1Prm{
				Label: "Group",
				Name:  "samplestationgroup",
				ID:    "samplestationinputgroup",
			},
			itemGroupDropdown,
			dev_mdsamplestationview.JSHideModal(""),
		)
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm})
	}
	logger.Info("Add Sample Station",
		zap.Any("response", dataResp),
		zap.Any("code", code),
		zap.Any("name", name),
		zap.Any("group", group),
	)

	// re-initial page
	dataTableSS, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation(search, currPage, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("error get table data",
			zap.Any("error", err),
		)
		return err
	}

	tableComp := dev_mdsamplestationview.TableSampleStation(dataTableSS,
		tableID,
		"/dev/md/samplestation/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/samplestation/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
	)

	paginationComp := pagination.PaginationV3(
		totalPage,
		currPage,
		"/dev/md/samplestation/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "true",
		dev_mdsamplestationview.BeforeRequestContent(),
		dev_mdsamplestationview.AfterRequestContent(),
	)

	newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
		dialogAddBodyID,
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationid",
			Placeholder: "Kode Sample Station",
			Type:        "hidden",
			ID:          "samplestationinputid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationcode",
			Placeholder: "Kode Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Nama Sample Station",
			Name:        "samplestationname",
			Placeholder: "Nama Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomDropdownv1Prm{
			Label: "Group",
			Name:  "samplestationgroup",
			ID:    "samplestationinputgroup",
		},
		itemGroupDropdown,
		dev_mdsamplestationview.JSHideModal("#"+dialogAddID),
	)
	toastSucc := customtoastv2.CustomToastV2Show("Success", "Success add group result "+name, "success")

	return utils.ViewMulti(c, []templ.Component{
		toastSucc,
		tableComp,
		paginationComp,
		newForm,
	})
}

// Edit Modal form
func (mdss *MDSampleStationHandler) HandleOpenEditForm(c echo.Context) error {
	logger, _ := zap.NewProduction()
	defer logger.Sync()

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

	// list item dropdown
	dataGroupDropdown, err := mdss.MDSampleStationServices.GetListGroupSampleStation()
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR EDIT GET ITEM DROPDOWN", zap.Any("error", err))
		return err
	}
	itemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataGroupDropdown, 0)

	// get data by id
	dataSS, err := mdss.MDSampleStationServices.GetMDSampleStationByID(id)
	if err != nil {
		newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
			dialogEditBodyID,
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationid",
				Placeholder: "Kode Sample Station",
				Type:        "hidden",
				ID:          "samplestationinputid",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationcode",
				Placeholder: "Kode Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama Sample Station",
				Name:        "samplestationname",
				Placeholder: "Nama Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
			},
			models.CustomDropdownv1Prm{
				Label: "Group",
				Name:  "samplestationgroup",
				ID:    "samplestationinputgroup",
			},
			itemGroupDropdown,
			dev_mdsamplestationview.JSHideModal(""),
		)
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", "error get data sample station result", "danger"), newForm})
	}

	// init dropdown
	var idSelected int = 0
	for _, x := range dataGroupDropdown {
		if x.Group == dataSS.T_SampleStationIsNonLab {
			idSelected = x.ID
		}
	}

	selectedDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataGroupDropdown, idSelected)

	newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
		dialogEditBodyID,
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationid",
			Placeholder: "Kode Sample Station",
			Type:        "hidden",
			ID:          "samplestationinputid",
			Value:       strconv.Itoa(dataSS.T_SampleStationID),
		},
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationcode",
			Placeholder: "Kode Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
			Value:       dataSS.T_SampleStationCode,
		},
		models.CustomTextFieldv2Prm{
			Label:       "Nama Sample Station",
			Name:        "samplestationname",
			Placeholder: "Nama Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
			Value:       dataSS.T_SampleStationName,
		},
		models.CustomDropdownv1Prm{
			Label: "Group",
			Name:  "samplestationgroup",
			ID:    "samplestationinputgroup",
		},
		selectedDropdown,
		dev_mdsamplestationview.JSShowModal("#"+dialogEditID),
	)
	return utils.View(c, newForm)
}

func (mdss *MDSampleStationHandler) HandleCloseEditForm(c echo.Context) error {
	logger, _ := zap.NewProduction()

	dialogEditBodyID := c.FormValue("dialogEditBodyID")

	dataGroupDropdown, err := mdss.MDSampleStationServices.GetListGroupSampleStation()
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR EDIT GET ITEM DROPDOWN", zap.Any("error", err))
		return err
	}
	itemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataGroupDropdown, 0)

	newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
		dialogEditBodyID,
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationid",
			Placeholder: "Kode Sample Station",
			Type:        "hidden",
			ID:          "samplestationinputid",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationcode",
			Placeholder: "Kode Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomTextFieldv2Prm{
			Label:       "Nama Sample Station",
			Name:        "samplestationname",
			Placeholder: "Nama Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
		},
		models.CustomDropdownv1Prm{
			Label: "Group",
			Name:  "samplestationgroup",
			ID:    "samplestationinputgroup",
		},
		itemGroupDropdown,
		dev_mdsamplestationview.JSHideModal(""),
	)
	return utils.View(c, newForm)
}

func (mdss *MDSampleStationHandler) HandleEditMDSS(c echo.Context) error {
	logger, _ := zap.NewProduction()
	defer logger.Sync()

	id := c.FormValue("samplestationid")
	code := c.FormValue("samplestationcode")
	name := c.FormValue("samplestationname")
	group := c.FormValue("samplestationgroup")

	tableID := c.FormValue("tableID")
	paginationID := c.FormValue("paginationID")
	searchID := c.FormValue("searchID")
	search := c.FormValue("search")
	currPagePrm := c.FormValue("currpage" + paginationID)
	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 SAMPLE STATION PARAM",
		zap.Any("code", code),
		zap.Any("nama", name),
		zap.Any("group", group),
		zap.Any("tableid", tableID),
		zap.Any("search", search),
		zap.Any("currpage", currPage),
	)

	// dropdown item
	dataItemDropdown, err := mdss.MDSampleStationServices.GetListGroupSampleStation()
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET ITEM DROPDOWN", zap.Any("error", err))
		return err
	}
	itemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataItemDropdown, 0)

	// check item dropdown
	var idSelectedGroup int
	idSelectedGroup, err = strconv.Atoi(group)
	if err != nil {
		newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
			dialogEditBodyID,
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationid",
				Placeholder: "Kode Sample Station",
				Type:        "hidden",
				ID:          "samplestationinputid",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationcode",
				Placeholder: "Kode Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama Sample Station",
				Name:        "samplestationname",
				Placeholder: "Nama Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
			},
			models.CustomDropdownv1Prm{
				Label: "Group",
				Name:  "samplestationgroup",
				ID:    "samplestationinputgroup",
			},
			itemGroupDropdown,
			dev_mdsamplestationview.JSHideModal(""),
		)
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", "error convert str to int", "warning"), newForm})
	}

	for _, x := range dataItemDropdown {
		if x.ID == idSelectedGroup {
			group = x.Group
		}
	}

	formValidation := ""
	codeValidation := ""
	nameValidation := ""
	groupValidation := ""

	if strings.TrimSpace(code) == "" {
		formValidation = "Code sample station tidak boleh kosong"
		codeValidation = "Code sample station tidak boleh kosong"
		nameValidation = ""
		groupValidation = ""
	}
	if strings.TrimSpace(name) == "" {
		formValidation = "Nama sample station tidak boleh kosong"
		codeValidation = ""
		nameValidation = "Nama sample station tidak boleh kosong"
		groupValidation = ""
	}
	if strings.TrimSpace(group) == "" {
		formValidation = "Group sample station tidak boleh kosong"
		codeValidation = ""
		nameValidation = ""
		groupValidation = "Group sample station tidak boleh kosong"
	}
	if strings.TrimSpace(code) == "" && strings.TrimSpace(name) == "" && strings.TrimSpace(group) == "" {
		formValidation = "Code, Nama, dan Group tidak boleh kosong"
		codeValidation = "Code sample station tidak boleh kosong"
		nameValidation = "Nama sample station tidak boleh kosong"
		groupValidation = "Group sample station tidak boleh kosong"
	}

	if formValidation != "" || codeValidation != "" || nameValidation != "" || groupValidation != "" {
		newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
			dialogEditBodyID,
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationid",
				Placeholder: "Kode Sample Station",
				Type:        "hidden",
				ID:          "samplestationinputid",
			},
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationcode",
				Placeholder: "Kode Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
				Value:       code,
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama Sample Station",
				Name:        "samplestationname",
				Placeholder: "Nama Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
				Value:       name,
			},
			models.CustomDropdownv1Prm{
				Label: "Group",
				Name:  "samplestationgroup",
				ID:    "samplestationinputgroup",
			},
			itemGroupDropdown,
			dev_mdsamplestationview.JSHideModal(""),
		)
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Warning", formValidation, "warning"), newForm})
	}

	// Edit data sample station
	dataSS, err := mdss.MDSampleStationServices.EditMDSampleStation(id, code, name, group)
	if err != nil {
		dropdownItem := dev_mdsamplestationview.ItemGroupDropdown(dataItemDropdown, idSelectedGroup)
		logger.Info("Error Add to DB",
			zap.Any("Error", err),
			zap.Any("code", code),
			zap.Any("name", name),
			zap.Any("group", group),
		)
		newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
			dialogEditBodyID,
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationid",
				Placeholder: "Kode Sample Station",
				Type:        "hidden",
				ID:          "samplestationinputid",
				Value:       id,
			},
			models.CustomTextFieldv2Prm{
				Label:       "Kode Sample Station",
				Name:        "samplestationcode",
				Placeholder: "Kode Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
				Value:       code,
			},
			models.CustomTextFieldv2Prm{
				Label:       "Nama Sample Station",
				Name:        "samplestationname",
				Placeholder: "Nama Sample Station",
				Type:        "text",
				ID:          "samplestationinputname",
				Value:       name,
			},
			models.CustomDropdownv1Prm{
				Label: "Group",
				Name:  "samplestationgroup",
				ID:    "samplestationinputgroup",
			},
			dropdownItem,
			dev_mdsamplestationview.JSHideModal(""),
		)
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), newForm})
	}
	logger.Info("Add to DB",
		zap.Any("resp", dataSS),
		zap.Any("code", code),
		zap.Any("name", name),
		zap.Any("group", group),
	)

	// re-initialize page
	dataTableSS, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation(search, currPage, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("error get table data",
			zap.Any("error", err),
		)
		return err
	}

	tableComp := dev_mdsamplestationview.TableSampleStation(dataTableSS,
		tableID,
		"/dev/md/samplestation/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/samplestation/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
	)

	paginationComp := pagination.PaginationV3(
		totalPage,
		currPage,
		"/dev/md/samplestation/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "true",
		dev_mdsamplestationview.BeforeRequestContent(),
		dev_mdsamplestationview.AfterRequestContent(),
	)

	currItemGroupDropdown := dev_mdsamplestationview.ItemGroupDropdown(dataItemDropdown, idSelectedGroup)

	var retVal []templ.Component
	newForm := dev_mdsamplestationview.BodyFormMDSampleStation(
		dialogEditBodyID,
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationid",
			Placeholder: "Kode Sample Station",
			Type:        "hidden",
			ID:          "samplestationinputid",
			Value:       id,
		},
		models.CustomTextFieldv2Prm{
			Label:       "Kode Sample Station",
			Name:        "samplestationcode",
			Placeholder: "Kode Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
			Value:       code,
		},
		models.CustomTextFieldv2Prm{
			Label:       "Nama Sample Station",
			Name:        "samplestationname",
			Placeholder: "Nama Sample Station",
			Type:        "text",
			ID:          "samplestationinputname",
			Value:       name,
		},
		models.CustomDropdownv1Prm{
			Label: "Group",
			Name:  "samplestationgroup",
			ID:    "samplestationinputgroup",
		},
		currItemGroupDropdown,
		dev_mdsamplestationview.JSHideModal("#"+dialogEditID),
	)
	toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil edit Group Result  "+name, "success")

	retVal = append(retVal, toastSuccess)
	retVal = append(retVal, tableComp)
	retVal = append(retVal, paginationComp)
	retVal = append(retVal, newForm)

	return utils.ViewMulti(c, retVal)
}

// Delete Modal form
func (mdss *MDSampleStationHandler) HandleOpenDeleteForm(c echo.Context) error {
	id := c.QueryParam("id")
	dialogDeleteID := c.QueryParam("dialogDeleteID")
	dialogDeleteBodyID := c.QueryParam("dialogDeleteBodyID")

	dataMDSS, err := mdss.MDSampleStationServices.GetMDSampleStationByID(id)
	if err != nil {
		newForm := dev_mdsamplestationview.DeleteConfirmationBody(
			models.CustomTextFieldv2Prm{
				Name:  "samplestationid",
				Type:  "hidden",
				Value: strconv.Itoa(dataMDSS.T_SampleStationID),
			},
			dialogDeleteBodyID,
			"Apakah anda yakin menghapus sample station berikut ?",
			[]string{"Kode", "Nama Sample Station", "Group"},
			[]string{"", "", ""},
			dev_mdsamplestationview.JSShowModal(""),
		)
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", "Get Sample Station Error", "danger"), newForm})
	}
	newForm := dev_mdsamplestationview.DeleteConfirmationBody(
		models.CustomTextFieldv2Prm{
			Name:  "samplestationid",
			Type:  "hidden",
			Value: strconv.Itoa(dataMDSS.T_SampleStationID),
		},
		dialogDeleteBodyID,
		"Apakah anda yakin menghapus sample station berikut ?",
		[]string{"Kode", "Nama Sample Station", "Group"},
		[]string{dataMDSS.T_SampleStationCode, dataMDSS.T_SampleStationName, dataMDSS.T_SampleStationIsNonLab},
		dev_mdsamplestationview.JSShowModal("#"+dialogDeleteID),
	)
	return utils.View(c, newForm)
}

func (mdss *MDSampleStationHandler) HandleCloseFormDelete(c echo.Context) error {
	dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")
	newForm := dev_mdsamplestationview.DeleteConfirmationBody(
		models.CustomTextFieldv2Prm{
			Name:  "samplestationid",
			Type:  "hidden",
			Value: "",
		},
		dialogDeleteBodyID,
		"Apakah anda yakin menghapus sample station berikut ?",
		[]string{"Kode", "Nama Sample Station", "Group"},
		[]string{"", "", ""},
		dev_mdsamplestationview.JSShowModal(""),
	)

	return utils.View(c, newForm)
}

func (mdss *MDSampleStationHandler) HandleDeleteMDSS(c echo.Context) error {
	logger, _ := zap.NewProduction()
	defer logger.Sync()

	id := c.FormValue("samplestationid")
	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")
	dialogEditBodyID := c.FormValue("dialogEditBodyID")
	dialogDeleteBodyID := c.FormValue("dialogDeleteBodyID")

	currPag, err := strconv.Atoi(currPagePrm)
	if err != nil {
		return err
	}
	logger.Info("ADD SAMPLE STATION PARAM",
		zap.Any("tableid", tableID),
		zap.Any("search", search),
		zap.Any("currpage", currPag),
	)

	dataSS, err := mdss.MDSampleStationServices.DeleteMDSampleStation(id)
	if err != nil {
		logger.Info("Error", zap.Any("Error", err))

		newForm := dev_mdsamplestationview.DeleteConfirmationBody(
			models.CustomTextFieldv2Prm{Name: "samplestationid", Type: "hidden", Value: ""},
			dialogDeleteBodyID,
			"Apakah anda yakin menghapus sample station berikut ?",
			[]string{"Kode", "Nama Sample Station", "Group"},
			[]string{"", "", ""},
			dev_mdsamplestationview.JSShowModal(""),
		)
		return utils.ViewMulti(c, []templ.Component{customtoastv2.CustomToastV2Show("Error", err.Error(), "danger"), newForm})
	}

	logger.Info("ADD SAMPLE STATION",
		zap.Any("return", dataSS),
	)

	dataSSList, totalPage, err := mdss.MDSampleStationServices.GetListSampleStation(search, currPag, 5)
	if err != nil {
		return err
	}
	if len(dataSSList) == 0 && totalPage > 1 {
		currPag = currPag - 1
		dataSSList, _, err = mdss.MDSampleStationServices.GetListSampleStation(search, currPag, 5)
		if err != nil {
			return err
		}
	}

	tableComponent := dev_mdsamplestationview.TableSampleStation(dataSSList,
		tableID,
		"/dev/md/samplestation/openedit",
		"#"+dialogEditBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"/dev/md/samplestation/opendelete",
		"#"+dialogDeleteBodyID,
		"outerHTML",
		"#dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
	)

	tablePagination := pagination.PaginationV3(
		totalPage,
		currPag,
		"/dev/md/samplestation/changepage",
		paginationID,
		"#tableID, #searchID, #"+searchID+", #paginationID, #dialogEditBodyID, #dialogEditID, #dialogDeleteBodyID, #dialogDeleteID",
		"#"+paginationID,
		"outerHTML", "", "true",
		dev_mdsamplestationview.BeforeRequestContent(),
		dev_mdsamplestationview.AfterRequestContent(),
	)

	var retVal []templ.Component
	newForm := dev_mdsamplestationview.DeleteConfirmationBody(
		models.CustomTextFieldv2Prm{Name: "samplestationid", Type: "hidden", Value: ""},
		dialogDeleteBodyID,
		"Apakah anda yakin menghapus sample station berikut ?",
		[]string{"Kode", "Nama Sample Station", "Group"},
		[]string{"", "", ""},
		dev_mdsamplestationview.JSHideModal("#"+dialogDeleteID),
	)
	toastSuccess := customtoastv2.CustomToastV2Show("Success", "Berhasil menghapus sample station", "success")
	retVal = append(retVal, toastSuccess)
	retVal = append(retVal, tableComponent)
	retVal = append(retVal, tablePagination)
	retVal = append(retVal, newForm)

	return utils.ViewMulti(c, retVal)
}
