@page "/"
@using Blazor_DotNet8_MovieApp.Models;
@using Blazor_DotNet8_MovieApp.Services;

@inject IMovieReviewService MovieReviewService

<PageTitle>Movies in DotNet8</PageTitle>

@if(Movies is null)
{
    <h1>Loading Movies...</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)
            {
                <div class="col-md-3 mb-2">
                    <a href="/MovieReview/@movie?.Id">
                        <img class="img-thumbnail" src="@movie?.ImageUrl">
                        <div class="card-body">
                            <h5 class="card-title">
                                @movie?.Title
                            </h5>
                            <p class="card-text">
                                @movie?.Description
                            </p>
                        </div>
                    </a>
                </div>
            }

        </div>
    }
}

@code {
    List<MovieModel> Movies = null;

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