import logging

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

from .base import BaseScreen

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


class SqlScreen(BaseScreen):
    """
    Screen to edit SQL queries.
    """

    BINDINGS = [
        ("ctrl+f1", "execute", "execute"),
        ("ctrl+f2", "quit", "quit"),
    ]

    CSS_PATH = "../styles/sql.tcss"

    area: TextArea

    ### Lifecycle methods ###

    def compose(self) -> ComposeResult:
        """
        Compose the service screen.
        """
        yield Header()
        with Vertical(classes="text-area-container"):
            self.area = TextArea(
                language="sql",
                id="sql_input",
                classes="text-area",
            )
            yield self.area
        yield Footer()

    ### Actions ###

    def action_execute(self) -> None:
        """
        Execute the SQL query in the text area.
        """
        self.notify("Executing SQL query...")

    def action_quit(self) -> None:
        """
        Leave the SQL screen without executing the query.
        """
        self.app.pop_screen()
