"""Food-Tab: automatisches Essen als einzelne Regelkarte."""
import customtkinter

from .ruleCard import HealingRuleCard


def eatFoodSpec():
    def cfg(context):
        return context.context['healing']['eatFood']

    return {
        'title': 'Eat food',
        'toggle': {
            'get': lambda context: cfg(context)['enabled'],
            'set': lambda context, value: context.toggleFoodByKey(value),
        },
        'fields': [
            {
                'type': 'hotkey', 'name': 'hotkey', 'label': 'Hotkey:',
                'get': lambda context: cfg(context)['hotkey'],
                'set': lambda context, key: context.setFoodHotkey(key),
            },
        ],
    }


class FoodTab(customtkinter.CTkFrame):
    def __init__(self, parent, context):
        super().__init__(parent, fg_color='transparent')
        self.context = context
        self.grid_columnconfigure(0, weight=1)

        self.eatFoodCard = HealingRuleCard(self, context, eatFoodSpec())
        self.eatFoodCard.grid(column=0, row=0, padx=10, pady=10, sticky='new')
