<?php

namespace Leadlion\CategorySliders\Block;

class SliderBlock extends \Magento\Framework\View\Element\Template
{
    /**
    * @var \Magento\Catalog\Helper\Category
    */
    protected $categoryRepository;
    
    public function __construct(
    \Magento\Catalog\Model\CategoryRepository $categoryRepository,
    \Leadlion\Autogedal\Helper\Config $helper,
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    \Magento\Framework\View\Element\Template\Context $context,
    \Magento\Catalog\Block\Product\View $product,
    \Magento\Catalog\Block\Category\View $category        
    ) {
        $this->categoryRepository = $categoryRepository;
        $this->helper = $helper;
        $this->_storeManager = $storeManager;
        $this->_product = $product;
        $this->_category = $category;
        parent::__construct($context);
    }
    
    public function getProductSliderBefore($categories)
    {
        $uspBlockName = null;
        if(is_array($categories)):
            foreach($categories as $category):
                if($this->getCategory($category)->getProductSlidersBlockSectionOne() && $this->getCategory($category)->getIsActive()):
                    $uspBlockName = $this->getCategory($category)->getProductSlidersBlockSectionOne();
                endif;
            endforeach;
        else:
            $uspBlockName = $this->getCategory($categories)->getProductSlidersBlockSectionOne();
        endif;
        
        if(!$uspBlockName):
           $uspBlockName = $this->helper->getConfig('leadlion/product_slider/product_no_block_before', $this->_storeManager->getStore()->getId()); 
        endif;
        
        return $uspBlockName;
    }
    public function getProductSliderAfter($categories)
    {
        $uspBlockName = null;
        if(is_array($categories)):
            foreach($categories as $category):
                if($this->getCategory($category)->getProductSlidersBlockSectionTwo() && $this->getCategory($category)->getIsActive()):
                    $uspBlockName = $this->getCategory($category)->getProductSlidersBlockSectionTwo();
                endif;
            endforeach;
        else:
            $uspBlockName = $this->getCategory($categories)->getProductSlidersBlockSectionTwo();
        endif;
        
        if(!$uspBlockName):
           $uspBlockName = $this->helper->getConfig('leadlion/product_slider/product_no_block_after', $this->_storeManager->getStore()->getId()); 
        endif;
        
        return $uspBlockName;
    }
    
    public function getCategory($category)
    {
        $categoryData = $this->categoryRepository->get($category);
        
        return $categoryData;
    }
    
}
