<?php

namespace Engine\Form\Container;

// TODO: should not be used for corporate/supplier profile popups - these pages should be redone (maybe this type of form should be completely eliminated)

/**
 * The main form container. This will hold multiple input elements in it
 * @author Lucian
 */
class Ajax extends \Engine\Form\Container\GeneralAbstract
{
	public $class = 'AJAXContainer';

	// implement a "defaultContainer" algorithm
	protected $defaultContainer = null;

	// the URL where to perform requests
	protected $URL = '';

	/**
	 * Base constructor
	 * @param String $label (optional)
	 */
	function __construct($label=''){
		parent::__construct($label);

		$this->setStyle("preLoad", true);
	}

	/**
	 * Get the default container
	 */
	public function getDefaultContainer(){ return $this->defaultContainer; }

	/**
	 * Set the default container. I'm counting here on PHP sending objects as references
	 * @param \Engine\Form\Container\GeneralAbstract $container
	 * @return \Engine\Form\Container\GeneralAbstract
	 */
	public function setDefaultContainer(\Engine\Form\Container\GeneralAbstract $container){ $this->defaultContainer = $container; return $this->defaultContainer;}

	/**
	 * (non-PHPdoc)
	 * @see \Engine\Form\Container\GeneralAbstract::getTemplateParams()
	 */
	public function getTemplateParams($templateClass = null, $parentElement = null){
		$params = parent::getTemplateParams($templateClass, $parentElement);

		$params['defaultContainer'] = $this->getDefaultContainer();
		if(!$params['defaultContainer']){
			$params['defaultContainer'] = reset($this->childs);
		}

		$params['URL'] = $this->URL;

		return $params;
	}

	public function setURL($URL){
		$this->URL = $URL;
		return $this;
	}

	public function getURL(){
		return $this->URL;
	}
}
