extends ./wrapper

mixin menu-item-adm(name, desc, price, prefix, newItem)
	.row
		.col-md-1
			if newItem
				button.btn.btn-sm.btn-success(type="submit",form="#{prefix}")
					+icon("ok")
			else
				form(style="display:inline",method="post",action="")
					input(type='hidden',name='del',value='#{prefix}')
					button.btn.btn-sm.btn-danger(type="submit")
						+icon("remove")
				button.btn.btn-sm.btn-primary(type="submit",form="#{prefix}")
					+icon("edit")
		form.col-md-11(id="#{prefix}",method="post",action="")
			.col-md-9
				input(type='hidden',name='nametag',value='#{prefix}')
				+input-val-simple("text",prefix + "-name","Name","name","name",name)
				+input-val-simple("text",prefix + "-desc","Beschreibung","desc","desc",desc)
			.col-md-3.text-right
				+input-group("","€")
					input.form-control(type="number",id="#{prefix + '-price'}",name="price",value="#{price}").text-right

mixin menu-item(name, desc, price)
	.row
		.col-md-9
			span.lead= name
			br
			span.small= desc
		.col-md-3(style="display: flex;flex-direction: column;justify-content: center;")
			p.text-right #{price.toFixed(2).replace(/(\d)(?=(\d{3})+\,)/g, '$1,').replace(/^(.*)\.(.*)$/g, '$1,$2€')}


mixin menu-cat(name, anchor, content, adm, prefix)
	a(name= anchor)
	h2= name
	.container
		.row
			.col-md-10.col-md-offset-1.stripe
				if adm
					each val, index in content
						+menu-item-adm(val.name, val.desc, val.price, prefix + "-" + index, "")
					+menu-item-adm("", "", "", prefix + "-new", "x")
				else
					each val, index in content
						+menu-item(val.name, val.desc, val.price)
					

mixin menu-part(part, adm, prefix)
		each val, index in part
			+menu-cat(val.name, val.anchor, val.items, adm, prefix + "-" + index)

block vars
	- var pageTitle = 'Speisekarte'
block content
	.center-page
		h1 Speisen
		+menu-part(menuJSON.food, isAdmin, "f")
		h1 Getränke
		+menu-part(menuJSON.drinks, isAdmin, "d")
		