#
#   Imandra Inc.
#
#   speclogician/tui/splash.py
#

from typing import Any
from pathlib import Path
from textual.screen import Screen
from textual.containers import Container
from textual.app import ComposeResult
from textual.widgets import Static
from textual_image.widget import Image
from rich.align import Align
from rich.text import Text

class SplashScreen(Screen[Any]):
    CSS = """
    SplashScreen {
        align: center middle;
    }

    #logo {
        margin-bottom: 1;
    }

    #status {
        width: auto;
        content-align: center middle;
    }    

    """
    LOGO_PATH = Path(__file__).parent / "images" / "speclogician-minimal.png"
    def compose(self) -> ComposeResult:
        with Container(id="logo") as c:
            c.border_title = "width: auto; height: auto;"
            yield Image(self.LOGO_PATH, classes="width-auto height-auto")

        yield Static(
            Align.center(Text("Loading…", style="dim")),
            id="status",
        )

    def on_mount(self) -> None:
        def go_next() -> None:
            if getattr(self.app, "demo_md", None):
                self.app.action_demo()
            else:
                self.app.switch_screen("main")

        self.set_timer(2.0, go_next)