include mixins_week

mixin show_changes(pentrys, n)
	if(pentrys.length > 0)
		fieldset
			legend !{n}
			each pentry in pentrys
				- var my_uid = generateUID();
				.panel.panel-primary(style="margin-left: 10px;")
					.panel-heading
						h3.panel-title(data-toggle="collapse", data-target="#"+my_uid, style="cursor: pointer;") !{pentry.name}
							.small(style="font-size: 85%;")
								i !{pentry.punit}
					.panel-collapse.collapse(id=my_uid)
						.panel-body
							ul.nav.nav-tabs
								each c in pentry.changes
									- var cls = (c.idx === 0 ? "active" : "");
									- c.tab_id = generateUID();
									- var color = c.type === "new" ? "green" : (c.type==="remove" ? "red" : "gold")
									li(class=cls, style="border-bottom: 3px solid " + color +";")
										a(data-toggle="tab", href="#"+c.tab_id) !{c.user} !{c.tab_id}
									
							.tab-content(style="padding-left: 10px; padding-right: 10px;")
								each c in pentry.changes
									- var cls = (c.idx === 0 ? "active" : "");
									- var clss = ["tab-pane", cls]
									div(class=clss, id=c.tab_id)
										.btn-group.btn-group-sm(style="margin-top: 10px;")
											button.btn.btn-success Akzeptieren
											button.btn.btn-danger(data-toggle="modal", data-target="#confirmReject") Ablehnen

										.changes_details
											if(c.type !== "new")
												if(pentry.punit !== c.punit)
													p(style="margin-bottom: 10px;")
														b !{c.punit}
												else
													p.small(style="margin-bottom: 10px;")
														b Gleicher pastoraler Kontext.

											if(c.diff !== "")
												p(style="margin-bottom: 0px;")
													b Diff
												pre
													code
														!{c.diff}
											p(style="margin-bottom: 0px;")
												b Roh-Daten
											pre
												code
													!{c.data}
										

mixin pday_with_changes(pday)
	.panel.panel-default(data-date=pday.date)
		.panel-heading
			h3.panel-title(data-toggle="collapse", data-target="#PANEL_#{pday.date}", aria-expanded="false", aria-controls="PANEL_#{pday.date}", style="cursor: pointer;") !{pday.date_pretty}
		.panel-collapse.collapse(id="PANEL_#{pday.date}")
			.panel-body(style="padding: 10px;")
				- var celebration_printed = false;
				.day_details
					table(width="100%")
						+week_day_mobile(pday.day)
				+show_changes(pday.events, "Ereignisse")
				+show_changes(pday.todos, "Zu Tun")
				+show_changes(pday.away, "Abwesend")
				+show_changes(pday.keep_in_mind, "Zu Beachten")
				+show_changes(pday.vehicle_use, "Fahrzeugbenutzung")

each day in changes
	+pday_with_changes(day)
