"""
s17 - Single References slide (replaces former s17+s18 split).

All 15 entries cited in this talk, in 2 columns, small font.
"""

import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))

from manim import Text, VGroup, FadeIn, UP, DOWN, LEFT, RIGHT
from src.slides._core import SceneSlide
from src.slides._theme import SecurityPalette, Fonts, Sizes, Layout
from src.slides._layout import slide_title
from src.slides._refs import BIB


class S17References(SceneSlide):
    SECTION = None
    WITH_FOOTER = True
    ON_DARK = True

    def construct_content(self):
        title = slide_title(
            "References  (cited in this talk)",
            font_size=36, with_accent_rule=True,
        )
        title.move_to((0.0, 3.0, 0.0))

        def make_entry(n: int) -> VGroup:
            author, ttl, venue = BIB[n]
            num   = Text(f"[{n}]", font=Fonts.MONO, font_size=11,
                         color=SecurityPalette.WARN, weight="BOLD")
            body  = Text(f"{author}  -  {ttl}",
                         font=Fonts.SANS, font_size=11,
                         color=SecurityPalette.FG)
            ven   = Text(venue, font=Fonts.SANS, font_size=9,
                         color=SecurityPalette.FG_DIM)
            line1 = VGroup(num, body).arrange(RIGHT, buff=0.18, aligned_edge=UP * 0)
            return VGroup(line1, ven).arrange(DOWN, buff=0.04, aligned_edge=LEFT)

        col1_nums = list(range(1, 9))    # [1..8]
        col2_nums = list(range(9, 16))   # [9..15]

        col1 = VGroup(*[make_entry(n) for n in col1_nums]).arrange(
            DOWN, buff=0.18, aligned_edge=LEFT)
        col2 = VGroup(*[make_entry(n) for n in col2_nums]).arrange(
            DOWN, buff=0.18, aligned_edge=LEFT)

        cols = VGroup(col1, col2).arrange(RIGHT, buff=0.7, aligned_edge=UP)
        cols.move_to((0.0, -0.3, 0.0))

        note = Text(
            "Full bibliography in the paper at  mcs.danielwagner.ro/paper",
            font=Fonts.MONO, font_size=Sizes.CAPTION,
            color=SecurityPalette.FG_DIM,
        )
        note.move_to((0.0, Layout.BOTTOM_EDGE + 0.95, 0))

        self.play(FadeIn(title, shift=0.2 * UP), run_time=0.4)
        self.play(FadeIn(cols), run_time=0.8)
        self.play(FadeIn(note), run_time=0.4)
        self.wait(0.5)
        self.next_slide()
