@model IEnumerable<Francesco.Recipes.World.Views.Category.CategoryRecipesViewModel>

@{
	ViewData["Title"] = "Category Recipes";
}

<h1>Category Recipes</h1>

@foreach (var categoryRecipes in Model)
{
	<div class="category-section">
		<h2>@categoryRecipes.Category.Name</h2>
		<a asp-action="Create" asp-route-categoryId="@categoryRecipes.Category.Id" class="btn btn-primary">Rezept erstellen</a>
		<div class="recipes">
			@foreach (var recipe in categoryRecipes.Recipes)
			{
				<div class="recipe-card">
					<div class="recipe-image">
						@if (recipe.MediaFiles.Any() && recipe.MediaFiles.First().Data != null)
						{
							var mediaFile = recipe.MediaFiles.First();
							if (mediaFile.Data != null)
							{
								<img src="data:@mediaFile.MimeType;base64,@Convert.ToBase64String(mediaFile.Data)" alt="@recipe.Name" class="img-fluid" />
							}
						}
					</div>
					<div class="recipe-info">
						<h3>@recipe.Name</h3>
						<p>@recipe.Description</p>
						<p><strong>Difficulty:</strong> @recipe.Difficulty</p>
						<p><strong>Servings:</strong> @recipe.Servings</p>
						<p><strong>Preparation Time:</strong> @recipe.PreparationTime</p>
						<p><strong>Cooking Time:</strong> @recipe.CookingTime</p>
						<div class="recipe-favorite">
							@if (recipe.IsFavorite)
							{
								<form method="post" asp-action="RemoveFavorite" asp-controller="Recipe">
									<input type="hidden" name="recipeId" value="@recipe.Id" />
									<button type="submit" class="btn btn-danger">Remove from Favorites</button>
								</form>
							}
							else
							{
								<form method="post" asp-action="AddFavorite" asp-controller="Recipe">
									<input type="hidden" name="recipeId" value="@recipe.Id" />
									<button type="submit" class="btn btn-primary">Add to Favorites</button>
								</form>
							}
						</div>
					</div>
				</div>
			}
			<div class="recipe-card add-recipe-card">
				<a asp-action="Create" asp-route-categoryId="@categoryRecipes.Category.Id" class="btn btn-primary">Rezept hinzufügen</a>
			</div>
		</div>
	</div>
}

<style>
	.category-section {
		margin-bottom: 2rem;
	}

	.recipes {
		display: flex;
		flex-wrap: wrap;
	}

	.recipe-card {
		width: 200px;
		margin: 1rem;
		padding: 1rem;
		border: 1px solid #ccc;
		border-radius: 8px;
		box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
	}

	.recipe-image img {
		width: 100%;
		height: auto;
		border-radius: 8px;
	}

	.recipe-info {
		margin-top: 1rem;
	}

	.add-recipe-card {
		display: flex;
		align-items: center;
		justify-content: center;
		background-color: #f8f8f8;
		border: 2px dashed #ccc;
	}
</style>

