<?php
/**
 * @author Amasty Team
 * @copyright Copyright (c) Amasty (https://www.amasty.com)
 * @package Jet Theme Backend for Magento 2 (System)
 */

namespace Amasty\JetTheme\Model\Template\Filter;

use Amasty\JetTheme\Model\ConfigProvider;
use Magento\Framework\Filter\DirectiveProcessorInterface;
use Magento\Framework\Filter\Template;

class WidthDirective implements DirectiveProcessorInterface
{
    private const PATTERN = '/{{width \(([a-z\_]{0,50})\)}}/si';

    /**
     * @var ConfigProvider
     */
    private $configProvider;

    public function __construct(ConfigProvider $configProvider)
    {
        $this->configProvider = $configProvider;
    }

    public function process(array $construction, Template $filter, array $templateVariables): string
    {
        return $this->configProvider->getWidthSetting($construction[1]);
    }

    public function getRegularExpression(): string
    {
        return self::PATTERN;
    }
}
