@using Microsoft.AspNetCore.Authorization

@inject GreenTree.Strohrmann.ERP.Services.Authorization.AdministrationOptions AdministrationOptions
@inject GreenTree.Strohrmann.ERP.Services.Authorization.IAuthorizationService AuthorizationService

@{ 
	var isAdministrator = User.Claims
        .Any(c => c.Type == System.Security.Claims.ClaimTypes.NameIdentifier &&
                  c.Value == AdministrationOptions.Administrator);
}

<!DOCTYPE html>
<html lang="de">

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>@ViewData["Title"] - Strohrmann ERP</title>

    <!-- Bootstrap core CSS -->
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />

    <!-- FontAwesome core CSS -->
    <link rel="stylesheet" href="~/lib/font-awesome/css/all.min.css" />

    <!-- FontAwesome CSS -->
    <link rel="stylesheet" href="~/lib/font-awesome/css/fontawesome.min.css" />

    <!-- jQueryUI CSS -->
    <link rel="stylesheet" href="~/lib/jqueryui/jquery-ui.min.css" />

    <!-- DataTables CSS -->
    <link rel="stylesheet" href="~/lib/datatables/css/dataTables.bootstrap4.min.css" />

    <!-- Custom page CSS -->
    <link rel="stylesheet" href="~/css/site.css" />

    <!-- Custom styles for this template -->
    <link rel="stylesheet" href="~/css/simple-sidebar.css" />

</head>

<body>

    <!-- jQuery core JavaScript -->
    <script src="~/lib/jquery/dist/jquery.min.js"></script>

    <!-- Bootstrap core JavaScript -->
    <script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>

    <!-- jQuery UI JavaScript -->
    <script src="~/lib/jqueryui/jquery-ui.min.js"></script>

    <!-- DataTables JavaScript -->
    <script src="~/lib/datatables/js/jquery.dataTables.min.js"></script>
    <script src="~/lib/datatables/js/dataTables.bootstrap4.min.js"></script>
    <script src="~/lib/datatables-responsive/dataTables.responsive.js"></script>
    <!-- application core JavaScript -->
    <script src="~/js/site.js" asp-append-version="true"></script>

    @RenderSection("Scripts", required: false)

    <div class="d-flex" id="wrapper">

        <!-- Sidebar -->
        <div class="bg-light border-right" id="sidebar-wrapper">
            <div class="sidebar-heading">Strohrmann ERP</div>
            <div class="list-group list-group-flush">
                <h5 class="list-group-item">Dashboard</h5>
                <a asp-controller="Home" asp-action="Index" class="list-group-item list-group-item-action bg-light">
                    <span class="fas fa-fw fa-tachometer-alt"></span>
                    <span>Übersicht</span>
                </a>
                @if (isAdministrator) 
                {
                    <h5 class="list-group-item">Administration</h5>
                    <a asp-controller="Rights" asp-action="Index" class="list-group-item list-group-item-action bg-light">
                        <span class="fas fa-fw fa-user-friends w-10"></span>
                        <span>Benutzerverwaltung</span>
                    </a>
                }
                @if (isAdministrator || AuthorizationService.UserHasBasedataPolicy(User.Identity))
				{
                    <h5 class="list-group-item">Stammdaten</h5>
                    @if (isAdministrator || AuthorizationService.UserHasCategoryPolicy(User.Identity, "Customer"))
					{
                        <a asp-controller="Customer" asp-action="Index" class="list-group-item list-group-item-action bg-light">
                            <span class="fas fa-fw fa-user-tag"></span>
                            <span>Kunden</span>
                        </a>
					}
                    @if (isAdministrator || AuthorizationService.UserHasCategoryPolicy(User.Identity, "Employee"))
					{
                        <a asp-controller="Employee" asp-action="Index" class="list-group-item list-group-item-action bg-light">
                            <span class="fas fa-fw fa-people-carry"></span>
                            <span>Mitarbeiter</span>
                        </a>
					}
                    @if (isAdministrator || AuthorizationService.UserHasCategoryPolicy(User.Identity, "Material"))
					{
                        <a asp-controller="Material" asp-action="Index" class="list-group-item list-group-item-action bg-light">
                            <span class="fas fa-fw fa-box"></span>
                            <span>Material</span>
                        </a>
					}
                    @if (isAdministrator || AuthorizationService.UserHasCategoryPolicy(User.Identity, "Supplier"))
					{
                        <a asp-controller="Supplier" asp-action="Index" class="list-group-item list-group-item-action bg-light">
                            <span class="fas fa-fw fa-truck"></span>
                            <span>Lieferant</span>
                        </a>
					}
				}
                @if (isAdministrator || AuthorizationService.UserHasCategoryPolicy(User.Identity, "Craft"))
				{
                    <h5 class="list-group-item">Operativ</h5>
                    <a asp-controller="Craft" asp-action="Index" class="list-group-item list-group-item-action bg-light">
                        <span class="fas fa-fw fa-warehouse"></span>
                        <span>Gewerke</span>
                    </a>
				}
            </div>
        </div>
        <!-- /#sidebar-wrapper -->

        <!-- Page Content -->
        <div id="page-content-wrapper">
            <div id="contentHeadContainer" class="container-fluid pr-0">
                <div class="row d-flex top-menu">
                    <div class="mr-auto p-0">
                        <nav class="navbar navbar-expand-lg navbar-light">
                            <button class="btn btn-primary" id="menu-toggle" title="Menü ein- / ausklappen">
                                <span class="fas fa-th-list"></span>
                            </button>
                        </nav>
                    </div>
                    <div class="d-none d-lg-inline p-2">
                        <img class="align-middle mt-1" src="~/img/strohrmann_logo.png" title="Strohrmann" height="30" />
                    </div>
                    <div class="d-flex user-logo-container">
                        <img class="align-self-center mr-1 ml-3" src="~/img/user_logo.png" title="@User.Identity.Name" height="40" />
                        <span class="align-self-center mr-4 ml-1 text-white">
                            <small>@User.Identity.Name</small>
                        </span>
                        <a class="btn btn-info btn-sm align-self-center mr-4" role="button" href="@Url.Action("Logout", "Account")">
                            Ausloggen
                        </a>
                    </div>
                </div>
            </div>

            <div id="contentBodyContainer" class="container-fluid overflow-auto">
                @RenderBody()
            </div>
        </div>
        <!-- /#page-content-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- Menu Toggle Script -->
    <script type="text/javascript">

        $("#menu-toggle").click(function(e) {
            e.preventDefault();
            $("#wrapper").toggleClass("toggled");
        });

        $(window).resize(function () {
            $("#contentBodyContainer").height($(window).height() - $("#contentHeadContainer").height());
        });

        $(document).ready(function () {
            $("#contentBodyContainer").height($(window).height() - $("#contentHeadContainer").height());
        });

    </script>

</body>

</html>