"""
Base SceneSlide class - all s##_*.py scenes inherit from this.

SceneSlide handles background color and optional chrome (section label + footer)
so each scene file only contains content logic.

See manim/README.md for the dev loop and render commands.
The class name "SceneSlide" matches the VS Code Manim Sideview regex (\\w*Scene\\w*).
"""

import sys
from pathlib import Path

_ROOT = Path(__file__).resolve().parent.parent.parent
if str(_ROOT) not in sys.path:
    sys.path.insert(0, str(_ROOT))

from manim import (
    Scene, FadeIn, FadeOut, VGroup, Group,
    LEFT, RIGHT, UP, DOWN, ORIGIN,
)
from manim_slides import Slide, ThreeDSlide

from src.slides._theme import SecurityPalette
from src.slides._layout import chrome


class BasicSlide(Slide):
    """
    Default slide: dark terminal background, optional section indicator + footer.

    Subclasses set:
      SECTION    = "ACT II  -  Memory Vulns"   # or None for full-bleed
      WITH_FOOTER = True                        # default
      ON_DARK    = True                         # default - all slides dark

    and override `construct_content(self)` instead of `construct(self)`.
    """

    SECTION:    str | None = None
    WITH_FOOTER: bool      = True
    ON_DARK:     bool      = True

    def construct(self):
        # Windows + manim-slides reverse-mux fix (mate/proiect convention).
        self.skip_reversing = True

        bg = SecurityPalette.BG if self.ON_DARK else SecurityPalette.BG_LIGHT
        self.camera.background_color = bg

        if self.SECTION is not None or self.WITH_FOOTER:
            self._chrome = chrome(
                section=self.SECTION,
                with_footer=self.WITH_FOOTER,
                on_dark=self.ON_DARK,
            )
            self.add(self._chrome)
        else:
            self._chrome = None

        self.construct_content()

    def construct_content(self):
        raise NotImplementedError(
            f"{self.__class__.__name__} must override construct_content()"
        )


SceneSlide = BasicSlide


__all__ = [
    "BasicSlide", "SceneSlide", "Slide",
    "FadeIn", "FadeOut", "VGroup", "Group",
    "LEFT", "RIGHT", "UP", "DOWN", "ORIGIN",
    "SecurityPalette",
]
