import logging

from textual.app import ComposeResult
from textual.containers import Vertical
from textual.widgets import DataTable, Footer, Header

from .base import BaseScreen

logger = logging.getLogger("shovl.screens")


class ServiceScreen(BaseScreen):
    """
    Base service screen. Inherited by all service screens (e.g. database,
    bucket, etc.) to provide common functionality such as displaying
    connection info, handling common keybindings, etc.
    """

    CSS_PATH = "../styles/service.tcss"

    table: DataTable

    ### Lifecycle methods ###

    def compose(self) -> ComposeResult:
        """
        Compose the service screen.
        """
        yield Header()
        # with Vertical(classes="breadcrumbs-container"):
        #    yield Label(
        #        "",
        #        classes="breadcrumbs",
        #        id="breadcrumbs",
        #    )
        with Vertical(classes="table-container"):
            self.table = DataTable(
                classes="table",
                id="table",
            )
            yield self.table
        yield Footer()

    ### Event handlers ###

    def on_mount(self) -> None:
        """
        Handle the mount event.
        """
        self.focus_main()

    ### Class methods ###

    def focus_main(self) -> None:
        """
        Focus the tabe.
        """
        self.table.focus()
