@page "/mud/project/roadmap"
@using System.Text.RegularExpressions

<PageTitle>Roadmap - MudBlazor</PageTitle>

<DocsPage DisplayFooter="true">
    <DocsPageHeader Title="Roadmap" />
    <DocsPageContent>
        @if (string.IsNullOrEmpty(_roadMap))
        {
            <MudProgressCircular Color="Color.Primary" Indeterminate="true" />
        }
        else
        {
            <MudStack Spacing="2" Class="mud-typography mud-typography-body1">
                @((MarkupString)GetBody(_roadMap))
            </MudStack>
        }
    </DocsPageContent>
</DocsPage>

@code {
    private string _roadMap;

    [Inject]
    private HttpClient HttpClient { get; set; }

    protected override async Task OnInitializedAsync()
    {
        var response = await HttpClient.GetAsync("https://raw.githubusercontent.com/MudBlazor/MudBlazor/dev/ROADMAP.md");
        _roadMap = await response.Content.ReadAsStringAsync();
    }

    private static string GetBody(string value)
    {
        // Wrap paragraphs in <p> tags before titles are converted to HTML headers
        value = Regex.Replace(value, @"(^|\n\n)(?!#)([^\n]+(\n(?!#)[^\n]+)*)", "$1<p>$2</p>", RegexOptions.Multiline);
        value = Regex.Replace(value, @"(##\s)(?<title>.+)", "<h5 class=\"mud-typography mud-typography-h5 mt-3\"><b>${title}</b></h5><hr class=\"mud-divider mud-divider-fullwidth\">");
        value = Regex.Replace(value, @"(#\s)(?<title>.+)", "<h4 class=\"mud-typography mud-typography-h4\"><b>${title}</b></h4><hr class=\"mud-divider mud-divider-fullwidth\">");
        value = Regex.Replace(value, @"\[(.*?)\]\((.*?)\)", "<a target=\"_blank\" href=\"$2\" class=\"mud-link mud-primary-text mud-link-underline-hover\">$1</a>");

        return value;
    }
}