@using PantheonRA.WebApi.Contracts.Enums;

@if ((!PantheonRA.BackOffice.CurrentUser.HasGranules() ||
    PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.WorkRosterGranule) || PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.DocumentsTasksGranule) ||
    PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.B2BGranule)) &&
    (PantheonRA.BackOffice.CurrentUser.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.DOCUMENTS) ||
    PantheonRA.BackOffice.CurrentUser.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.TASKS)))
{
    <li data-list-item-id="DocumentTask"
        class="dropdown @Html.IsSelected("Index", "Documents") @Html.IsSelected("Create", "Documents") @Html.IsSelected("Edit", "Documents")
                    @Html.IsSelected("RunWorkflow", "Documents") @Html.IsSelected("Index", "Task") @Html.IsSelected("Edit", "Task") ">
        <a href="@(PantheonRA.BackOffice.CurrentUser.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.DOCUMENTS) &&
                    (!PantheonRA.BackOffice.CurrentUser.HasGranules() || PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.DocumentsTasksGranule) || PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.B2BGranule))
                    ? Url.Action("Index", "Documents") : Url.Action("Index", "Task"))">
            <i class="fas fa-file-check"></i> <span class="nav-label">
                @(PantheonRA.BackOffice.CurrentUser.HasGranules() && !PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.DocumentsTasksGranule) ?
                    (PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.B2BGranule) ? Loc.Documents : Loc.Tasks) : Loc.DocumentsNavMenu)
            </span>
        </a>

        @{ var allGranules = GranulesHelper.GetAllActiveGranules(); }

        @if (!PantheonRA.BackOffice.CurrentUser.HasGranules() || (PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.WorkRosterGranule) && allGranules.Count > 1))
        {
            <ul class="dropdown-menu dropdown-menu-right">
                @if ((!PantheonRA.BackOffice.CurrentUser.HasGranules() || PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.DocumentsTasksGranule))
                    && PantheonRA.BackOffice.CurrentUser.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.DOCUMENTS))
                {
                    <li><a href="@Url.Action("Index", "Documents")">@Loc.Documents.SetMenuNameLength()</a></li>
                }
                @if ((!PantheonRA.BackOffice.CurrentUser.HasGranules() ||
                    PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.WorkRosterGranule) || PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.DocumentsTasksGranule))
                    && PantheonRA.BackOffice.CurrentUser.CanAccess(PantheonRA.WebApi.Contracts.Enums.Permissions.TASKS))
                {
                    <li><a href="@Url.Action("Index", "Task")">@Loc.MenuTasks.SetMenuNameLength()</a></li>
                }
            </ul>
        }
    </li>
}