using System.Linq;
using Microsoft.AspNetCore.Mvc;
using Nop.Core.Domain.Catalog;
using Nop.Web.Factories;
using Nop.Web.Framework.Components;
using Nop.Web.Models.Catalog;

namespace Nop.Web.Components
{
    public class HomepageBrandB2CViewComponent : NopViewComponent
    {
        private readonly CatalogSettings _catalogSettings;
        private readonly ICatalogModelB2CFactory _catalogModelB2CFactory;
        public HomepageBrandB2CViewComponent(CatalogSettings catalogSettings,
            ICatalogModelB2CFactory catalogModelB2CFactory)
        {
            _catalogSettings = catalogSettings;
            _catalogModelB2CFactory = catalogModelB2CFactory;
        }

        public IViewComponentResult Invoke(bool isSlideDisplayed = false)
        {
            if (_catalogSettings.ManufacturersBlockItemsToDisplay == 0)
                return Content("");

            var model = _catalogModelB2CFactory.PrepareManufacturerAllModels();
            if (!model.Any())
                return Content("");

            return View(new ManufacturerComponentB2CModel
            {
                Manufacturers = model,
                IsSlideDisplayed = isSlideDisplayed
            });
        }
    }
}
