"""Layout registration + header builders.""" from __future__ import annotations from typing import Any from shared.sx.parser import SxExpr from .utils import _clear_deeper_oob, _ensure_container_nav from .calendar import ( _post_header_sx, _calendar_header_sx, _calendar_admin_header_sx, _day_header_sx, _day_admin_header_sx, _markets_header_sx, ) from .entries import _entry_header_html, _entry_admin_header_html from .slots import _slot_header_html from .tickets import _ticket_types_header_html, _ticket_type_header_html # --------------------------------------------------------------------------- # Layouts # --------------------------------------------------------------------------- def _register_events_layouts() -> None: from shared.sx.layouts import register_custom_layout register_custom_layout("events-calendar-admin", _cal_admin_full, _cal_admin_oob) register_custom_layout("events-slots", _slots_full, _slots_oob) register_custom_layout("events-slot", _slot_full, _slot_oob) register_custom_layout("events-day-admin", _day_admin_full, _day_admin_oob) register_custom_layout("events-entry", _entry_full, _entry_oob) register_custom_layout("events-entry-admin", _entry_admin_full, _entry_admin_oob) register_custom_layout("events-ticket-types", _ticket_types_full, _ticket_types_oob) register_custom_layout("events-ticket-type", _ticket_type_full, _ticket_type_oob) register_custom_layout("events-markets", _markets_full, _markets_oob) # --- Calendar admin layout (root + post + child(post-admin + calendar + cal-admin)) --- async def _cal_admin_full(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, post_admin_header_sx ctx = await _ensure_container_nav(ctx) slug = (ctx.get("post") or {}).get("slug", "") return await render_to_sx_with_env("events-cal-admin-layout-full", {}, post_header=await _post_header_sx(ctx), admin_header=await post_admin_header_sx(ctx, slug, selected="calendars"), calendar_header=_calendar_header_sx(ctx), calendar_admin_header=_calendar_admin_header_sx(ctx), ) async def _cal_admin_oob(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, post_admin_header_sx, oob_header_sx from shared.sx.parser import SxExpr ctx = await _ensure_container_nav(ctx) slug = (ctx.get("post") or {}).get("slug", "") return await render_to_sx_with_env("events-cal-admin-layout-oob", {}, admin_oob=await post_admin_header_sx(ctx, slug, oob=True, selected="calendars"), cal_oob=_calendar_header_sx(ctx, oob=True), cal_admin_oob_wrap=await oob_header_sx("calendar-header-child", "calendar-admin-header-child", _calendar_admin_header_sx(ctx)), clear_oob=SxExpr(_clear_deeper_oob("post-row", "post-header-child", "post-admin-row", "post-admin-header-child", "calendar-row", "calendar-header-child", "calendar-admin-row", "calendar-admin-header-child")), ) # --- Slots layout (same full as cal-admin but different OOB) --- async def _slots_full(ctx: dict, **kw: Any) -> str: return await _cal_admin_full({**ctx, "is_admin_section": True}, **kw) async def _slots_oob(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, post_admin_header_sx from shared.sx.parser import SxExpr ctx = await _ensure_container_nav({**ctx, "is_admin_section": True}) slug = (ctx.get("post") or {}).get("slug", "") return await render_to_sx_with_env("events-slots-layout-oob", {}, admin_oob=await post_admin_header_sx(ctx, slug, oob=True, selected="calendars"), cal_admin_oob=_calendar_admin_header_sx(ctx, oob=True), clear_oob=SxExpr(_clear_deeper_oob("post-row", "post-header-child", "post-admin-row", "post-admin-header-child", "calendar-row", "calendar-header-child", "calendar-admin-row", "calendar-admin-header-child")), ) # --- Slot detail layout (extends cal-admin with slot header) --- async def _slot_full(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, post_admin_header_sx ctx = await _ensure_container_nav({**ctx, "is_admin_section": True}) slug = (ctx.get("post") or {}).get("slug", "") return await render_to_sx_with_env("events-slot-layout-full", {}, post_header=await _post_header_sx(ctx), admin_header=await post_admin_header_sx(ctx, slug, selected="calendars"), calendar_header=_calendar_header_sx(ctx), calendar_admin_header=_calendar_admin_header_sx(ctx), slot_header=_slot_header_html(ctx), ) async def _slot_oob(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, post_admin_header_sx, oob_header_sx from shared.sx.parser import SxExpr ctx = await _ensure_container_nav({**ctx, "is_admin_section": True}) slug = (ctx.get("post") or {}).get("slug", "") return await render_to_sx_with_env("events-slot-layout-oob", {}, admin_oob=await post_admin_header_sx(ctx, slug, oob=True, selected="calendars"), cal_admin_oob=_calendar_admin_header_sx(ctx, oob=True), slot_oob_wrap=await oob_header_sx("calendar-admin-header-child", "slot-header-child", _slot_header_html(ctx)), clear_oob=SxExpr(_clear_deeper_oob("post-row", "post-header-child", "post-admin-row", "post-admin-header-child", "calendar-row", "calendar-header-child", "calendar-admin-row", "calendar-admin-header-child", "slot-row", "slot-header-child")), ) # --- Day admin layout (root + post + post-admin + child(cal + day + day-admin)) --- async def _day_admin_full(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, post_admin_header_sx ctx = await _ensure_container_nav(ctx) slug = (ctx.get("post") or {}).get("slug", "") return await render_to_sx_with_env("events-day-admin-layout-full", {}, post_header=await _post_header_sx(ctx), admin_header=await post_admin_header_sx(ctx, slug, selected="calendars"), calendar_header=_calendar_header_sx(ctx), day_header=_day_header_sx(ctx), day_admin_header=_day_admin_header_sx(ctx), ) async def _day_admin_oob(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, post_admin_header_sx, oob_header_sx from shared.sx.parser import SxExpr ctx = await _ensure_container_nav(ctx) slug = (ctx.get("post") or {}).get("slug", "") return await render_to_sx_with_env("events-day-admin-layout-oob", {}, admin_oob=await post_admin_header_sx(ctx, slug, oob=True, selected="calendars"), cal_oob=_calendar_header_sx(ctx, oob=True), day_admin_oob_wrap=await oob_header_sx("day-header-child", "day-admin-header-child", _day_admin_header_sx(ctx)), clear_oob=SxExpr(_clear_deeper_oob("post-row", "post-header-child", "post-admin-row", "post-admin-header-child", "calendar-row", "calendar-header-child", "day-row", "day-header-child", "day-admin-row", "day-admin-header-child")), ) # --- Entry layout (root + child(post + cal + day + entry), + menu) --- async def _entry_full(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env return await render_to_sx_with_env("events-entry-layout-full", {}, post_header=await _post_header_sx(ctx), calendar_header=_calendar_header_sx(ctx), day_header=_day_header_sx(ctx), entry_header=_entry_header_html(ctx), ) async def _entry_oob(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, oob_header_sx from shared.sx.parser import SxExpr return await render_to_sx_with_env("events-entry-layout-oob", {}, day_oob=_day_header_sx(ctx, oob=True), entry_oob_wrap=await oob_header_sx("day-header-child", "entry-header-child", _entry_header_html(ctx)), clear_oob=SxExpr(_clear_deeper_oob("post-row", "post-header-child", "calendar-row", "calendar-header-child", "day-row", "day-header-child", "entry-row", "entry-header-child")), ) # --- Entry admin layout (root + post + child(post-admin + cal + day + entry + entry-admin), + menu) --- async def _entry_admin_full(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, post_admin_header_sx ctx = await _ensure_container_nav(ctx) slug = (ctx.get("post") or {}).get("slug", "") return await render_to_sx_with_env("events-entry-admin-layout-full", {}, post_header=await _post_header_sx(ctx), admin_header=await post_admin_header_sx(ctx, slug, selected="calendars"), calendar_header=_calendar_header_sx(ctx), day_header=_day_header_sx(ctx), entry_header=_entry_header_html(ctx), entry_admin_header=_entry_admin_header_html(ctx), ) async def _entry_admin_oob(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, post_admin_header_sx, oob_header_sx from shared.sx.parser import SxExpr ctx = await _ensure_container_nav(ctx) slug = (ctx.get("post") or {}).get("slug", "") return await render_to_sx_with_env("events-entry-admin-layout-oob", {}, admin_oob=await post_admin_header_sx(ctx, slug, oob=True, selected="calendars"), entry_oob=_entry_header_html(ctx, oob=True), entry_admin_oob_wrap=await oob_header_sx("entry-header-child", "entry-admin-header-child", _entry_admin_header_html(ctx)), clear_oob=SxExpr(_clear_deeper_oob("post-row", "post-header-child", "post-admin-row", "post-admin-header-child", "calendar-row", "calendar-header-child", "day-row", "day-header-child", "entry-row", "entry-header-child", "entry-admin-row", "entry-admin-header-child")), ) # --- Ticket types layout (extends entry admin with ticket-types header, + menu) --- async def _ticket_types_full(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env return await render_to_sx_with_env("events-ticket-types-layout-full", {}, post_header=await _post_header_sx(ctx), calendar_header=_calendar_header_sx(ctx), day_header=_day_header_sx(ctx), entry_header=_entry_header_html(ctx), entry_admin_header=_entry_admin_header_html(ctx), ticket_types_header=_ticket_types_header_html(ctx), ) async def _ticket_types_oob(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, oob_header_sx return await render_to_sx_with_env("events-ticket-types-layout-oob", {}, entry_admin_oob=_entry_admin_header_html(ctx, oob=True), ticket_types_oob_wrap=await oob_header_sx("entry-admin-header-child", "ticket_types-header-child", _ticket_types_header_html(ctx)), ) # --- Ticket type detail layout (extends ticket types with ticket-type header, + menu) --- async def _ticket_type_full(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env return await render_to_sx_with_env("events-ticket-type-layout-full", {}, post_header=await _post_header_sx(ctx), calendar_header=_calendar_header_sx(ctx), day_header=_day_header_sx(ctx), entry_header=_entry_header_html(ctx), entry_admin_header=_entry_admin_header_html(ctx), ticket_types_header=_ticket_types_header_html(ctx), ticket_type_header=_ticket_type_header_html(ctx), ) async def _ticket_type_oob(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, oob_header_sx return await render_to_sx_with_env("events-ticket-type-layout-oob", {}, ticket_types_oob=_ticket_types_header_html(ctx, oob=True), ticket_type_oob_wrap=await oob_header_sx("ticket_types-header-child", "ticket_type-header-child", _ticket_type_header_html(ctx)), ) # --- Markets layout (root + child(post + markets)) --- async def _markets_full(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env return await render_to_sx_with_env("events-markets-layout-full", {}, post_header=await _post_header_sx(ctx), markets_header=_markets_header_sx(ctx), ) async def _markets_oob(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import render_to_sx_with_env, oob_header_sx return await render_to_sx_with_env("events-markets-layout-oob", {}, post_oob=await _post_header_sx(ctx, oob=True), markets_oob_wrap=await oob_header_sx("post-header-child", "markets-header-child", _markets_header_sx(ctx)), )