from fastapi import Request
from folkugat_web.api.router import get_router
from folkugat_web.fragments import llistes
from folkugat_web.services import auth
from folkugat_web.templates import templates

router = get_router()


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


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


@router.post("/api/llistes/editor/")
def insert_row(request: Request, _: auth.RequireLogin):
    return llistes.llistes_editor_insert_row(request)


@router.delete("/api/llistes/{playlist_id}")
def delete_playlist(playlist_id: int, _: auth.RequireLogin):
    return llistes.llistes_editor_delete_row(playlist_id)
