<?php
/**
  * Ahead WebSoft Technologies Pvt Ltd.
  * @copyright  Copyright 2006-2026 Ahead WebSoft Technologies Pvt Ltd.
  * @license    https://www.socialengine.com/policies
*/
class Engine_Content_Decorator_Container extends Engine_Content_Decorator_Abstract
{
  public $helper = 'htmlContainer';

  public function getClass()
  {
    $name = $this->getElement()->getName();
    if( null === $name ) {
      return null;
    }
    return 'generic_layout_container layout_' . preg_replace('/[^\w\d]/', '_', $name);
  }

	public function getId()
	{
		$element = $this->getElement();
		$name = $element->getName();

		if (null === $name) {
			return null;
		}

		$id = 'layout_' . preg_replace('/[^\w\d]/', '_', $name);

		if (method_exists($element, 'getIdentity')) {
			$id .= '_' . $element->getIdentity();
		}

		return $id;
	}
  
  public function render($content)
  {
    $element = $this->getElement();
    $separator = $this->getSeparator();
    $attribs = array_merge($element->getAttribs(), $this->getParams());
    $view = $element->getView();

    // Auto class
    $class = $this->getClass();
    if( null !== $class ) {
      if( empty($attribs['class']) ) {
        $attribs['class'] = $class;
      } else {
        $attribs['class'] .= ' ' . $class;
      }
    }

		// Auto id
    $id = $this->getId();
    if( null !== $id ) {
      if( empty($attribs['id']) ) {
        $attribs['id'] = $id;
      } else {
        $attribs['id'] .= ' ' . $id;
      }
    }

    $name = $this->getElement()->getName();
    $layout = preg_replace('/[^\w\d]/', '_', $name);
    if($layout == 'left' || $layout == 'right'){
      $content = "<div class='theiaStickySidebar'>".$content.'</div>';
    }
    return $view->{$this->helper}($content, $attribs) . $separator;
  }
}
