"""Types for pgt TUI pages and navigation."""

from __future__ import annotations

from dataclasses import dataclass
from enum import Enum, auto
from pathlib import Path
from typing import Protocol, runtime_checkable

from pygit2 import Repository
from pyratatui import Frame, Rect

from pygittools.tui.keys import KeyLike


class PageAction(Enum):
    NONE = auto()
    QUIT = auto()
    REPLACE = auto()
    PUSH = auto()
    POP = auto()


@dataclass(frozen=True, slots=True)
class PageResult:
    action: PageAction = PageAction.NONE
    next_page: Page | None = None
    switch_repo: Path | None = None
    repo_changed: bool = False


@dataclass(frozen=True, slots=True)
class PageContext:
    repo: Repository
    repo_path: Path


@runtime_checkable
class Page(Protocol):
    """A full-screen view in the pgt TUI."""

    @property
    def title(self) -> str: ...

    def on_enter(self, ctx: PageContext) -> None: ...

    def draw(self, frame: Frame, area: Rect) -> None: ...

    def status_text(self) -> str: ...

    def handle_key(self, key: KeyLike) -> PageResult: ...