@model PermissionMappingModel
@using (Html.BeginForm())
{
    <div class="section-header">
        <div class="title">
            <img src="@Url.Content("~/Administration/Content/images/ico-configuration.png")" alt="" />
            @T("Admin.Configuration.ACL")
        </div>
        <div class="options">
            <button type="submit" name="save" value="save" class="t-button">@T("Admin.Common.Save")</button>
        </div>
    </div>
    
    <table class="adminContent">
        <tr>
            <td>
                @if (Model.AvailablePermissions.Count == 0)
                {
                    <text>No permissions defined</text>
                }
                else if (Model.AvailableCustomerRoles.Count == 0)
                {
                    <text>No customer roles available</text>
                }
                else
                {
                    <table class="tablestyle" cellspacing="0" rules="all" border="1" style="width: 100%;
                        border-collapse: collapse;">
                        <tbody>
                            <tr class="headerstyle">
                                <th scope="col">
                                    <b>@T("Admin.Configuration.ACL.Permission")</b>
                                </th>
                                @foreach (var cr in Model.AvailableCustomerRoles)
                                {
                                    <th scope="col">
                                        <b>@cr.Name</b>
                                    </th>
                                }
                            </tr>
                            @{
                                bool altRow = true;
                            }
                            @foreach (var pr in Model.AvailablePermissions)
                            {
                                altRow = !altRow;
                                <tr class="@(altRow ? "altrowstyle" : "rowstyle")">
                                    <td>
                                        <span>@pr.Name</span>
                                    </td>
                                    @foreach (var cr in Model.AvailableCustomerRoles)
                                    {
                                        var allowed = Model.Allowed.ContainsKey(pr.SystemName) && Model.Allowed[pr.SystemName][cr.Id];
                                        <td>
                                            <input id="allow_@(cr.Id)" class="allow_@(cr.Id)" type="checkbox" value="@(pr.SystemName)" name="allow_@(cr.Id)" @(allowed ? " checked=checked" : null) />
                                        </td>
                                    }
                                </tr>
                            }
                        </tbody>
                    </table>
                }
            </td>
        </tr>
    </table>

}
