@model SummaryViewModel
@{
    ViewData["Title"] = "School Bus Checker";

    var busRoutes = Model.Routes.OrderBy(r => r.BusNumber).ToList();
    var hasDelays = busRoutes.Any();

    var userBusRoutes = Model.User.Routes
        .GroupJoin(busRoutes, ur => ur.BusNumber, br => br.BusNumber, (ur, routes) => new
        {
            UserRoute = ur,
            RouteDisruptions = routes
        })
        .OrderBy(r => r.UserRoute.BusNumber)
        .ToList();
}

@if (hasDelays)
{
    <h3 class="alert-heading">Uh oh! We have @busRoutes.Count delays</h3>
}
else
{
    <h3 class="alert-heading">Good news! No delays today!</h3>
}

@foreach (var busRoute in userBusRoutes)
{
    var hasUserDelays = busRoute.RouteDisruptions.Any();

    <div class="alert @(hasUserDelays ? "alert-danger" : "alert-success")">
        <strong>@busRoute.UserRoute.Label (@busRoute.UserRoute.BusNumber) - </strong>

        @if (busRoute.RouteDisruptions.Any())
        {
            var delayList = string.Join(", ", busRoute.RouteDisruptions
                .Select(r => $"{r.Impact} ({r.Schedules}) for {r.Schools}")
                .ToArray());

            <strong>@delayList</strong>
        }
        else
        {
            @:No Delays!
        }

    </div>
}