from fastapi import HTTPException, Request
from folkugat_web.model.pagines import Pages
from folkugat_web.services import sessions as sessions_service
from folkugat_web.templates import templates


def pagina(request: Request, session_id: int, logged_in: bool):
    session = sessions_service.get_session(session_id=session_id)
    if not session:
        raise HTTPException(status_code=404, detail="Could not find session")
    session = sessions_service.add_playlists_to_session(session=session)
    return templates.TemplateResponse(
        "fragments/sessio/pagina.html",
        {
            "request": request,
            "logged_in": logged_in,
            "Pages": Pages,
            "session_id": session_id,
            "session": session,
            "date_names": sessions_service.get_date_names,
        }
    )
