@model List<FotbalPortal.Models.PlayerResult>

@{
    ViewBag.Title = "Sestavy zápasu";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Sestavy</h2>

<div>
    @using (Html.BeginForm("Sheet", "Result", FormMethod.Post)) {
        int j = 0;
        
        @Html.AntiForgeryToken();
        @Html.ValidationSummary(true);
        
        <table id="sheet">
            <tr>
                <th>Hráč</th><th>Počet minut</th><th>Góly</th><th>Inkasované</th><th>ŽK</th><th>ČK</th>
            </tr>

        @foreach (var i in Model)
        {
            string trida = "";
            if (j == 10) { trida = "line"; } 
            
            <tr class="@trida">
                <td>@Html.DropDownListFor(a => a[j].playerID, new SelectList(ViewBag.playerID, "Value", "Text"), "- žádný -" )</td>
                <td>@Html.TextBoxFor(a => a[j].minutes)</td>
                <td>@Html.TextBoxFor(a => a[j].goals)</td>
                <td>@Html.TextBoxFor(a => a[j].goalsReceived)</td>
                <td>@Html.TextBoxFor(a => a[j].yellowCards)</td>
                <td>@Html.TextBoxFor(a => a[j].redCards)</td>
            </tr>
            @Html.HiddenFor(a => a[j].clubID)
            @Html.HiddenFor(a => a[j].resultID)
            @Html.HiddenFor(a => a[j].id)
            @Html.HiddenFor(a => a[j].playerID)
            
            j++;
        }

        </table>     
        <input type="submit" value="Uložit sestavu" />
    }
</div>

@section Scripts {
    <script language="javascript">
        $(document).ready(function () {
            $("select").each(function (index) {
                $(this).find("option:first").attr("value", "0");

                var value = $("input[name='[" + index + "].playerID']").val();
                $(this).val(value);
            });
        });

    </script>   
}
