@inject NavigationManager NavigationManager
@implements IDisposable

<div>
    <DxMenu Orientation="@Orientation.Vertical" CssClass="menu">
        <Items>
            <DxMenuItem NavigateUrl="/" Text="Home" CssClass="@MenuItemCssClass("/")" IconCssClass="icon icon-home"></DxMenuItem>
            <DxMenuItem NavigateUrl="/pvk" Text="Personalverkauf" Target="_blank" CssClass="@MenuItemCssClass("/pvk")" IconCssClass="icon icon-counter"></DxMenuItem>
            <DxMenuItem NavigateUrl="/controlling" Text="Controlling" Target="_blank" CssClass="@MenuItemCssClass("/controlling")" IconCssClass="icon icon-weather"></DxMenuItem>
        </Items>
    </DxMenu>
</div>

@code {
    private string? currentLocalPath;

    protected override void OnInitialized() {
        currentLocalPath = new Uri(NavigationManager.Uri).LocalPath;
        NavigationManager.LocationChanged += OnLocationChanged;
    }

    private void OnLocationChanged(object? sender, LocationChangedEventArgs e) {
        currentLocalPath = new Uri(NavigationManager.Uri).LocalPath;
        InvokeAsync(StateHasChanged);
    }

    private string? MenuItemCssClass(string itemPath) {
        return string.Equals(currentLocalPath, itemPath, StringComparison.OrdinalIgnoreCase) ? "menu-item-active" : null;
    }

    public void Dispose() {
        NavigationManager.LocationChanged -= OnLocationChanged;
    }
}