import customtkinter

from src.ui import theme
from src.ui.widgets import FormModal


class BaseModal(FormModal):
    """Label fuer einen Wegpunkt vergeben oder aendern."""

    def __init__(self, parent, waypoint=None, onConfirm=lambda: {}):
        super().__init__(parent, 'Wegpunkt-Label')
        self.onConfirm = onConfirm
        self.body.grid_columnconfigure(0, weight=1)

        customtkinter.CTkLabel(
            self.body, text='Label (leer lassen fuer keins):',
            font=theme.font(12), text_color=theme.MUTED,
        ).grid(row=0, column=0, columnspan=2, sticky='w', pady=(4, 2))
        self.labelEntry = customtkinter.CTkEntry(self.body)
        self.labelEntry.grid(row=1, column=0, columnspan=2, sticky='ew',
                             pady=(0, 6))
        if waypoint is not None and waypoint['label']:
            self.labelEntry.insert(0, waypoint['label'])

    def confirm(self):
        self.onConfirm(self.labelEntry.get(), {})
        self.destroy()
