<?php


namespace AutoAdmin\Bundle\BrickBuilder\Brick;


use AutoAdmin\Bundle\BrickBuilder\Model\BrickInterface;

class BrickTextRenderer extends BrickRenderer
{
    public function render(BrickInterface $brick): ?string
    {
        $string = (string)parent::render($brick);// the brick and its children as html string

        foreach (['svg', 'style'] as $t) {
            $string = preg_replace('|<' . $t . ' ?(.+)</' . $t . '>|s', '', $string);
        }
        $string = preg_replace('|<\!--(.*?)-->|s', '', $string);
        $string = html_entity_decode($string, ENT_HTML5 | ENT_QUOTES);
        $string = strip_tags($string);
        $string = str_replace("\n", ' ', $string);
        $string = preg_replace('| +|s', ' ', $string);

        return $string;
    }
}
