"""Completion screen — celebration when all lessons are done."""

from __future__ import annotations

from textual.app import ComposeResult
from textual.containers import Center, Vertical
from textual.screen import Screen
from textual.widgets import Button, Footer, Header, Static

from cde_onboard.progress import ProgressManager


class CompletionScreen(Screen[None]):
    """Celebration screen shown when all lessons are completed."""

    def __init__(self, progress: ProgressManager) -> None:
        super().__init__()
        self.progress = progress

    def compose(self) -> ComposeResult:
        yield Header()
        with Center():
            with Vertical(id="completion-container"):
                yield Static(
                    "[bold green]Congratulations![/bold green]",
                    id="completion-title",
                )
                yield Static(
                    "You've completed all ONA onboarding lessons!\n\n"
                    "You now know how to:\n"
                    "  [cyan]1.[/cyan] Configure dev containers\n"
                    "  [cyan]2.[/cyan] Set up ONA environments\n"
                    "  [cyan]3.[/cyan] Define tasks in automations.yaml\n"
                    "  [cyan]4.[/cyan] Configure services with Docker Compose\n"
                    "  [cyan]5.[/cyan] Manage dotfiles\n"
                    "  [cyan]6.[/cyan] Work with multiple repositories\n\n"
                    "Check the [bold]cde-onboard-practice/[/bold] directory\n"
                    "for all your scaffolded configuration files.",
                    id="completion-summary",
                )
                yield Button("Back to Menu", id="btn-menu", variant="primary")
                yield Button("Quit", id="btn-quit", variant="default")
        yield Footer()

    def on_button_pressed(self, event: Button.Pressed) -> None:
        if event.button.id == "btn-menu":
            from cde_onboard.screens.welcome import WelcomeScreen

            # Clear all screens and go back to welcome
            while len(self.app.screen_stack) > 1:
                self.app.pop_screen()
            self.app.push_screen(WelcomeScreen(self.progress))
        elif event.button.id == "btn-quit":
            self.app.exit()
