"""Laid-out document model: pages of positioned draw nodes (output of layout, input of drawing)."""

from __future__ import annotations

from dataclasses import dataclass, field
from typing import Any


class DrawNode:
    """A resolved node. Coordinates are relative to the parent draw node (pt, y down)."""

    __slots__ = (
        "arc",
        "blend",
        "children",
        "clip",
        "deferred",
        "fills",
        "fit",
        "focal",
        "h",
        "id",
        "image",
        "kind",
        "opacity",
        "origin",
        "path",
        "points",
        "radius",
        "rotation",
        "stroke_sides",
        "strokes",
        "text",
        "text_runs",
        "w",
        "x",
        "y",
    )

    def __init__(self, kind: str, node_id: str, x: float, y: float, w: float, h: float) -> None:
        self.kind = kind
        self.id = node_id
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.rotation = 0.0
        self.origin: tuple[float, float] = (0.5, 0.5)
        self.opacity = 1.0
        self.blend = "normal"
        self.fills: list[dict[str, Any]] = []
        self.strokes: list[dict[str, Any]] = []
        self.stroke_sides: tuple[str, ...] | None = None
        self.radius: Any = 0
        self.clip = False
        self.children: list[DrawNode] = []
        self.text: dict[str, Any] | None = None
        self.text_runs: list[dict[str, Any]] = []
        self.deferred: Any = None
        self.image: Any = None
        self.fit = "cover"
        self.focal: tuple[float, float] = (0.5, 0.5)
        self.points: list[tuple[float, float]] = []
        self.path: list[list[Any]] = []
        self.arc: tuple[float, float, float] | None = None

    def __repr__(self) -> str:
        return f"<DrawNode {self.kind} {self.id} {self.x:.1f},{self.y:.1f} {self.w:.1f}x{self.h:.1f}>"


@dataclass
class Page:
    sheet_id: str
    sheet_name: str
    w: float
    h: float
    bleed: float = 0.0
    background: dict[str, Any] | None = None
    items: list[DrawNode] = field(default_factory=list)
    vars: dict[str, Any] = field(default_factory=dict)
    skip_numbering: bool = False
    restart: int | None = None
    raster: bool = True
    section: int = 0
