package dev_handlers

import (
	breadcrumadmin "cpone/component/breadcrumbadmin"
	navbarmenu "cpone/component/navbar"
	sidebaruserprofile "cpone/component/sidebar_user_profile"
	"cpone/models"
	"cpone/services"
	"cpone/utils"
	dev_detailmcu "cpone/views/dev/mcu"

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

type DetailMcuServices interface {
	GetBreadcrumb(title string) (models.BreadCrumbV1, error)
}

type DetailMcuHandler struct {
	DetailMcuServices DetailMcuServices
}

func NewDetailMcuHandler(dmcu DetailMcuServices) *DetailMcuHandler {
	return &DetailMcuHandler{
		DetailMcuServices: dmcu,
	}
}

func (dmcu *DetailMcuHandler) HandleShowDetailMcuScreen(c echo.Context) error {
	logger, _ := zap.NewProduction()
	title := "PT. Sadhana Abiyasa Sampoerna"

	id := c.Param("id")
	logger.Info("params", zap.Any("id", id))

	user, err := services.GetUserLogin()
	if err != nil {
		defer logger.Sync()
		logger.Info("Error get user dev", zap.Any("error", err))
		return err
	}

	dataBreadcrumb, err := dmcu.DetailMcuServices.GetBreadcrumb(title)
	if err != nil {
		defer logger.Sync()
		logger.Info("Error breadcrumb dev", zap.Any("error", err))
		return err
	}

	breadcrumb := breadcrumadmin.MainBreadcrumbAdminV1(dataBreadcrumb)
	navbaruser := navbarmenu.NavbarWithLogo(user)
	sidbaruser := sidebaruserprofile.Navbaruserprofile(user)

	content := dev_detailmcu.DetailMcuScreen(
		breadcrumb,
		dev_detailmcu.TabViewDetailMcu(id),
	)
	css := dev_detailmcu.CSSDetailMcu()
	js := dev_detailmcu.JSDetailMcu()

	view := dev_detailmcu.ShowDetailMcu(
		title,
		content,
		css,
		js,
		navbaruser,
		sidbaruser,
	)

	return utils.View(c, view)
}
