@inject NavigationManager NavigationManager
@using AliasVault.Shared.Core
@implements IDisposable

<footer class="relative lg:fixed bottom-0 left-0 right-0 dark:bg-gray-900 @(ShowBorder ? "border-t border-gray-200 dark:border-gray-700" : "")">
    <div class="container mx-auto px-4 py-4">
        <div class="flex flex-col lg:flex-row justify-between items-center">
            <p class="text-sm text-center text-gray-500 mb-4 lg:mb-0">
                © 2024 <span>@AppInfo.ApplicationName v@(AppInfo.GetFullVersion())</span>. All rights reserved.
            </p>
            <div class="hidden lg:block text-center text-gray-400 text-sm">@_randomQuote</div>
            <ul class="flex flex-wrap items-center justify-center">
                <li>
                    <a href="https://github.com/lanedirt/AliasVault" target="_blank" class="text-sm font-normal text-gray-500 hover:underline dark:text-gray-400">GitHub</a>
                </li>
            </ul>
        </div>
    </div>
</footer>

@code {
    /// <summary>
    /// Gets or sets a value indicating whether the footer should have a border.
    /// </summary>
    [Parameter]
    public bool ShowBorder { get; set; } = true;

    private static readonly string[] Quotes =
    [
        "Tip: Use the g+c (go create) keyboard shortcut to quickly create a new alias.",
        "Tip: Use the g+f (go find) keyboard shortcut to focus the search field.",
        "Tip: Use the g+h (go home) keyboard shortcut to go to the homepage.",
        "Tip: Use the g+l (go lock) keyboard shortcut to lock the vault.",
    ];

    private string _randomQuote = string.Empty;

    /// <inheritdoc />
    public void Dispose()
    {
        NavigationManager.LocationChanged -= RefreshQuote;
    }

    /// <inheritdoc />
    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender)
        {
            _randomQuote = Quotes[Random.Shared.Next(Quotes.Length)];
            NavigationManager.LocationChanged += RefreshQuote;
        }
    }

    /// <summary>
    /// Shows a new random quote.
    /// </summary>
    private void RefreshQuote(object? sender, LocationChangedEventArgs e)
    {
        _randomQuote = Quotes[Random.Shared.Next(Quotes.Length)];
        StateHasChanged();
    }
}
