@page "/"
@* @attribute [StreamRendering(true)] *@
@attribute [RenderModeServer]


@inject IMovieReviewService MovieReviewService

<PageTitle>Movies in DotNet8</PageTitle>
<h1>Movies</h1>

@if(Movies is null)
{
    <h1>Loading...</h1>
}
else
{
    @for (int i = 0; i <= Movies.Count / 4; i++)
    {
        MovieModel[] movieGroup = Movies.Skip(i * 4).Take(4).ToArray();

        <div class="row">
            
            @foreach(MovieModel movie in movieGroup)
            {
                <MovieItem Movie="@movie" />
            }

        </div>
    }
}

@code {
    List<MovieModel> Movies = null;

    protected override async Task OnInitializedAsync()
    {
        await Task.Delay(2000);
        Movies = MovieReviewService?.GetMovies();
    }
}