@using ScadaLink.Security

<nav class="sidebar d-flex flex-column">
    <div class="brand">ScadaLink</div>

    <ul class="nav flex-column flex-grow-1">
        <li class="nav-item">
            <NavLink class="nav-link" href="/" Match="NavLinkMatch.All">Dashboard</NavLink>
        </li>

        <AuthorizeView>
            <Authorized>
                @* Admin section — Admin role only *@
                <AuthorizeView Policy="@AuthorizationPolicies.RequireAdmin">
                    <Authorized Context="adminContext">
                        <li class="nav-section-header">Admin</li>
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/admin/ldap-mappings">LDAP Mappings</NavLink>
                        </li>
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/admin/sites">Sites</NavLink>
                        </li>
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/admin/data-connections">Data Connections</NavLink>
                        </li>
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/admin/api-keys">API Keys</NavLink>
                        </li>
                    </Authorized>
                </AuthorizeView>

                @* Design section — Design role *@
                <AuthorizeView Policy="@AuthorizationPolicies.RequireDesign">
                    <Authorized Context="designContext">
                        <li class="nav-section-header">Design</li>
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/design/templates">Templates</NavLink>
                        </li>
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/design/shared-scripts">Shared Scripts</NavLink>
                        </li>
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/design/external-systems">External Systems</NavLink>
                        </li>
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/admin/areas">Areas</NavLink>
                        </li>
                    </Authorized>
                </AuthorizeView>

                @* Deployment section — Deployment role *@
                <AuthorizeView Policy="@AuthorizationPolicies.RequireDeployment">
                    <Authorized Context="deploymentContext">
                        <li class="nav-section-header">Deployment</li>
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/deployment/instances">Instances</NavLink>
                        </li>
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/deployment/deployments">Deployments</NavLink>
                        </li>
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/deployment/debug-view">Debug View</NavLink>
                        </li>
                    </Authorized>
                </AuthorizeView>

                @* Monitoring — visible to all authenticated users *@
                <li class="nav-section-header">Monitoring</li>
                <li class="nav-item">
                    <NavLink class="nav-link" href="/monitoring/health">Health Dashboard</NavLink>
                </li>
                <li class="nav-item">
                    <NavLink class="nav-link" href="/monitoring/event-logs">Event Logs</NavLink>
                </li>
                <li class="nav-item">
                    <NavLink class="nav-link" href="/monitoring/parked-messages">Parked Messages</NavLink>
                </li>

                @* Audit Log — Admin only *@
                <AuthorizeView Policy="@AuthorizationPolicies.RequireAdmin">
                    <Authorized Context="auditContext">
                        <li class="nav-item">
                            <NavLink class="nav-link" href="/monitoring/audit-log">Audit Log</NavLink>
                        </li>
                    </Authorized>
                </AuthorizeView>
            </Authorized>
        </AuthorizeView>
    </ul>

    <AuthorizeView>
        <Authorized>
            <div class="border-top border-secondary px-3 py-2">
                <div class="d-flex justify-content-between align-items-center">
                    <span class="text-light small">@context.User.FindFirst("DisplayName")?.Value</span>
                    <form method="post" action="/auth/logout" data-enhance="false">
                        <button type="submit" class="btn btn-outline-light btn-sm py-0 px-2">Sign Out</button>
                    </form>
                </div>
            </div>
        </Authorized>
    </AuthorizeView>
</nav>
