<?php

namespace Lc\ShopBundle\Twig;

use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\PageInterface;
use Lc\ShopBundle\Form\Frontend\NewsletterType;
use Lc\ShopBundle\Services\TaxRateUtils;
use Lc\ShopBundle\Services\UnitUtils;
use Lc\ShopBundle\Services\Utils;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;

class BridgeTwigExtension extends AbstractExtension
{
        private $utils ;
        private $merchantUtils ;

        public function __construct(Utils $utils, MerchantUtilsInterface $merchantUtils)
        {
                $this->utils = $utils ;
                $this->merchantUtils = $merchantUtils ;
        }

        public function getFunctions()
        {
                return array(
                        new TwigFunction('getDayByNumber', [$this, 'getDayByNumber']),
                        new TwigFunction('getUnitsList', [$this, 'getUnitsList']),
                        new TwigFunction('getTaxRatesList', [$this, 'getTaxRatesList']),
                        new TwigFunction('lc_liip', [$this, 'lcLiip']),
                        new TwigFunction('getElementByDevAlias', [$this, 'getElementByDevAlias']),
                );
        }

        public function getFilters()
        {
                return [
                        new TwigFilter('slugify', [$this, 'slugify']),
                        new TwigFilter('lc_liip', [$this, 'lcLiip']),

                ];
        }

        public function getDayByNumber($number)
        {
                return $this->utils->getDayByNumber($number) ;
        }

        public function getUnitsList()
        {
                return $this->utils->getUnitsList() ;
        }

        public function getTaxRatesList()
        {
                return $this->merchantUtils->getTaxRatesList() ;
        }

        public function getElementByDevAlias($devAlias, $class = PageInterface::class)
        {
                return $this->utils->getElementByDevAlias($devAlias, $class) ;
        }

        public function slugify($string)
        {
                return $this->utils->slugify($string) ;
        }

        public function lcLiip($path, $thumb = 'tile', $default = 'default.jpg'){

                return $this->utils->lcLiip($path, $thumb,  $default);
        }
}
