@if (this.allReviews != null && this.inputModel != null)
{
    <div class="tab-pane fade show active"
         id="review"
         role="tabpanel"
         aria-labelledby="review-tab">
        <div class="row">
            <div class="col-lg-6">
                <ReviewBanner Reviews="@this.allReviews"></ReviewBanner>
                <ReviewsList Reviews="@this.allReviews"
                             TotalPagesQuantity="@this.totalPagesQuantity"
                             OnDeleteReview="this.DeleteClickHandler">
                </ReviewsList>
            </div>
            <div class="col-lg-6">
                <div class="review_box">
                    <h4>Add a Review</h4>
                    <p>Your Rating:</p>
                    <div class="star-rating">
                        <input @onclick='(() => { this.inputModel.Stars = 5; this.ratingWord = "Outstanding"; })' id="star5" type="radio" name="rating" value="star5" />
                        <label for="star5" title="5 stars">
                            <i class="fas fa-star"></i>
                        </label>
                        <input @onclick='(() => { this.inputModel.Stars = 4; this.ratingWord = "Very Good"; })' id="star4" type="radio" name="rating" value="star4" />
                        <label for="star4" title="4 stars">
                            <i class="fas fa-star"></i>
                        </label>
                        <input @onclick='(() => { this.inputModel.Stars = 3; this.ratingWord = "Good"; })' id="star3" type="radio" name="rating" value="star3" />
                        <label for="star3" title="3 stars">
                            <i class="fas fa-star"></i>
                        </label>
                        <input @onclick='(() => { this.inputModel.Stars = 2; this.ratingWord = "Average"; })' id="star2" type="radio" name="rating" value="star2" />
                        <label for="star2" title="2 stars">
                            <i class="fas fa-star"></i>
                        </label>
                        <input @onclick='(() => { this.inputModel.Stars = 1; this.ratingWord = "Terrible"; })' id="star1" type="radio" name="rating" value="star1" />
                        <label for="star1" title="1 star">
                            <i class="fas fa-star"></i>
                        </label>
                    </div>
                    <p>@this.ratingWord</p>
                    <EditForm Model="@this.inputModel" OnValidSubmit="@this.CreateReview" class="row contact_form">
                        <DataAnnotationsValidator />
                        <div class="col-md-12">
                            <div class="form-group">
                                <ValidationMessage For="(() => this.inputModel.Stars)" />
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <InputText id="fullName" @bind-Value="this.inputModel.FullName" type="text" class="form-control" placeholder="Your Name" />
                                <ValidationMessage For="@(() => this.inputModel.FullName)" />
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <InputText id="email" @bind-Value="this.inputModel.Email" type="email" class="form-control" placeholder="Email Address" />
                                <ValidationMessage For="@(() => this.inputModel.Email)" />
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <InputText id="phoneNumber" @bind-Value="this.inputModel.PhoneNumber" type="text" class="form-control" placeholder="Phone Number" />
                                <ValidationMessage For="@(() => this.inputModel.PhoneNumber)" />
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-group">
                                <InputTextArea id="content" @bind-Value="this.inputModel.Content" class="form-control" rows="8" placeholder="Message" />
                                <ValidationMessage For="@(() => this.inputModel.Content)" />
                            </div>
                        </div>
                        <div class="col-md-12 text-right">
                            <button type="submit" class="btn submit_btn">
                                Submit Now
                            </button>
                        </div>
                    </EditForm>
                </div>
            </div>
        </div>
    </div>
}
@code {
    private AddReviewInputModel inputModel = new AddReviewInputModel();
    private ICollection<ReviewViewModel> allReviews;
    private int totalPagesQuantity = 1;
    private string ratingWord = string.Empty;

    [Parameter]
    public string ProductId { get; set; }

    private async Task CreateReview()
    {
        await this.ReviewService.AddReview(this.inputModel);
        this.inputModel.Content = string.Empty;
        this.inputModel.Stars = 0;
        this.allReviews = await this.ReviewService.GetAllReviews(this.ProductId);

        totalPagesQuantity = this.CalculateTotalPages();
    }

    private int CalculateTotalPages()
    {
        return Math.Max(1, (int)Math.Ceiling(this.allReviews.Count / (decimal)GlobalConstants.ReviewsOnPage));
    }

    private async Task DeleteClickHandler(string id)
    {
        await this.ReviewService.RemoveReview(id);
        await this.OnInitializedAsync();
    }

    protected override async Task OnInitializedAsync()
    {
        var username = this.HttpContextAccessor.HttpContext.User.Identity.Name;
        inputModel = await this.ReviewService.ExtractReviewInformation(username, this.ProductId);
        this.allReviews = await this.ReviewService.GetAllReviews(this.ProductId);

        totalPagesQuantity = this.CalculateTotalPages();
    }
}