from typing import Annotated

from fastapi import Request
from fastapi.params import Param
from folkugat_web.api import router
from folkugat_web.fragments import temes
from folkugat_web.services import auth
from folkugat_web.templates import templates


@router.get("/temes")
def page(
        request: Request,
        logged_in: auth.LoggedIn,
        query: Annotated[str, Param()] = "",
):
    return templates.TemplateResponse(
        "index.html",
        {
            "request": request,
            "page_title": "Folkugat",
            "content": f"/api/content/temes?query={query}",
            "logged_in": logged_in,
            "animate": False,
        }
    )


@router.get("/api/content/temes")
def content(
    request: Request,
    logged_in: auth.LoggedIn,
    query: Annotated[str, Param()] = "",
):
    return temes.temes_pagina(request, logged_in, query)


@router.get("/api/temes/busca")
def busca(request: Request, query: str, logged_in: auth.LoggedIn, limit: int = 10, offset: int = 0):
    return temes.temes_busca(request, query=query, limit=limit, offset=offset, logged_in=logged_in)
