@{
    ViewData["Title"] = "Scoring Configuration";
    var constants = ViewBag.ScoringConstants as IEnumerable<ScoringConstantDto>;
    var placements = ViewBag.PlacementPointConfigs as IEnumerable<PlacementPointConfigDto>;
}

<h2>Scoring Configuration</h2>
<hr />

<partial name="_Notification" />

<div class="row">
    <div class="col-md-8">
        <div class="card shadow-sm mb-4">
            <div class="card-header bg-dark text-white">
                <h5 class="mb-0">Scoring Constants (World Athletics)</h5>
            </div>
            <div class="card-body p-0">
                <table class="table table-hover mb-0">
                    <thead><tr><th>Event</th><th>A</th><th>B</th><th>C</th><th>Unit</th><th>Action</th></tr></thead>
                    <tbody>
                        @if (constants != null)
                        {
                            @foreach (var c in constants)
                            {
                                <tr>
                                    <form asp-action="UpdateScoringConstant" method="post">
                                        <input type="hidden" name="ScoringConstantId" value="@c.ScoringConstantId" />
                                        <td>@c.EventName</td>
                                        <td><input type="number" step="0.00001" name="A" value="@c.A" class="form-control form-control-sm" style="width:100px" /></td>
                                        <td><input type="number" step="0.1" name="B" value="@c.B" class="form-control form-control-sm" style="width:80px" /></td>
                                        <td><input type="number" step="0.01" name="C" value="@c.C" class="form-control form-control-sm" style="width:80px" /></td>
                                        <td>@c.Unit</td>
                                        <td><button type="submit" class="btn btn-sm btn-outline-primary">Save</button></td>
                                    </form>
                                </tr>
                            }
                        }
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card shadow-sm">
            <div class="card-header bg-dark text-white">
                <h5 class="mb-0">Placement Points</h5>
            </div>
            <div class="card-body p-0">
                <table class="table table-hover mb-0">
                    <thead><tr><th>Place</th><th>Points</th><th>Action</th></tr></thead>
                    <tbody>
                        @if (placements != null)
                        {
                            @foreach (var p in placements.OrderBy(x => x.Placement))
                            {
                                <tr>
                                    <form asp-action="UpdatePlacementPointConfig" method="post">
                                        <input type="hidden" name="PlacementPointConfigId" value="@p.PlacementPointConfigId" />
                                        <input type="hidden" name="Placement" value="@p.Placement" />
                                        <td>#@p.Placement</td>
                                        <td><input type="number" name="Points" value="@p.Points" class="form-control form-control-sm" style="width:60px" /></td>
                                        <td><button type="submit" class="btn btn-sm btn-outline-primary">Save</button></td>
                                    </form>
                                </tr>
                            }
                        }
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
