from ui.crud import Crud, Json_External_Dialog_Editor_Cell_Widget
from ui.recipe_spec_editor import Recipe_Spec_Editor
from ui.widget import Widget


class Recipes_Management(Widget):
    def __init__(self):
        super().__init__()
        crud_aliases = {
            # "id": "Id",
            "name": "Ricetta",
            "client": "Cliente",
            "part_number": "N° disegno",
            "spec": "Specifica",
            "description": "Descrizione",
            "archived": "Archiviata",
        }
        self.crud = Crud(
            "recipes",
            display_name="GESTIONE RICETTE",
            # readonly=["id"],
            readonly=False,
            select=list(crud_aliases.keys()),
            fields_aliases=crud_aliases,
            autocomplete={
                "archived": False,
            },
            widget_classes={"spec": lambda *args, **kwargs: Json_External_Dialog_Editor_Cell_Widget(Recipe_Spec_Editor, *args, **kwargs), },
        )
        self.layout().addWidget(self.crud, 0, 0, -1, -1)
