@{
    Layout = null;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Week Planner - Recipe Manager</title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" />
    <link rel="stylesheet" href="~/css/site.css" />
</head>

<body>
    <header>
        <nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-dark bg-primary border-bottom box-shadow mb-3">
            <div class="container-fluid">
                <a class="navbar-brand" href="/">
                    <i class="fas fa-utensils"></i> Recipe Manager
                </a>
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse"
                    aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
                <div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
                    <ul class="navbar-nav flex-grow-1">
                        <li class="nav-item">
                            <a class="nav-link" href="/">
                                <i class="fas fa-home"></i> All Recipes
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link active" href="/WeekPlanner">
                                <i class="fas fa-calendar-week"></i> Week Planner
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link" href="/Recipe/Create">
                                <i class="fas fa-plus"></i> Add Recipe
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
    </header>
    <div class="container-fluid">
        <main role="main" class="pb-3">
            <h1 class="mb-4">📅 Week Planner</h1>

            @if (Model?.CurrentWeekPlan == null)
            {
                <div class="alert alert-info">
                    <h4>No meal plan for this week yet!</h4>
                    <p>Create a new week plan to start planning your meals.</p>
                    <form action="/WeekPlanner/CreateWeekPlan" method="post" class="d-inline">
                        <input type="hidden" name="startDate"
                            value="@(Model?.StartDate.ToString("yyyy-MM-dd") ?? DateTime.Today.ToString("yyyy-MM-dd"))" />
                        <button type="submit" class="btn btn-primary">
                            Create Week Plan
                        </button>
                    </form>
                </div>
            }
            else
            {
                <div class="alert alert-success">
                    <h4>Week Plan: @Model!.CurrentWeekPlan!.Name</h4>
                    <p>Week of: @Model!.StartDate.ToString("MMMM dd, yyyy")</p>
                </div>

                <div class="row">
                    @foreach (var dayPlan in Model!.CurrentWeekPlan!.DayPlans)
                    {
                        <div class="col-md-6 col-lg-4 mb-3">
                            <div class="card">
                                <div class="card-header d-flex justify-content-between">
                                    <h5 class="mb-0">@dayPlan.DayOfWeek</h5>
                                    <small class="text-muted">@dayPlan.Date.ToString("MMM dd")</small>
                                </div>
                                <div class="card-body">
                                    @if (dayPlan.Recipe != null)
                                    {
                                        <h6 class="card-title">
                                            <a href="/Recipe/Details/@dayPlan.Recipe.Id" class="text-decoration-none">
                                                @dayPlan.Recipe.Title
                                            </a>
                                        </h6>
                                        @if (!string.IsNullOrEmpty(dayPlan.MainIngredient))
                                        {
                                            <span class="badge bg-primary mb-2">@dayPlan.MainIngredient</span>
                                        }
                                        @if (!string.IsNullOrEmpty(dayPlan.Recipe.Time))
                                        {
                                            <span class="badge bg-info mb-2">@dayPlan.Recipe.Time</span>
                                        }
                                    }
                                    else
                                    {
                                        <p class="text-muted mb-2">No recipe selected</p>
                                        @if (!string.IsNullOrEmpty(dayPlan.MainIngredient))
                                        {
                                            <span class="badge bg-secondary mb-2">@dayPlan.MainIngredient</span>
                                        }
                                    }
                                </div>
                                <div class="card-footer">
                                    <div class="btn-group w-100" role="group">
                                        <a href="/WeekPlanner/ConfigureDay?weekPlanId=@Model.CurrentWeekPlan.Id&dayOfWeek=@dayPlan.DayOfWeek"
                                            class="btn btn-sm btn-outline-primary">
                                            Configure
                                        </a>
                                        <form action="/WeekPlanner/RandomizeRecipe" method="post" class="d-inline"
                                            style="flex: 1;">
                                            <input type="hidden" name="dayPlanId" value="@dayPlan.Id" />
                                            <button type="submit" class="btn btn-sm btn-outline-success w-100">
                                                Random Recipe
                                            </button>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    }
                </div>

                <div class="mt-4">
                    <h5>Week Navigation</h5>
                    <div class="btn-group" role="group">
                        <a href="/WeekPlanner?startDate=@Model.StartDate.AddDays(-7).ToString("yyyy-MM-dd")"
                            class="btn btn-outline-secondary">
                            ← Previous Week
                        </a>
                        <a href="/WeekPlanner?startDate=@Model.StartDate.AddDays(7).ToString("yyyy-MM-dd")"
                            class="btn btn-outline-primary">
                            Next Week →
                        </a>
                    </div>
                </div>
            }
        </main>
    </div>

    <footer class="border-top footer text-muted mt-5">
        <div class="container">
            &copy; @DateTime.Now.Year - Recipe Manager - Your Personal Recipe Collection
        </div>
    </footer>
    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
    <script src="~/js/site.js"></script>
</body>

</html>