<div class="col-lg-4 col-md-6">
    <div class="single-product">
        <div class="product-img">
            <img class="card-img"
                 src="@Card.ImageUrl"
                 alt="" />
            <div class="p_icon">
                <a href="#">
                    <i class="ti-eye"></i>
                </a>
                <a @onclick="(() => this.AddProductToFavorite(this.Card.Id))">
                    <i class="ti-heart"></i>
                </a>
                <a @onclick="(() => this.AddProductToBasket(this.Card.Id, 1))">
                    <i class="ti-shopping-cart"></i>
                </a>
            </div>
        </div>
        <div class="product-btm">
            <a href="/SdvShop/Shop/Product/@Card.Id" class="d-block">
                <h4>@Card.Name</h4>
            </a>
            <div class="mt-3">
                <span class="mr-4">@Card.Price</span>
                <del>$35.00</del>
            </div>
        </div>
    </div>
</div>

@code {
    [Parameter]
    public ProductCardViewModel Card { get; set; }

    private async Task AddProductToBasket(string id, int quantity)
    {
        this.ShoppingCartState.AddProduct(id, quantity);
        var oldValue = await this.SessionStorage.GetItemAsync<Dictionary<string, int>>("CodeShop");
        if (oldValue.Any(x => x.Key == id))
        {
            oldValue[id] += quantity;
        }
        else
        {
            oldValue.Add(id, quantity);
        }

        await this.SessionStorage.SetItemAsync("CodeShop", oldValue);
        this.NavigationManager.NavigateTo("/SdvShop/Shop/ShoppingCart");
    }

    private async Task AddProductToFavorite(string id)
    {
        this.FavoriteProductsState.AddProduct(id);
        var oldValues = await this.LocalStorage.GetItemAsync<List<string>>("CodeShopFavProducts");
        if (!oldValues.Any(x => x == id))
        {
            oldValues.Add(id);
        }

        await this.LocalStorage.SetItemAsync("CodeShopFavProducts", oldValues);
    }
}