"""Orders defpage setup — registers layouts and loads .sx pages.""" from __future__ import annotations from typing import Any def setup_orders_pages() -> None: """Register orders-specific layouts and load page definitions.""" _register_orders_layouts() _load_orders_page_files() def _load_orders_page_files() -> None: """Load defpage definitions from orders/sxc/pages/*.sx.""" import os from shared.sx.pages import load_page_dir load_page_dir(os.path.dirname(__file__), "orders") # --------------------------------------------------------------------------- # Layouts # --------------------------------------------------------------------------- def _register_orders_layouts() -> None: from shared.sx.layouts import register_custom_layout register_custom_layout("orders", _orders_full, _orders_oob, _orders_mobile) register_custom_layout("order-detail", _order_detail_full, _order_detail_oob, _order_detail_mobile) async def _orders_full(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import root_header_sx, header_child_sx, call_url, render_to_sx list_url = kw.get("list_url", "/") account_url = call_url(ctx, "account_url", "") root_hdr = await root_header_sx(ctx) auth_hdr = await render_to_sx("auth-header-row", account_url=account_url, select_colours=ctx.get("select_colours", ""), account_nav=_as_sx_nav(ctx), ) orders_hdr = await render_to_sx("orders-header-row", list_url=list_url) inner = "(<> " + auth_hdr + " " + orders_hdr + ")" return "(<> " + root_hdr + " " + await header_child_sx(inner) + ")" async def _orders_oob(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import root_header_sx, render_to_sx from shared.sx.helpers import call_url from shared.sx.parser import SxExpr list_url = kw.get("list_url", "/") account_url = call_url(ctx, "account_url", "") auth_hdr = await render_to_sx("auth-header-row", account_url=account_url, select_colours=ctx.get("select_colours", ""), account_nav=_as_sx_nav(ctx), oob=True, ) orders_hdr = await render_to_sx("orders-header-row", list_url=list_url) auth_child_oob = await render_to_sx("oob-header-sx", parent_id="auth-header-child", row=SxExpr(orders_hdr)) root_hdr = await root_header_sx(ctx, oob=True) return "(<> " + auth_hdr + " " + auth_child_oob + " " + root_hdr + ")" async def _orders_mobile(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import mobile_menu_sx, mobile_root_nav_sx return mobile_menu_sx(await mobile_root_nav_sx(ctx)) async def _order_detail_full(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import root_header_sx, render_to_sx from shared.sx.helpers import call_url from shared.sx.parser import SxExpr list_url = kw.get("list_url", "/") detail_url = kw.get("detail_url", "/") account_url = call_url(ctx, "account_url", "") root_hdr = await root_header_sx(ctx) order_row = await render_to_sx( "menu-row-sx", id="order-row", level=3, colour="sky", link_href=detail_url, link_label="Order", icon="fa fa-gbp", ) auth_hdr = await render_to_sx("auth-header-row", account_url=account_url, select_colours=ctx.get("select_colours", ""), account_nav=_as_sx_nav(ctx), ) orders_hdr = await render_to_sx("orders-header-row", list_url=list_url) detail_header = await render_to_sx( "order-detail-header-stack", auth=SxExpr(auth_hdr), orders=SxExpr(orders_hdr), order=SxExpr(order_row), ) return "(<> " + root_hdr + " " + detail_header + ")" async def _order_detail_oob(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import root_header_sx, render_to_sx from shared.sx.parser import SxExpr detail_url = kw.get("detail_url", "/") order_row_oob = await render_to_sx( "menu-row-sx", id="order-row", level=3, colour="sky", link_href=detail_url, link_label="Order", icon="fa fa-gbp", oob=True, ) header_child_oob = await render_to_sx("oob-header-sx", parent_id="orders-header-child", row=SxExpr(order_row_oob)) root_hdr = await root_header_sx(ctx, oob=True) return "(<> " + header_child_oob + " " + root_hdr + ")" async def _order_detail_mobile(ctx: dict, **kw: Any) -> str: from shared.sx.helpers import mobile_menu_sx, mobile_root_nav_sx return mobile_menu_sx(await mobile_root_nav_sx(ctx)) def _as_sx_nav(ctx: dict) -> Any: """Convert account_nav fragment to SxExpr for use in component calls.""" from shared.sx.helpers import _as_sx return _as_sx(ctx.get("account_nav"))