package dev_handlers

import (
	"cpone/views/dev/login"

	"github.com/a-h/templ"

	services "cpone/services/dev"

	"github.com/labstack/echo/v4"
)

type LoginService interface {
	GetLogin(Email string, Password string) (services.Login, error)
}

func NewLoginHandler(us LoginService) *LoginHandler {
	return &LoginHandler{
		LoginService: us,
	}
}

type LoginHandler struct {
	LoginService LoginService
}

func (lh *LoginHandler) HandlerShowLogin(c echo.Context) error {

	si := login.ShowLogin("Login ", login.MainLogin(), login.CssLogin(), login.JsLogin())

	return lh.ViewLogin(c, si)
}

func (uh *LoginHandler) ViewLogin(c echo.Context, cmp templ.Component) error {
	c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)

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