from __future__ import annotations

from importlib.metadata import version
from pathlib import Path

from textual.app import App
from textual.theme import Theme

from smartwallet.ui.screens.main_screen import MainScreen

_smartwallet_theme = Theme(
    name="smartwallet",
    primary="#22c55e",
    secondary="#3b82f6",
    accent="#a855f7",
    foreground="#f5f5f5",
    background="#000000",
    surface="#121212",
    panel="#1a1a1a",
    success="#10b981",
    warning="#f59e0b",
    error="#ef4444",
    dark=True,
    variables={
        "block-cursor-text-style": "bold",
        "footer-key-foreground": "#22c55e",
        "input-selection-background": "#22c55e 30%",
    },
)


def _get_version() -> str:
    try:
        return version("smartwallet")
    except Exception:
        return "dev"


class SmartWalletApp(App):
    TITLE = f"SmartWallet v{_get_version()}"
    CSS_PATH = Path(__file__).parent / "styles" / "app.tcss"

    def on_mount(self) -> None:
        self.register_theme(_smartwallet_theme)
        self.theme = "smartwallet"
        self.push_screen(MainScreen())
