@model WeeklyPartChanges

@{
    ViewData["Title"] = "Weekly Part Changes | Mesa Reporting Services";
}

<div aria-label="breadcrumb">
    <ol class="breadcrumb">
        <li class="breadcrumb-item"><a asp-area="" asp-controller="Home" asp-action="Index">Home</a></li>
        <li class="breadcrumb-item"><a asp-area="" asp-controller="PlanningReport" asp-action="Index">Planning Reports</a></li>
        <li class="breadcrumb-item active" aria-current="page">Weekly Part Changes Report</li>
    </ol>
</div>
<br />

<h1 class="text-center">Weekly Part Changes</h1>

<div>
    <div class="row">
        <div class="col-6">
            <p>Number of Part Changes: @Model.TotalPartChanges</p>
        </div>
        <div class="col-6">
            <p class="text-end">@Model.StartDate - @Model.EndDate</p>
        </div>
    </div>
    <div>
        <table class="table">
            <thead>
                <tr>
                    <th scope="col">Reactor</th>
                    <th scope="col">PSN</th>
                    <th scope="col">WO_COUNT</th>
                </tr>
            </thead>
            <tbody>
                @for (int i = 0; i < Model.ReactorPSNWORuns.Count; i++)
                {
                    int count = 1;
                    bool doesMatch = false;

                    if (i + count < Model.ReactorPSNWORuns.Count)
                        doesMatch = Model.ReactorPSNWORuns[i].REACTOR == Model.ReactorPSNWORuns[i + count].REACTOR;

                    while (doesMatch)
                    {
                        count++;
                        if (i + count < Model.ReactorPSNWORuns.Count)
                            doesMatch = Model.ReactorPSNWORuns[i].REACTOR == Model.ReactorPSNWORuns[i + count].REACTOR;
                        else
                            doesMatch = false;
                    }

                    for (int j = 0; j < count; j++)
                    {
                        string tableColor = "";

                        if (count > 1)
                            tableColor = "table-info";

                        <tr class="align-middle @tableColor">
                            @if (j == 0)
                            {
                                <td rowspan="@(count)">@Model.ReactorPSNWORuns[i].REACTOR</td>
                                <td>@Model.ReactorPSNWORuns[i].PSN</td>
                                <td>@Model.ReactorPSNWORuns[i].WO_COUNT</td>
                            }
                            else
                            {
                                <td>@Model.ReactorPSNWORuns[i + j].PSN</td>
                                <td>@Model.ReactorPSNWORuns[i + j].WO_COUNT</td>
                            }
                        </tr>
                    }
                    i = i + (count - 1);
                }
            </tbody>
        </table>
    </div>
</div>