@using PantheonRA.BackOffice;
@using PantheonRA.WebApi.Contracts.Enums;

@if ((!PantheonRA.BackOffice.CurrentUser.HasGranules() ||
    PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.TravelOrderGranule) || PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.WorkRosterGranule)) && 
    (CurrentUser.CanAccess(Permissions.EMPLOYEES) ||
     CurrentUser.CanAccess(Permissions.EMPLOYEES_OWN_DATA) ||
     CurrentUser.CanAccess(Permissions.TIME_RECORDS) ||
     CurrentUser.CanAccess(Permissions.TRAVEL_ORDERS) ||
     CurrentUser.CanAccess(Permissions.TRAVEL_ORDERS_OWN_DATA)))
{
    <li data-list-item-id="HumanResources"
        class="dropdown @Html.IsSelected("Index", "TravelOrders") @Html.IsSelected("Create", "TravelOrderAllData") @Html.IsSelected("Edit", "TravelOrderAllData")
                            @Html.IsSelected("Index", "Vehicles") @Html.IsSelected("Create", "Vehicles") @Html.IsSelected("Edit", "Vehicles")
                            @Html.IsSelected("Index", "Employees") @Html.IsSelected("Create", "Employees") @Html.IsSelected("Edit", "Employees")
                            @Html.IsSelected("Index", "TimeRecords") @Html.IsSelected("Index", "TimeAttendance") @Html.IsSelected("Index", "TimeRecordRequests")
                            @Html.IsSelected("Index", "Evaluation")">
    
        <a href="@(PantheonRA.BackOffice.CurrentUser.HasGranules() ?
            (PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.WorkRosterGranule) ? Url.Action("Index", "TimeRecords") : Url.Action("Create", "TravelOrderAllData")) : Url.Action("Index", "Employees"))">
            <i class="fas fa-users"></i> <span class="nav-label">
                @(PantheonRA.BackOffice.CurrentUser.HasGranules() ?
                (PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.WorkRosterGranule) ? Loc.TimeRecord.SetMenuNameLength() : Loc.MenuTravelOrders.SetMenuNameLength()) : Loc.Staff)
            </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 d">
                @if (!PantheonRA.BackOffice.CurrentUser.HasGranules() &&
                    (CurrentUser.CanAccess(Permissions.EMPLOYEES) || CurrentUser.CanAccess(Permissions.EMPLOYEES_OWN_DATA)))
                {
                    <li><a href="@Url.Action("Index", "Employees")">@Loc.EmployeesNavMenu.SetMenuNameLength()</a></li>
                }
                @if ((!PantheonRA.BackOffice.CurrentUser.HasGranules() || PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.WorkRosterGranule))
                    && CurrentUser.CanAccess(Permissions.TIME_RECORDS))
                {
                    <li><a href="@Url.Action("Index", "TimeRecords")">@Loc.TimeRecord.SetMenuNameLength()</a></li>
                }
                @if (!PantheonRA.BackOffice.CurrentUser.HasGranules() &&
                    (CurrentUser.CanAccess(Permissions.EMPLOYEES) || CurrentUser.CanAccess(Permissions.EMPLOYEES_OWN_DATA)))
                {
                    <li><a href="@Url.Action("Index", "Evaluation")">@Loc.Evaluation.SetMenuNameLength()</a></li>
                }
                @if ((!PantheonRA.BackOffice.CurrentUser.HasGranules() || PantheonRA.BackOffice.CurrentUser.HasGranule(Granules.TravelOrderGranule)) &&
                    (CurrentUser.CanAccess(Permissions.TRAVEL_ORDERS) || CurrentUser.CanAccess(Permissions.TRAVEL_ORDERS_OWN_DATA)))
                {
                    <li><a href="@Url.Action("Create", "TravelOrderAllData")">@Loc.MenuTravelOrders.SetMenuNameLength()</a></li>
                }
                @if (!PantheonRA.BackOffice.CurrentUser.HasGranules() && CurrentUser.CanAccess(Permissions.TRAVEL_ORDERS))
                {
                    <li><a href="@Url.Action("Index", "Vehicles")">@Loc.MenuVehicles.SetMenuNameLength()</a></li>
                }
            </ul>
        }
    </li>
}