import { MenuItems } from '../../imports/api/menuItems.js';

Template.menuItemsTbl.onCreated(function() {
    this.autorun( () => {
        this.subscribe("myMenuItems", Session.get("menuId"));
    });
});

Template.menuItemsTbl.onRendered(function() {

});

Template.menuItemsTbl.helpers({
    thisMenuItems: function() {
        return MenuItems.find({}, { sort: { serveDateActual: 1 }});
    }
});

Template.menuItemsTbl.events({
    'click .deleteMenuItem' (event) {
        event.preventDefault();
        let menuItemId = this._id;
        Meteor.call('delete.menuItem', menuItemId, function(err, result) {
            if (err) {
                console.log("    ERROR: can't delte menu item: " + err);
            } else {
                console.log("    SUCCESS deleting menu item.");
            }
        });
    },
});