@model List<Meal>
@{
    ViewData["Title"] = "Alla måltider";
}

<h1>Alla måltider</h1>

<table class="table">
    <thead>
        <tr>
            <th>Namn</th>
            <th>Beskrivning</th>
            <th>Protein</th>
            <th>Kolhydrat</th>
            <th>Receptlänk</th>
            <th>Skapad</th>
            <th>Redigera</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var meal in Model)
        {
            <tr>
                <td>
                    <a asp-controller="Meal" asp-action="View" asp-route-id="@meal.Id">@meal.Name</a>
                </td>
                <td>@meal.Description</td>
                <td>@meal.ProteinType</td>
                <td>@meal.CarbType</td>
                <td>
                    @if (!string.IsNullOrWhiteSpace(meal.RecipeUrl))
                    {
                        <a href="@meal.RecipeUrl" target="_blank">Länk</a>
                    }
                </td>
                <td>@meal.CreatedAt.ToString("yyyy-MM-dd")</td>
                <td>
                    <a asp-controller="Meal" asp-action="Edit" asp-route-id="@meal.Id">Redigera</a>
                </td>
            </tr>
        }
    </tbody>
</table>

<a class="btn btn-success" asp-controller="Meal" asp-action="Edit">Lägg till ny måltid</a>
