@page "/weather"
@attribute [StreamRendering]
@* @attribute [OutputCache(Duration = 5)] *@

@inject WeatherApiClient WeatherApi
@inject WeatherApiClient2 WeatherApi2

<PageTitle>Weather</PageTitle>

<h1>Weather in Den Bosch</h1>

@if (forecasts1 == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <table class="table">
        <thead>
            <tr>
                <th>Date</th>
                <th>Temp. (C)</th>
                <th>Temp. (F)</th>
                <th>Summary</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var forecast in forecasts1)
            {
                <tr>
                    <td>@forecast.Date.ToShortDateString()</td>
                    <td>@forecast.TemperatureC</td>
                    <td>@forecast.TemperatureF</td>
                    <td>@forecast.Summary</td>
                </tr>
            }
        </tbody>
    </table>
}

<h1>Weather in New York</h1>

@if (forecasts2 == null)
{
    <p><em>Loading...</em></p>
}
else
{
    <table class="table">
        <thead>
        <tr>
            <th>Date</th>
            <th>Temp. (C)</th>
            <th>Temp. (F)</th>
            <th>Summary</th>
        </tr>
        </thead>
        <tbody>
        @foreach (var forecast in forecasts2)
        {
            <tr>
                <td>@forecast.Date.ToShortDateString()</td>
                <td>@forecast.TemperatureC</td>
                <td>@forecast.TemperatureF</td>
                <td>@forecast.Summary</td>
            </tr>
        }
        </tbody>
    </table>
}

@code {
    private WeatherForecast[]? forecasts1;
    private WeatherForecast[]? forecasts2;

    protected override async Task OnInitializedAsync()
    {
        var forecastsTask1 = WeatherApi.GetWeatherAsync();
        var forecastsTask2 = WeatherApi2.GetWeatherAsync();

        await Task.WhenAll(forecastsTask1, forecastsTask2);

        forecasts1 = await forecastsTask1;
        forecasts2 = await forecastsTask2;
    }
}