@page "/SpeisekarteChinesich"

@inject HttpClient Http
@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage

<h1>Speisekarte Chinesisch</h1>
<div class="container">
	<div class="row">
		<div class="col-8">
			<div class="btn-group d-flex" role="group">
				<button type="button" class="btn">Chinesisch</button>
				<button type="button" class="btn">Nudel</button>
				<button type="button" class="btn">Reis</button>
				<button type="button" class="btn">Nachspeise</button>
			</div>

			@foreach (var item in menuitemueberkategories)
			{
				@if (item.Bezeichnung == "Chinesisch")
				{
					@foreach (var item2 in menuitemkategories)
					{
						if (item2.MenuItemUeberkategorieIdmenuItemUeberkategorie == item.IdmenuItemUeberkategorie)
						{
							@foreach (var item3 in menuitems)
							{
								if (item2.IdmenuItemKategorie == item3.MenuItemKategorieIdmenuItemKategorie)
								{
									<div class="card mt-3 " @onclick="@(() => SetMenuItemId(item3.IdmenuItem))">
										<div class="card-body">
											@*create two divs columns*@
											<div class="row">
												<div class="col-8">
													<h5 class="card-title">@item3.Bezeichnung</h5>
													<p class="card-text">@item3.Zusatzinformation</p>
												</div>
												@*div text center*@
												<div class="col-4 d-flex justify-content-center align-items-center">
													<div style="font-size:15pt;">@item3.Preis</div>
												</div>
											</div>
										</div>
									</div>
								}
							}
						}
					}
				}
			}
		</div>
		<div class="col-4">
			@* warenkorb anzeige als bootstrap card*@
			<div class="card">
				<div class="card-header">
					Warenkorb
				</div>
				@if (menuitemIds.Count == 0)
				{
					<div class="card-body">
						<h5 class="card-title" style="font-size:10pt; margin-bottom:0px;">Warenkorb ist leer</h5>
					</div>
				}
				else
				{
					@foreach (var item in menuitemIds)
					{
						@foreach (var item2 in menuitems)
						{
							@if (item.Key == item2.IdmenuItem)
							{
								<div class="card-body">
									<p>@item.Value</p>
									<h5 class="card-title" style="font-size:10pt; margin-bottom:0px;">@item2.Bezeichnung</h5>
									<p class="card-text" style="font-size:8pt;margin-bottom:0px;">@item2.Zusatzinformation</p>
									<p class="card-text" id="preis" style="text-align:right; "><span style="background-color:#c7ffd5; border-radius:20px; font-size:10pt; padding:5px">@item2.Preis</span></p>
								</div>
							}
						}
					}
				}
			</div>
			<div class="d-flex flex-column mb-5">
				<a href="/speisekarte" class="btn btn-primary mx-2 mt-5">Zurück</a>
				<a href="/shopping_cart" class="btn btn-primary mx-2 mt-1 mb-5">Weiter</a>
			</div>
		</div>
	</div>
</div>


@code {
	public Dictionary<int, int> menuitemIds = new Dictionary<int, int>();

	private void SetMenuItemId(int id)
	{
		if (menuitemIds.ContainsKey(id))
		{
			menuitemIds[id]++;
		}
		else
		{
			menuitemIds.Add(id, 1);
		}
		localStorage.SetItem<Dictionary<int, int>>("MenuItemIds", menuitemIds);
	}
	// allergien, bestellungsposition, kunde, menuitem, menuitemkategorie, menuitemueberkategorie, rabatt

	private List<Allergie> allergien = new List<Allergie>();
	private List<Bestellungsposition> bestellungspositions = new List<Bestellungsposition>();
	private List<Kunde> kunden = new List<Kunde>();
	private List<Menuitem> menuitems = new List<Menuitem>();
	private List<Menuitemkategorie> menuitemkategories = new List<Menuitemkategorie>();
	private List<Menuitemueberkategorie> menuitemueberkategories = new List<Menuitemueberkategorie>();
	private List<Rabatt> rabatte = new List<Rabatt>();

	protected override async Task OnInitializedAsync()
	{
		if (localStorage.GetItem<Dictionary<int, int>>("MenuItemIds") != null)
		{
			menuitemIds = localStorage.GetItem<Dictionary<int, int>>("MenuItemIds");
		}

		allergien = await Http.GetFromJsonAsync<List<Allergie>>("https://localhost:7076/api/allergien");
		bestellungspositions = await Http.GetFromJsonAsync<List<Bestellungsposition>>("https://localhost:7076/api/bestellungspositionen");
		kunden = await Http.GetFromJsonAsync<List<Kunde>>("https://localhost:7076/api/kunden");
		menuitems = await Http.GetFromJsonAsync<List<Menuitem>>("https://localhost:7076/api/Menuitems");
		menuitemkategories = await Http.GetFromJsonAsync<List<Menuitemkategorie>>("https://localhost:7076/api/Menuitemkategories");
		menuitemueberkategories = await Http.GetFromJsonAsync<List<Menuitemueberkategorie>>("https://localhost:7076/api/Menuitemueberkategories");
		rabatte = await Http.GetFromJsonAsync<List<Rabatt>>("https://localhost:7076/api/Rabatte");

	}

	public class Allergie
	{
		public int Idallergie { get; set; }

		public string? Beschreibung { get; set; }

		public virtual ICollection<Menuitem> MenuItemIdmenuItems { get; set; } = new List<Menuitem>();
	}
	public class Bestellungsposition
	{
		public int Idbestellung { get; set; }

		public int? Menge { get; set; }

		public DateTime? Datum { get; set; }

		public int KundeIdkunde { get; set; }

		public int RabattIdrabatt { get; set; }

		public virtual Kunde KundeIdkundeNavigation { get; set; } = null!;

		public virtual Rabatt RabattIdrabattNavigation { get; set; } = null!;

		public virtual ICollection<Menuitem> MenuItemIdmenuItems { get; set; } = new List<Menuitem>();
	}
	public class Kunde
	{
		public int Idkunde { get; set; }

		public string? Code { get; set; }

		public int? Treuepunkte { get; set; }

		public virtual ICollection<Bestellungsposition> Bestellungspositions { get; set; } = new List<Bestellungsposition>();
	}

	public class Menuitem
	{
		public int IdmenuItem { get; set; }

		public string? Bezeichnung { get; set; }

		public string? Zusatzinformation { get; set; }

		public decimal? Preis { get; set; }

		public int MenuItemKategorieIdmenuItemKategorie { get; set; }

		public virtual Menuitemkategorie MenuItemKategorieIdmenuItemKategorieNavigation { get; set; } = null!;

		public virtual ICollection<Allergie> AllergieIdallergies { get; set; } = new List<Allergie>();

		public virtual ICollection<Bestellungsposition> BestellungspositionIdbestellungs { get; set; } = new List<Bestellungsposition>();
	}
	public class Menuitemkategorie
	{
		public int IdmenuItemKategorie { get; set; }

		public string? Bezeichnung { get; set; }

		public int MenuItemUeberkategorieIdmenuItemUeberkategorie { get; set; }

		public virtual Menuitemueberkategorie MenuItemUeberkategorieIdmenuItemUeberkategorieNavigation { get; set; } = null!;

		public virtual ICollection<Menuitem> Menuitems { get; set; } = new List<Menuitem>();
	}

	public class Menuitemueberkategorie
	{
		public int IdmenuItemUeberkategorie { get; set; }

		public string? Bezeichnung { get; set; }

		public virtual ICollection<Menuitemkategorie> Menuitemkategories { get; set; } = new List<Menuitemkategorie>();
	}

	public class Rabatt
	{
		public int Idrabatt { get; set; }

		public decimal? Prozent { get; set; }

		public DateTime? GueltigkeitVon { get; set; }

		public DateTime? GueltigkeitBis { get; set; }

		public virtual ICollection<Bestellungsposition> Bestellungspositions { get; set; } = new List<Bestellungsposition>();
	}







}