import customtkinter

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

CITIES = ['AbDendriel', 'Ankrahmun', 'Carlin', 'Darashia', 'Edron',
          'Farmine', 'Issavi', 'Kazoordon', 'LibertBay', 'PortHope',
          'Rathleton', 'Svargrond', 'Thais', 'Venore', 'Yalahar',
          'Feyrist', 'Dark Mansion']


class DepositItemsModal(FormModal):
    """Stadt fuer das Deposit-Depot waehlen."""

    def __init__(self, parent, waypoint=None, onConfirm=lambda: {}):
        super().__init__(parent, 'Deposit Items – Stadt')
        self.onConfirm = onConfirm
        self.body.grid_columnconfigure(0, weight=1)

        customtkinter.CTkLabel(
            self.body, text='Stadt', font=theme.font(12),
            text_color=theme.MUTED,
        ).grid(row=0, column=0, columnspan=2, sticky='w', pady=(4, 2))
        self.picker = SearchableComboBox(
            self.body, values=CITIES, placeholder='Stadt suchen …')
        self.picker.grid(row=1, column=0, columnspan=2, sticky='ew',
                         pady=(0, 6))
        city = waypoint['options'].get('city') if waypoint is not None else None
        if city is not None:
            self.picker.set(city)

    def confirm(self):
        if self.picker.get() not in CITIES:
            return self.fail('Stadt aus der Liste waehlen.')
        self.onConfirm(None, {'city': self.picker.get()})
        self.destroy()
