from __future__ import annotations

from quart import (
    request, Blueprint, g
)


def register():
    bp = Blueprint("admin", __name__, url_prefix='/admin')

    @bp.before_request
    async def _prepare_page_data():
        if "defpage_" not in (request.endpoint or ""):
            return
        from shared.sx.page import get_template_context
        from sx.sx_components import _entry_admin_main_panel_html
        ctx = await get_template_context()
        g.entry_admin_content = _entry_admin_main_panel_html(ctx)

    from shared.sx.pages import mount_pages
    mount_pages(bp, "events", names=["entry-admin"])

    return bp
