@page "/weather"

<PageTitle>Weather</PageTitle>

<h1>Weather</h1>

<DxGrid Data="@forecasts">
    <Columns>
        <DxGridDataColumn Caption="Date" FieldName="Date" />
        <DxGridDataColumn Caption="Temperature (C)" FieldName="TemperatureC" />
        <DxGridDataColumn Caption="Temperature (F)" FieldName="TemperatureF" />
        <DxGridDataColumn Caption="Summary" FieldName="Summary" />
    </Columns>
</DxGrid>

@code {
    private WeatherForecast[]? forecasts;

    protected override async Task OnInitializedAsync() {
        DateOnly startDate = DateOnly.FromDateTime(DateTime.Now);
        string[] summaries = ["Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"];
        forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast(
                Date: startDate.AddDays(index),
                TemperatureC: Random.Shared.Next(-20, 55),
                Summary: summaries[Random.Shared.Next(summaries.Length)]
            )).ToArray();
    }

    private record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) {
        public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
    }
}
