"""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


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


@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, stdscr: int, height: int, width: int) -> None: ...

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

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