<?php
namespace Meramo\Mrmbepages\ViewHelpers;

use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;

class CategoryViewHelper extends AbstractViewHelper
{
           /**
     * initialize Arguments
     * 
     * @return void
     */
    public function initializeArguments()
    {
        $this->registerArgument('slug', 'string', 'Category for Active page', true);
        
    }

    public function render()
    {
        $slug = $this->arguments['slug'];

        $category = $this->createCategory($slug);

        return $category;
    }

    protected function createCategory(string $value)
    { 
        if(substr($value, 0, 1) === '/') {
            $value = ltrim($value, '/');

            if(substr($value, 0, 1) === '_') {
                $value = ltrim($value, '_');
            }

            $data = explode('/', $value);
        }
        return $data[0];
    }
}