using Nop.Web.Framework.Components;
using Microsoft.AspNetCore.Mvc;
using Nop.Services.Catalog;
using Nop.Web.Factories;
using Nop.Web.Models.Catalog;

namespace Nop.Web.Components
{
    public class ProductTagSideListB2CViewComponent : NopViewComponent
    {
        private readonly ICatalogModelB2CFactory _catalogModelB2CFactory;
        private readonly IProductTagService _IProductTagService;

        public ProductTagSideListB2CViewComponent(ICatalogModelB2CFactory catalogModelB2CFactory, IProductTagService IProductTagService)
        {
            _catalogModelB2CFactory = catalogModelB2CFactory;
            _IProductTagService = IProductTagService;
        }

        public IViewComponentResult Invoke(string tagname = "")
        {
            var productTag = _IProductTagService.GetProductTagByName(tagname);
            if (productTag == null)
                return Content("");

            var model = _catalogModelB2CFactory.PrepareProductsByTagModel(productTag, new CatalogPagingFilteringModel());
            return View(model);
        }
    }
}