package mcu_corporate_handlers

import (
	"cpone/models"
	"cpone/utils"
	corporate_mcudetail "cpone/views/corporate/mcu/mcutab"
	"fmt"

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

type TabKesimpulanServices interface {
	GetListKesimpulanLab(id string) ([]models.ModelKesimpulanLab, error)
	GetListKesimpulanNonLab(id string) ([]models.ModelKesimpulanLab, error)
	GetListKesimpulanFisik(id string) ([]models.ModelKesimpulanLab, error)
	GetListKesimpulanLabV2(id string) ([]models.ModelKesimpulanLab, error)
	GetListKesimpulanNonLabV2(id string) ([]models.ModelKesimpulanLab, error)
	GetListKesimpulanFisikV2(id string) ([]models.ModelKesimpulanLab, error)
}

type TabKesimpulanHandler struct {
	TabKesimpulanServices TabKesimpulanServices
}

func NewTabKesimpulanHandler(us TabKesimpulanServices) *TabKesimpulanHandler {
	return &TabKesimpulanHandler{
		TabKesimpulanServices: us,
	}
}

func (tkh *TabKesimpulanHandler) HandleShowTabKesimpulanScreen(c echo.Context) error {
	logger, _ := zap.NewProduction()

	tableID := utils.GenerateRandomID("tablebody")
	id := c.Param("id")

	dataLab, err := tkh.TabKesimpulanServices.GetListKesimpulanLabV2(id)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET LIST LAB",
			zap.Any("error", err),
		)
		fmt.Println(dataLab)
		return err
	}
	tableComponentLab := corporate_mcudetail.CardTableKesimpulan("3 Kelainan Pemeriksaan Lab terbesar :", dataLab, tableID)

	dataNonLab, err := tkh.TabKesimpulanServices.GetListKesimpulanNonLabV2(id)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET LIST NON LAB",
			zap.Any("error", err),
		)
		fmt.Println(dataNonLab)
		return err
	}
	tableComponentNonLab := corporate_mcudetail.CardTableKesimpulan("3 Kelainan Pemeriksaan Non Lab terbesar :", dataNonLab, tableID)

	dataFisik, err := tkh.TabKesimpulanServices.GetListKesimpulanFisikV2(id)
	if err != nil {
		defer logger.Sync()
		logger.Info("ERROR GET LIST FISIK",
			zap.Any("error", err),
		)
		fmt.Println(dataFisik)
		return err
	}
	tableComponentFisik := corporate_mcudetail.CardTableKesimpulan("3 Kelainan Pemeriksaan Fisik terbesar :", dataFisik, tableID)

	content := corporate_mcudetail.MainKesimpulan(
		tableID,
		tableComponentLab,
		tableComponentNonLab,
		tableComponentFisik,
	)

	return utils.View(c, content)
}
