package dev_handlers

import (
	"fmt"

	"cpone/views/dev/employee"

	services "cpone/services/dev"

	"github.com/a-h/templ"
	"github.com/labstack/echo/v4"
)

type EmployeeService interface {
	GetEmployeeService() ([]services.EmployeeService, error)
}

func NewEmployeeHandler(us EmployeeService) *EmployeeHandler {
	return &EmployeeHandler{
		EmployeeService: us,
	}
}

type EmployeeHandler struct {
	EmployeeService EmployeeService
}

func (eh *EmployeeHandler) ShowEmployee(c echo.Context) error {
	udata, err := eh.EmployeeService.GetEmployeeService()
	if err != nil {
		// fmt.Println(err)
		return err
	}

	fmt.Printf("%+v\n", udata)
	e := employee.ShowEmployee("Employee", employee.MainEmployee(employee.ListCardService(udata)), employee.CssEmployee(), employee.JsEmployee())
	return eh.View(c, e)
}

func (eh *EmployeeHandler) View(c echo.Context, cmp templ.Component) error {
	c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)

	return cmp.Render(c.Request().Context(), c.Response().Writer)
}
