@page "/"
@inject IJSRuntime JS;

<h1>Hello, world!</h1>

Welcome to your new app.
<br />

<TelerikButton OnClick="@SayHelloHandler" Primary="true">Say Hello</TelerikButton>
<TelerikButton OnClick="@OpenTabC" Primary="true">Open Tab C</TelerikButton>
<TelerikButton OnClick="@OpenTabF" Primary="true">Open Tab F</TelerikButton>
<TelerikButton OnClick="@CloseTabs" Primary="true">Close Tab</TelerikButton>
<br />

@helloString

@code {
    MarkupString helloString;

    void  SayHelloHandler()
    {
        string msg = string.Format("Hello from <strong>Telerik Blazor</strong> at {0}.<br /> Now you can use C# to write front-end!", DateTime.Now);
        helloString = new MarkupString(msg);

    }

    async Task OpenTabC()
    {
        await JS.InvokeVoidAsync("open", $"counter", "_blank");
        //await JS.InvokeAsync<object>("open", $"fetchdata", "_blank");
    }

    async Task OpenTabF()
    {
        await JS.InvokeVoidAsync("open", $"fetchdata", "_blank");
    }

    async Task CloseTabs()
    {
        //var task1 = new Object();
        //var task2 = new Object();
        var loadDataTasks = new Task[]
        {
            Task.Run(async () =>  await JS.InvokeVoidAsync("close", $"counter")),
            Task.Run(async () =>  await JS.InvokeVoidAsync("close", $"fetchdata"))
        };

        try
        {
            Task.WaitAll(loadDataTasks);
        }
        catch (Exception ex)
        {
            // handle exception
        }

        //await JS.InvokeAsync<object>("close", $"counter");
        //await JS.InvokeAsync<object>("close", $"fetchdata");
    }
}