package dev_handlers

import (
	"cpone/models"
	"cpone/utils"
	dev_mcudaftarpeserta "cpone/views/dev/mcu/daftarpeserta"
	"fmt"

	"github.com/labstack/echo/v4"
	"go.uber.org/zap"
)

type McuDaftarPesertaServices interface {
	GetListMcuDaftarPeserta(id string, currentPage int, rowPerPage int) ([]models.ModelMcuDaftarPeserta, int, error)
}

type McuDaftarPesertaHandler struct {
	McuDaftarPesertaServices McuDaftarPesertaServices
}

func NewMcuDaftarPeserta(mdp McuDaftarPesertaServices) *McuDaftarPesertaHandler {
	return &McuDaftarPesertaHandler{
		McuDaftarPesertaServices: mdp,
	}
}

func (mdp *McuDaftarPesertaHandler) HandleGetMcuDaftarPeserta(c echo.Context) error {
	logger, _ := zap.NewProduction()

	id := c.Param("id")

	// get listing data
	dataMcuDaftarPeserta, totalPage, err := mdp.McuDaftarPesertaServices.GetListMcuDaftarPeserta(id, 1, 5)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET LIST LAB",
			zap.Any("error", err),
		)
		fmt.Println(dataMcuDaftarPeserta)
		return err
	}

	defer logger.Sync()
	logger.Info("PESERTA",
		zap.Any("totalpage", totalPage),
	)

	return err
}

func (mdp *McuDaftarPesertaHandler) HandleShowMcuDaftarPeserta(c echo.Context) error {
	title := "Daftar Peserta"

	content := dev_mcudaftarpeserta.McuDaftarPesertaScreen()
	css := dev_mcudaftarpeserta.CSSMcuDaftarPeserta()
	js := dev_mcudaftarpeserta.JsMcuDaftarPeserta()

	view := dev_mcudaftarpeserta.ShowMcuDafterPeserta(
		title,
		content,
		css,
		js,
	)

	return utils.View(c, view)
}
