from textual.screen import Screen
from textual.widgets import Header, Footer, Static, Button
from textual.containers import Grid


# Screen[dict[int, str, int]]
class TagDeleteScreen(Screen):

    CSS = """

    Grid {
        grid-size: 4 9;
        grid-rows: 2 2 2 2 2 2 2 2 2;
        grid-columns: 30 30 30 30;
        height: 100%;
        width: 100%;
        padding: 1;
    }

    Input {
        border: none;
    }
    Button {
        border: none;
    }
    #toplabel {
        height: 1;
    }

    .two {
        column-span: 2;
    }
    .three {
        column-span: 3;
    }
    .four {
        column-span: 4;
    }
    .five {
        column-span: 5;
    }

    .box {
        height: 100%;
        border: solid green;
    }
    """

    def __init__(self, key=None, value=None):
        super().__init__()
        self.__key = key
        self.__value = value


    def on_mount(self):

        self.query_one("#keylabel", Static).update(str(self.__key))
        self.query_one("#valuelabel", Static).update(str(self.__value))


    def compose(self):

        yield Header()

        with Grid():
            
            #1
            yield Static(f"Are you sure to delete this tag ?", id="toplabel", classes="five")

            #2
            yield Static("Key")
            yield Static(" ", id="keylabel", classes="four")

            #3
            yield Static("Value")
            yield Static(" ", id="valuelabel", classes="four")

            #4
            yield Static(" ", classes="five")

            #9
            yield Button("Delete", id="delete_button")
            yield Button("Cancel", id="cancel_button")

        yield Footer()


   # Event handler for button press
    def on_button_pressed(self, event: Button.Pressed) -> None:

        if event.button.id == "delete_button":

            tag = (self.__key, self.__value)               
            self.dismiss(tag)

        if event.button.id == "cancel_button":
            self.app.pop_screen()

