<?php

namespace Engine\Form;

/**
 * basic layout class, used for auto-arranging inputs in the \Engine\Form\Filters container
 * @author Lucian Sirbu
 */
abstract class Filters_LayoutAbstract
{

	protected $childs = [];

	protected $options = [];

	protected $arrangedInputs = [];

	/**
	 *
	 * @param Array $childs list of inputs
	 * @param Array $options special formatted list of options
	 */
	public function __construct($childs, $options = []){
		$this->childs = $childs;
		$this->options = $options;
	}

	/**
	 * Return the list of arranged items
	 * @return multitype:
	 */
	public function arrange(){
		return $this->arrangedInputs;
	}

	/**
	 * group items into sections
	 */
	protected function extractSections($childs){
		$groups = [];
		foreach($childs as $child){
			$groups[$child->getExtraInfo('section')][] = $child;
		}

		return $groups;
	}

}
