from fastapi import Request
from folkugat_web.api.router import get_router
from folkugat_web.config import calendari as calendari_conf
from folkugat_web.fragments import live, sessions
from folkugat_web.services import auth
from folkugat_web.templates import templates

router = get_router()


@router.get("/sessions")
def page(request: Request, logged_in: auth.LoggedIn):
    return templates.TemplateResponse(
        "index.html",
        {
            "request": request,
            "page_title": "Folkugat",
            "content": "/api/content/sessions",
            "logged_in": logged_in,
            "animate": False,
        }
    )


@router.get("/api/content/sessions")
def content(request: Request, logged_in: auth.LoggedIn):
    return sessions.sessions_pagina(request, logged_in)


@router.get("/api/sessions/upcoming")
def calendari(
    request: Request,
    logged_in: auth.LoggedIn,
    limit: int = calendari_conf.CALENDARI_PAGING_CONFIG.initial_items,
):
    return sessions.sessions_calendari(request=request, limit=limit, logged_in=logged_in)


@router.get("/api/sessions/history")
def history(
    request: Request,
    logged_in: auth.LoggedIn,
    limit: int = calendari_conf.HISTORY_PAGING_CONFIG.initial_items,
):
    return sessions.sessions_historial(request=request, limit=limit, logged_in=logged_in)


@router.get("/api/sessions/live")
def get_live(request: Request):
    return live.sessio_en_directe(request)
