from flask import Blueprint, abort, make_response, render_template, g

from src.lib.artist import get_unapproved_links_with_artists

from .types import mod_props

moderator = Blueprint("mod", __name__)


@moderator.before_request
def check_credentials():
    account = g.get("account")
    if not account or (account.role != "moderator" and account.role != "administrator"):
        return abort(code=404)


@moderator.get("/moderator")
def get_dashboard():
    props = mod_props.Dashboard()

    response = make_response(
        render_template(
            "account/moderator/dashboard.html",
            props=props,
        ),
        200,
    )
    response.headers["Cache-Control"] = "s-maxage=60"
    return response


@moderator.route("/moderator/tasks/creator_links")
def get_creator_links():
    links = get_unapproved_links_with_artists()
    props = {"currentPage": "mod"}

    response = make_response(
        render_template(
            "account/moderator/creator_links.html",
            links=links,
            props=props,
        ),
        200
    )
    return response


# @moderator.route("/mod/tasks/files")
# def get_files():
#     files = []
#     props = mod_props.Files(
#         files= files
#     )
#     response = make_response(render_template(
#         'moderator_files.html',
#         props = props,
#     ), 200)
#     response.headers['Cache-Control'] = 's-maxage=60'
#     return response
