@using BlazingPizza.Services;

@page "/"
@inject HttpClient HttpClient
@inject NavigationManager NavigationManager
@inject OrderState OrderState


<div class="main">
	<h1>Blazing Pizzas</h1>
	<ul class="pizza-cards">
		@if (_specials != null)
		{
			@foreach (var special in _specials)
			{
				<li @onclick="@(() => OrderState.ShowConfigurePizzaDialog(special))" style="background-image: url('@special.ImageUrl')">
					<div class="pizza-info">
						<span class="title">@special.Name</span>
						<span class="description">@special.Description</span>
						<span class="price">@special.GetFormattedBasePrice()</span>
					</div>
				</li>
			}
		}
	</ul>
</div>

@if (OrderState.ShowingConfigureDialog)
{
	<ConfigurePizzaDialog 
		Pizza="OrderState.ConfiguringPizza"
		OnCancel="OrderState.CancelConfigurePizzaDialog"
		OnConfirm="OrderState.ConfirmConfigurePizzaDialog"/>
}

@code {
	private List<PizzaSpecial> _specials = new List<PizzaSpecial>();

	protected override async Task OnInitializedAsync()
	{
		_specials = await HttpClient.GetFromJsonAsync<List<PizzaSpecial>>(NavigationManager.BaseUri + "specials");
	}
}
		